test task model
This commit is contained in:
@@ -6,8 +6,6 @@ import HelloWorld from './components/HelloWorld.vue'
|
||||
<template>
|
||||
<header>
|
||||
<div class="wrapper">
|
||||
<HelloWorld msg="You did it!" />
|
||||
|
||||
<nav>
|
||||
<RouterLink to="/">Home</RouterLink>
|
||||
<RouterLink to="/about">About</RouterLink>
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import WelcomeItem from './WelcomeItem.vue'
|
||||
import DocumentationIcon from './icons/IconDocumentation.vue'
|
||||
import ToolingIcon from './icons/IconTooling.vue'
|
||||
import EcosystemIcon from './icons/IconEcosystem.vue'
|
||||
import CommunityIcon from './icons/IconCommunity.vue'
|
||||
import SupportIcon from './icons/IconSupport.vue'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<DocumentationIcon />
|
||||
</template>
|
||||
<template #heading>Documentation</template>
|
||||
|
||||
Vue’s
|
||||
<a href="https://vuejs.org/" target="_blank" rel="noopener">official documentation</a>
|
||||
provides you with all information you need to get started.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<ToolingIcon />
|
||||
</template>
|
||||
<template #heading>Tooling</template>
|
||||
|
||||
This project is served and bundled with
|
||||
<a href="https://vitejs.dev/guide/features.html" target="_blank" rel="noopener">Vite</a>. The
|
||||
recommended IDE setup is
|
||||
<a href="https://code.visualstudio.com/" target="_blank" rel="noopener">VSCode</a> +
|
||||
<a href="https://github.com/johnsoncodehk/volar" target="_blank" rel="noopener">Volar</a>. If
|
||||
you need to test your components and web pages, check out
|
||||
<a href="https://www.cypress.io/" target="_blank" rel="noopener">Cypress</a> and
|
||||
<a href="https://on.cypress.io/component" target="_blank">Cypress Component Testing</a>.
|
||||
|
||||
<br />
|
||||
|
||||
More instructions are available in <code>README.md</code>.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<EcosystemIcon />
|
||||
</template>
|
||||
<template #heading>Ecosystem</template>
|
||||
|
||||
Get official tools and libraries for your project:
|
||||
<a href="https://pinia.vuejs.org/" target="_blank" rel="noopener">Pinia</a>,
|
||||
<a href="https://router.vuejs.org/" target="_blank" rel="noopener">Vue Router</a>,
|
||||
<a href="https://test-utils.vuejs.org/" target="_blank" rel="noopener">Vue Test Utils</a>, and
|
||||
<a href="https://github.com/vuejs/devtools" target="_blank" rel="noopener">Vue Dev Tools</a>. If
|
||||
you need more resources, we suggest paying
|
||||
<a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">Awesome Vue</a>
|
||||
a visit.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<CommunityIcon />
|
||||
</template>
|
||||
<template #heading>Community</template>
|
||||
|
||||
Got stuck? Ask your question on
|
||||
<a href="https://chat.vuejs.org" target="_blank" rel="noopener">Vue Land</a>, our official
|
||||
Discord server, or
|
||||
<a href="https://stackoverflow.com/questions/tagged/vue.js" target="_blank" rel="noopener"
|
||||
>StackOverflow</a
|
||||
>. You should also subscribe to
|
||||
<a href="https://news.vuejs.org" target="_blank" rel="noopener">our mailing list</a> and follow
|
||||
the official
|
||||
<a href="https://twitter.com/vuejs" target="_blank" rel="noopener">@vuejs</a>
|
||||
twitter account for latest news in the Vue world.
|
||||
</WelcomeItem>
|
||||
|
||||
<WelcomeItem>
|
||||
<template #icon>
|
||||
<SupportIcon />
|
||||
</template>
|
||||
<template #heading>Support Vue</template>
|
||||
|
||||
As an independent project, Vue relies on community backing for its sustainability. You can help
|
||||
us by
|
||||
<a href="https://vuejs.org/sponsor/" target="_blank" rel="noopener">becoming a sponsor</a>.
|
||||
</WelcomeItem>
|
||||
</template>
|
||||
@@ -1,86 +0,0 @@
|
||||
<template>
|
||||
<div class="item">
|
||||
<i>
|
||||
<slot name="icon"></slot>
|
||||
</i>
|
||||
<div class="details">
|
||||
<h3>
|
||||
<slot name="heading"></slot>
|
||||
</h3>
|
||||
<slot></slot>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.item {
|
||||
margin-top: 2rem;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.details {
|
||||
flex: 1;
|
||||
margin-left: 1rem;
|
||||
}
|
||||
|
||||
i {
|
||||
display: flex;
|
||||
place-items: center;
|
||||
place-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 500;
|
||||
margin-bottom: 0.4rem;
|
||||
color: var(--color-heading);
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.item {
|
||||
margin-top: 0;
|
||||
padding: 0.4rem 0 1rem calc(var(--section-gap) / 2);
|
||||
}
|
||||
|
||||
i {
|
||||
top: calc(50% - 25px);
|
||||
left: -26px;
|
||||
position: absolute;
|
||||
border: 1px solid var(--color-border);
|
||||
background: var(--color-background);
|
||||
border-radius: 8px;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.item:before {
|
||||
content: ' ';
|
||||
border-left: 1px solid var(--color-border);
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: calc(50% + 25px);
|
||||
height: calc(50% - 25px);
|
||||
}
|
||||
|
||||
.item:after {
|
||||
content: ' ';
|
||||
border-left: 1px solid var(--color-border);
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: calc(50% + 25px);
|
||||
height: calc(50% - 25px);
|
||||
}
|
||||
|
||||
.item:first-of-type:before {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.item:last-of-type:after {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
10
src/use-cases/task/models/step.fixture.ts
Normal file
10
src/use-cases/task/models/step.fixture.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { Stepable } from '@/use-cases/task/interfaces/stepable'
|
||||
import { Step } from '@/use-cases/task/models/step'
|
||||
import { faker } from '@faker-js/faker'
|
||||
|
||||
export const createStepFixture = (partialStep?: Partial<Stepable>) =>
|
||||
new Step(
|
||||
partialStep?.id ?? faker.datatype.uuid(),
|
||||
partialStep?.title ?? faker.animal.bird(),
|
||||
partialStep?.estimation
|
||||
)
|
||||
@@ -1,27 +1,19 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { Step } from '@/use-cases/task/models/step'
|
||||
import { faker } from '@faker-js/faker'
|
||||
import type { Stepable } from '@/use-cases/task/interfaces/stepable'
|
||||
|
||||
const createStep = (partialStep?: Partial<Stepable>) =>
|
||||
new Step(
|
||||
partialStep?.id ?? faker.datatype.uuid(),
|
||||
partialStep?.title ?? faker.animal.bird(),
|
||||
partialStep?.estimation
|
||||
)
|
||||
import { createStepFixture } from '@/use-cases/task/models/step.fixture'
|
||||
|
||||
describe('Step', () => {
|
||||
it('adds substeps', () => {
|
||||
const step = createStep()
|
||||
const step = createStepFixture()
|
||||
|
||||
step.addSteps(createStep())
|
||||
step.addSteps(createStepFixture())
|
||||
|
||||
expect(step.steps.length).toEqual(1)
|
||||
})
|
||||
|
||||
it('removes substeps', () => {
|
||||
const step = createStep()
|
||||
step.addSteps(createStep())
|
||||
const step = createStepFixture()
|
||||
step.addSteps(createStepFixture())
|
||||
|
||||
step.removeStep(0)
|
||||
|
||||
@@ -29,19 +21,19 @@ describe('Step', () => {
|
||||
})
|
||||
|
||||
it('tells the estimation based on the sum of its substeps', () => {
|
||||
const step = createStep()
|
||||
const step = createStepFixture()
|
||||
.addSteps(
|
||||
createStep({
|
||||
createStepFixture({
|
||||
estimation: 1
|
||||
})
|
||||
)
|
||||
.addSteps(
|
||||
createStep({
|
||||
createStepFixture({
|
||||
estimation: 2
|
||||
})
|
||||
)
|
||||
.addSteps(
|
||||
createStep({
|
||||
createStepFixture({
|
||||
estimation: 3
|
||||
})
|
||||
)
|
||||
@@ -50,16 +42,16 @@ describe('Step', () => {
|
||||
})
|
||||
|
||||
it('tells the total estimation if the step estimation is set even with substeps', () => {
|
||||
const step = createStep({
|
||||
const step = createStepFixture({
|
||||
estimation: 8
|
||||
})
|
||||
.addSteps(
|
||||
createStep({
|
||||
createStepFixture({
|
||||
estimation: 1
|
||||
})
|
||||
)
|
||||
.addSteps(
|
||||
createStep({
|
||||
createStepFixture({
|
||||
estimation: 2
|
||||
})
|
||||
)
|
||||
@@ -69,20 +61,20 @@ describe('Step', () => {
|
||||
|
||||
it('flattens the substeps', () => {
|
||||
const leafs = [
|
||||
createStep({
|
||||
createStepFixture({
|
||||
id: 'leaf-1'
|
||||
}),
|
||||
createStep({
|
||||
createStepFixture({
|
||||
id: 'leaf-2'
|
||||
}),
|
||||
createStep({
|
||||
createStepFixture({
|
||||
id: 'leaf-3'
|
||||
})
|
||||
]
|
||||
|
||||
const step = createStep().addSteps(
|
||||
createStep().addSteps(leafs[0], leafs[1]),
|
||||
createStep().addSteps(createStep().addSteps(leafs[2]))
|
||||
const step = createStepFixture().addSteps(
|
||||
createStepFixture().addSteps(leafs[0], leafs[1]),
|
||||
createStepFixture().addSteps(createStepFixture().addSteps(leafs[2]))
|
||||
)
|
||||
const steps = Step.getStepLeafs([step])
|
||||
|
||||
|
||||
56
src/use-cases/task/models/task.test.ts
Normal file
56
src/use-cases/task/models/task.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import type { Stepable } from '@/use-cases/task/interfaces/stepable'
|
||||
import type { Taskable } from '@/use-cases/task/interfaces/taskable'
|
||||
import { createStepFixture } from '@/use-cases/task/models/step.fixture'
|
||||
import { Task } from '@/use-cases/task/models/task'
|
||||
import { faker } from '@faker-js/faker'
|
||||
import exp from 'constants'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
describe('Task', () => {
|
||||
it('has a simple id', () => {
|
||||
const uuid = faker.datatype.uuid()
|
||||
|
||||
const task = new Task(uuid)
|
||||
|
||||
expect(task.id).equals(uuid)
|
||||
})
|
||||
|
||||
it('allows a new task from a taskable object', () => {
|
||||
const taskable: Taskable = {
|
||||
id: faker.datatype.uuid(),
|
||||
title: faker.animal.lion(),
|
||||
link: faker.internet.url(),
|
||||
steps: [createStepFixture()]
|
||||
}
|
||||
const task = Task.fromTaskable(taskable)
|
||||
|
||||
expect(task).toEqual(taskable)
|
||||
})
|
||||
|
||||
it('adds steps and removes them', () => {
|
||||
const task = new Task(faker.datatype.uuid())
|
||||
|
||||
const [firstStep, secondStep] = [createStepFixture(), createStepFixture()]
|
||||
|
||||
task.addSteps(firstStep, secondStep)
|
||||
|
||||
expect(task.steps).toEqual([firstStep, secondStep])
|
||||
|
||||
task.removeStep(0)
|
||||
expect(task.steps).toEqual([secondStep])
|
||||
|
||||
task.removeStep(0)
|
||||
expect(task.steps).toEqual([])
|
||||
})
|
||||
|
||||
it('must have an id, a title and steps to be valid', () => {
|
||||
const task = new Task(faker.datatype.uuid())
|
||||
expect(Task.validate(task)).toEqual(false)
|
||||
|
||||
task.title = faker.animal.bird()
|
||||
expect(Task.validate(task)).toEqual(false)
|
||||
|
||||
task.addSteps(createStepFixture())
|
||||
expect(Task.validate(task)).toEqual(true)
|
||||
})
|
||||
})
|
||||
@@ -19,18 +19,14 @@ export class Task implements Taskable {
|
||||
return this
|
||||
}
|
||||
|
||||
if (index < this.steps.length) {
|
||||
if (index >= this.steps.length) {
|
||||
return this
|
||||
}
|
||||
|
||||
this.steps.splice(index)
|
||||
this.steps.splice(index, 1)
|
||||
return this
|
||||
}
|
||||
|
||||
public get flattenSteps() {
|
||||
return this.steps
|
||||
}
|
||||
|
||||
public static fromTaskable(taskable: Taskable) {
|
||||
const task = new Task(taskable.id)
|
||||
task.title = taskable.title
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import TheWelcome from '../components/TheWelcome.vue'
|
||||
</script>
|
||||
<script setup lang="ts"></script>
|
||||
|
||||
<template>
|
||||
<main>
|
||||
<TheWelcome />
|
||||
</main>
|
||||
<main>Bonjour</main>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user