Skip to content

Commit

Permalink
Update TaskCheckbox.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Nov 20, 2024
1 parent 7d20443 commit 097ca52
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/components/TaskCheckbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,73 @@ describe('TaskCheckbox', () => {

expect(updateTask).toHaveBeenCalledWith('123', { complete: true });
});

it('should not update task without id', async () => {
const task: TaskType = {
task: 'test task',
due: '2024-01-01T00:00:00',
cents: 100,
complete: false,
status: 'pending',
timezone: 'UTC'
};

const event = new Event('change');

await toggleComplete({ event, task, isConfirming: false });

expect(updateTask).not.toHaveBeenCalled();
});

it('should prompt for confirmation when uncompleting past due task', async () => {
const task: TaskType = {
id: '123',
task: 'test task',
due: '2023-01-01T00:00:00',
cents: 100,
complete: true,
status: 'complete',
timezone: 'UTC'
};

vi.setSystemTime(new Date('2024-01-01'));
const event = new Event('change');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
vi.spyOn(event, 'target', 'get').mockReturnValue(checkbox);
vi.spyOn(window, 'confirm').mockReturnValue(false);

await toggleComplete({ event, task, isConfirming: false });

expect(window.confirm).toHaveBeenCalledWith(
'This task is past due. Marking it incomplete will require contacting support to undo. Continue?'
);
expect(updateTask).not.toHaveBeenCalled();
expect(checkbox.checked).toBe(true);
});

it('should update past due task when confirmed', async () => {
const task: TaskType = {
id: '123',
task: 'test task',
due: '2023-01-01T00:00:00',
cents: 100,
complete: true,
status: 'complete',
timezone: 'UTC'
};

vi.setSystemTime(new Date('2024-01-01'));
const event = new Event('change');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
vi.spyOn(event, 'target', 'get').mockReturnValue(checkbox);
vi.spyOn(window, 'confirm').mockReturnValue(true);

await toggleComplete({ event, task, isConfirming: false });

expect(updateTask).toHaveBeenCalledWith('123', { complete: false });
expect(task.complete).toBe(false);
expect(task.status).toBe('pending');
});
});

0 comments on commit 097ca52

Please sign in to comment.