Skip to content

Commit

Permalink
fix: - keep done & cancelled date if they are present when status cha…
Browse files Browse the repository at this point in the history
…nged to done & cancelled respectively
  • Loading branch information
ilandikov committed Sep 19, 2024
1 parent 60738be commit 64e7123
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/ui/StatusEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,18 @@
const taskWithEditedStatusApplied = task.handleNewStatus(selectedStatus).pop();
if (taskWithEditedStatusApplied) {
// Update the doneDate field, in case changing the status changed the value:
editableTask.doneDate = taskWithEditedStatusApplied.done.formatAsDate();
editableTask.cancelledDate = taskWithEditedStatusApplied.cancelled.formatAsDate();
// XNOR logic:
// done date is empty and new status is DONE
// OR
// done date is filled and new status is not done
if ((editableTask.doneDate === '') === selectedStatus.isCompleted()) {
editableTask.doneDate = taskWithEditedStatusApplied.done.formatAsDate();
}
// same logic for cancelled date & CANCELLED status
if ((editableTask.cancelledDate === '') === selectedStatus.isCancelled()) {
editableTask.cancelledDate = taskWithEditedStatusApplied.cancelled.formatAsDate();
}
}
};
</script>
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/EditTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ describe('Task editing', () => {

it('should change status to Done and change doneDate', async () => {
const { waitForClose, container, submit } = await renderTaskModalAndChangeStatus(
'- [ ] expecting done date to be changed ✅ 2024-09-19',
'- [ ] expecting done date to be kept ✅ 2024-09-19',
'x',
);
expect(getElementValue(container, 'done')).toEqual(today);
expect(getElementValue(container, 'done')).toEqual('2024-09-19');

submit.click();
expect(await waitForClose).toMatchInlineSnapshot('"- [x] expecting done date to be changed ✅ 2024-02-29"');
expect(await waitForClose).toMatchInlineSnapshot('"- [x] expecting done date to be kept ✅ 2024-09-19"');
});

it('should change status to Todo and remove doneDate', async () => {
Expand Down Expand Up @@ -382,14 +382,14 @@ describe('Task editing', () => {

it('should change status to Cancelled and change cancelledDate', async () => {
const { waitForClose, container, submit } = await renderTaskModalAndChangeStatus(
'- [ ] expecting cancelled date to be changed ❌ 2024-09-20',
'- [ ] expecting cancelled date to be kept ❌ 2024-09-20',
'-',
);
expect(getElementValue(container, 'cancelled')).toEqual(today);
expect(getElementValue(container, 'cancelled')).toEqual('2024-09-20');

submit.click();
expect(await waitForClose).toMatchInlineSnapshot(
'"- [-] expecting cancelled date to be changed ❌ 2024-02-29"',
'"- [-] expecting cancelled date to be kept ❌ 2024-02-29"',
);
});

Expand Down

0 comments on commit 64e7123

Please sign in to comment.