Skip to content

Commit fdc7944

Browse files
committed
add TodoList toggle all button testn
1 parent b09bab1 commit fdc7944

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/App/TodoList/index.test.tsx

+24-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ const initialStore: Store = {
1717
bodyText: 'boss black',
1818
completed: false
1919
},
20-
{ id: 'QwejYipEf5nk', bodyText: 'caffe latte', completed: false }
20+
{
21+
id: 'QwejYipEf5nk',
22+
bodyText: 'caffe latte',
23+
completed: false
24+
}
2125
]
2226
}
2327

@@ -52,3 +56,22 @@ test('should reflect store value change to render elements', () => {
5256
expect(getAllByTestId('todo-item')[0]).toHaveTextContent('boss black')
5357
expect(getAllByTestId('todo-item')[1]).toHaveTextContent('caffe latte')
5458
})
59+
60+
test('should click toggle-all-button, then all item being comlete checked true and vice versa', () => {
61+
const { getByTestId, getAllByTestId } = render(
62+
<Provider store={initialStore}>
63+
<TodoList path="/" />
64+
</Provider>
65+
)
66+
67+
fireEvent.click(getByTestId('toggle-all-btn'))
68+
expect((getAllByTestId('todo-item-complete-check')[0] as HTMLInputElement).checked).toBe(true) /* eslint-disable-line prettier/prettier */
69+
expect((getAllByTestId('todo-item-complete-check')[1] as HTMLInputElement).checked).toBe(true) /* eslint-disable-line prettier/prettier */
70+
expect((getAllByTestId('todo-item-complete-check')[2] as HTMLInputElement).checked).toBe(true) /* eslint-disable-line prettier/prettier */
71+
72+
73+
fireEvent.click(getByTestId('toggle-all-btn'))
74+
expect((getAllByTestId('todo-item-complete-check')[0] as HTMLInputElement).checked).toBe(false) /* eslint-disable-line prettier/prettier */
75+
expect((getAllByTestId('todo-item-complete-check')[1] as HTMLInputElement).checked).toBe(false) /* eslint-disable-line prettier/prettier */
76+
expect((getAllByTestId('todo-item-complete-check')[2] as HTMLInputElement).checked).toBe(false) /* eslint-disable-line prettier/prettier */
77+
})

src/App/TodoList/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function TodoList({ path }: Props) {
3131
type="checkbox"
3232
onChange={toggleAll}
3333
data-cy="toggle-all-btn"
34+
data-testid="toggle-all-btn"
3435
/>
3536
<label htmlFor="toggle-all">Mark all as complete</label>
3637
<ul className="todo-list" data-testid="todo-list">

0 commit comments

Comments
 (0)