diff --git a/src/modules/task/components/NewTaskForm.vue b/src/modules/task/components/NewTaskForm.vue index 75d097e..c539134 100644 --- a/src/modules/task/components/NewTaskForm.vue +++ b/src/modules/task/components/NewTaskForm.vue @@ -1,10 +1,15 @@ diff --git a/src/modules/task/components/TaskForm.vue b/src/modules/task/components/TaskForm.vue index a0ee185..d8e02ab 100644 --- a/src/modules/task/components/TaskForm.vue +++ b/src/modules/task/components/TaskForm.vue @@ -14,16 +14,19 @@ const router = useRouter() const props = defineProps<{ id: string initialTask?: Taskable + initialSteps?: Stepable[] }>() const id = computed(() => props.id) const hasTasks = computed(() => store.tasks.length > 0) const steps = ref( - props.initialTask - ? Task.fromTaskable(props.initialTask).steps - : hasTasks.value - ? [] - : exampleSteps + props.initialSteps?.length + ? props.initialSteps + : props.initialTask + ? Task.fromTaskable(props.initialTask).steps + : hasTasks.value + ? [] + : exampleSteps ) const title = ref(props.initialTask?.title ?? '') diff --git a/src/modules/task/infra/adaptStepsToTextarea.test.ts b/src/modules/task/infra/adaptStepsToTextarea.test.ts index 7d331a2..192d5b0 100644 --- a/src/modules/task/infra/adaptStepsToTextarea.test.ts +++ b/src/modules/task/infra/adaptStepsToTextarea.test.ts @@ -93,4 +93,40 @@ describe('adapt steps to textarea value', () => { `"9b237c28d5254f2b819fa66c853a9a60-2"` ) }) + + it('parses steps with unchecked checkbox format', () => { + const stepInTextarea = '- [ ] step with checkbox | 20' + + const expectedStep = fixtureStep({ + id: expect.any(String), + title: 'step with checkbox', + estimation: 20 + }) + + expect(adaptTextareaToSteps(stepInTextarea)).toEqual([expectedStep]) + }) + + it('parses steps with checked checkbox format', () => { + const stepInTextarea = '- [x] completed step | 15' + + const expectedStep = fixtureStep({ + id: expect.any(String), + title: 'completed step', + estimation: 15 + }) + + expect(adaptTextareaToSteps(stepInTextarea)).toEqual([expectedStep]) + }) + + it('parses checkbox steps without estimation', () => { + const stepInTextarea = '- [ ] step without estimation' + + const expectedStep = fixtureStep({ + id: expect.any(String), + title: 'step without estimation', + estimation: 0 + }) + + expect(adaptTextareaToSteps(stepInTextarea)).toEqual([expectedStep]) + }) }) diff --git a/src/modules/task/infra/adaptStepsToTextarea.ts b/src/modules/task/infra/adaptStepsToTextarea.ts index 602bb62..e815db3 100644 --- a/src/modules/task/infra/adaptStepsToTextarea.ts +++ b/src/modules/task/infra/adaptStepsToTextarea.ts @@ -9,7 +9,7 @@ const extractTitleAndEstimationFromStep = ( ): [string, number] => { const [rawTitle, rawEstimation] = rawStep .trim() - .replace(/^-\s*/, '') + .replace(/^-\s*(\[[ x]\]\s*)?/, '') .split('|') const title = rawTitle.trim() diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 28a7ae4..b6c4f2b 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -1,9 +1,12 @@