-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for todo date functionalities
- Loading branch information
1 parent
546514f
commit 5ea5362
Showing
12 changed files
with
513 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Badge from './Badge.svelte'; | ||
|
||
describe('Badge', () => { | ||
it('renders as li when variant=li', () => { | ||
cy.mount(Badge, { | ||
props: { | ||
variant: 'li', | ||
'data-cy': 'badge', | ||
}, | ||
}); | ||
|
||
cy.get('li[data-cy="badge"]').should('be.visible'); | ||
cy.get('li[data-cy="badge"] span').should('not.exist'); | ||
}); | ||
|
||
it('renders as span when variant=span', () => { | ||
cy.mount(Badge, { | ||
props: { | ||
variant: 'span', | ||
'data-cy': 'badge', | ||
}, | ||
}); | ||
|
||
cy.get('span[data-cy="badge"]').should('be.visible'); | ||
cy.get('span[data-cy="badge"] span').should('not.exist'); | ||
}); | ||
|
||
it('renders icon slot when icon=true', () => { | ||
cy.mount(Badge, { | ||
props: { | ||
variant: 'span', | ||
icon: true, | ||
'data-cy': 'badge', | ||
}, | ||
}); | ||
|
||
cy.get('span[data-cy="badge"] span').should('be.visible'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/features/todos/components/TodoFormOptionalFields.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import TodoFormOptionalFields from './TodoFormOptionalFields.svelte'; | ||
|
||
import { settings } from '@features/settings/store'; | ||
import { generateTodo } from '../utils/test-helpers'; | ||
|
||
describe('TodoFormOptionalFields', () => { | ||
beforeEach(() => { | ||
cy.viewport(500, 500); | ||
|
||
settings.set({}); | ||
}); | ||
|
||
it('hides fields when settings.openOptionalFields=false', () => { | ||
settings.set({ openOptionalFields: false }); | ||
const data = generateTodo(); | ||
|
||
cy.mount(TodoFormOptionalFields, { | ||
props: { data }, | ||
}); | ||
|
||
cy.get('[data-cy="todo-form-optional-fields"]').should('not.have.attr', 'open'); | ||
}); | ||
|
||
it('displays fields when settings.openOptionalFields=true', () => { | ||
settings.set({ openOptionalFields: true }); | ||
const data = generateTodo(); | ||
|
||
cy.mount(TodoFormOptionalFields, { | ||
props: { data }, | ||
}); | ||
|
||
cy.get('[data-cy="todo-form-optional-fields"]').should('have.attr', 'open'); | ||
}); | ||
|
||
it('displays fields when any optional field is set in the todo item', () => { | ||
settings.set({ openOptionalFields: false }); | ||
const data = generateTodo({ date: '2024-10-27' }); | ||
|
||
cy.mount(TodoFormOptionalFields, { | ||
props: { data }, | ||
}); | ||
|
||
cy.get('[data-cy="todo-form-optional-fields"]').should('have.attr', 'open'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import TodoItemDate from './TodoItemDate.svelte'; | ||
|
||
import { TODOS_DATE_ABSOLUTE, TODOS_DATE_RELATIVE } from '@features/todos/constants'; | ||
|
||
describe('TodoItemDate', () => { | ||
beforeEach(() => { | ||
cy.clock(new Date(2024, 0, 1)); | ||
}); | ||
|
||
it('displays date in absolute format', () => { | ||
const date = '2024-01-10'; | ||
|
||
cy.mount(TodoItemDate, { | ||
props: { | ||
date, | ||
variant: TODOS_DATE_ABSOLUTE, | ||
}, | ||
}); | ||
|
||
cy.get('[data-cy="todo-item-date"]').should('contain.text', 'Jan 10'); | ||
}); | ||
|
||
it('displays date in relative format', () => { | ||
const date = '2024-01-10'; | ||
|
||
cy.mount(TodoItemDate, { | ||
props: { | ||
date, | ||
variant: TODOS_DATE_RELATIVE, | ||
}, | ||
}); | ||
|
||
cy.get('[data-cy="todo-item-date"]').should('contain.text', 'In 9 days'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { settings } from '@features/settings/store'; | ||
|
||
import { initializeTodos } from '.'; | ||
import { TODOS_EVENTUALLY, TODOS_THIS_WEEK, TODOS_TODAY } from './constants'; | ||
import { todos } from './store'; | ||
import { generateTodo } from './utils/test-helpers'; | ||
|
||
describe('initializeTodos', () => { | ||
const yesterday = new Date(2024, 0, 2); // tuesday | ||
const today = new Date(2024, 0, 3); // wednesday | ||
|
||
beforeEach(() => { | ||
cy.clock(today); | ||
|
||
settings.set({}); | ||
todos.set([]); | ||
}); | ||
|
||
it('skips moving todos when settings.moveTodosAutomatically is false', () => { | ||
settings.set({ moveTodosAutomatically: false }); | ||
|
||
const todosSpy = cy.spy(); | ||
todos.subscribe(todosSpy); | ||
|
||
initializeTodos(); | ||
|
||
cy.wrap(todosSpy).should('have.always.been.calledWith', []); | ||
}); | ||
|
||
it('skips moving todos when it was already done for the current day', () => { | ||
settings.set({ | ||
moveTodosAutomatically: true, | ||
moveTodosLastUpdated: today.getTime(), | ||
}); | ||
|
||
const todosSpy = cy.spy(); | ||
todos.subscribe(todosSpy); | ||
|
||
initializeTodos(); | ||
|
||
cy.wrap(todosSpy).should('have.always.been.calledWith', []); | ||
}); | ||
|
||
it('moves todos to today list when their date is the current day', () => { | ||
settings.set({ | ||
moveTodosAutomatically: true, | ||
moveTodosLastUpdated: yesterday.getTime(), | ||
}); | ||
|
||
const todo = generateTodo({ | ||
list: TODOS_EVENTUALLY, | ||
date: '2024-01-03', | ||
}); | ||
todos.set([todo]); | ||
|
||
const todosSpy = cy.spy(); | ||
todos.subscribe(todosSpy); | ||
|
||
initializeTodos(); | ||
|
||
cy.wrap(todosSpy).should('have.been.calledWith', [{ ...todo, list: TODOS_TODAY }]); | ||
}); | ||
|
||
it('moves todos to this week list when their date is within the current week', () => { | ||
settings.set({ | ||
moveTodosAutomatically: true, | ||
moveTodosLastUpdated: yesterday.getTime(), | ||
}); | ||
|
||
const todo = generateTodo({ | ||
list: TODOS_EVENTUALLY, | ||
date: '2024-01-05', | ||
}); | ||
todos.set([todo]); | ||
|
||
const todosSpy = cy.spy(); | ||
todos.subscribe(todosSpy); | ||
|
||
initializeTodos(); | ||
|
||
cy.wrap(todosSpy).should('have.been.calledWith', [{ ...todo, list: TODOS_THIS_WEEK }]); | ||
}); | ||
|
||
it('skips moving todos when their date is within the current week but has already past', () => { | ||
settings.set({ | ||
moveTodosAutomatically: true, | ||
moveTodosLastUpdated: yesterday.getTime(), | ||
}); | ||
|
||
const todo = generateTodo({ | ||
list: TODOS_EVENTUALLY, | ||
date: '2024-01-02', | ||
}); | ||
todos.set([todo]); | ||
|
||
const todosSpy = cy.spy(); | ||
todos.subscribe(todosSpy); | ||
|
||
initializeTodos(); | ||
|
||
cy.wrap(todosSpy).should('have.always.been.calledWith', [todo]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.