2021-10-28 23:39:47 +03:00
|
|
|
import expect from 'expect';
|
|
|
|
import todos from '../../reducers/todos';
|
|
|
|
import * as types from '../../constants/ActionTypes';
|
|
|
|
|
|
|
|
describe('todos reducer', () => {
|
|
|
|
it('should handle initial state', () => {
|
|
|
|
expect(todos(undefined, {})).toEqual([
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle ADD_TODO', () => {
|
|
|
|
expect(
|
|
|
|
todos([], {
|
|
|
|
type: types.ADD_TODO,
|
|
|
|
text: 'Run the tests',
|
2023-07-12 21:03:20 +03:00
|
|
|
}),
|
2021-10-28 23:39:47 +03:00
|
|
|
).toEqual([
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
todos(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
{
|
|
|
|
type: types.ADD_TODO,
|
|
|
|
text: 'Run the tests',
|
2023-07-12 21:03:20 +03:00
|
|
|
},
|
|
|
|
),
|
2021-10-28 23:39:47 +03:00
|
|
|
).toEqual([
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: false,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
todos(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: false,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
{
|
|
|
|
type: types.ADD_TODO,
|
|
|
|
text: 'Fix the tests',
|
2023-07-12 21:03:20 +03:00
|
|
|
},
|
|
|
|
),
|
2021-10-28 23:39:47 +03:00
|
|
|
).toEqual([
|
|
|
|
{
|
|
|
|
text: 'Fix the tests',
|
|
|
|
completed: false,
|
|
|
|
id: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: false,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle DELETE_TODO', () => {
|
|
|
|
expect(
|
|
|
|
todos(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: false,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
{
|
|
|
|
type: types.DELETE_TODO,
|
|
|
|
id: 1,
|
2023-07-12 21:03:20 +03:00
|
|
|
},
|
|
|
|
),
|
2021-10-28 23:39:47 +03:00
|
|
|
).toEqual([
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle EDIT_TODO', () => {
|
|
|
|
expect(
|
|
|
|
todos(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: false,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
{
|
|
|
|
type: types.EDIT_TODO,
|
|
|
|
text: 'Fix the tests',
|
|
|
|
id: 1,
|
2023-07-12 21:03:20 +03:00
|
|
|
},
|
|
|
|
),
|
2021-10-28 23:39:47 +03:00
|
|
|
).toEqual([
|
|
|
|
{
|
|
|
|
text: 'Fix the tests',
|
|
|
|
completed: false,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle COMPLETE_TODO', () => {
|
|
|
|
expect(
|
|
|
|
todos(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: false,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
{
|
|
|
|
type: types.COMPLETE_TODO,
|
|
|
|
id: 1,
|
2023-07-12 21:03:20 +03:00
|
|
|
},
|
|
|
|
),
|
2021-10-28 23:39:47 +03:00
|
|
|
).toEqual([
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: true,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle COMPLETE_ALL', () => {
|
|
|
|
expect(
|
|
|
|
todos(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: true,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
{
|
|
|
|
type: types.COMPLETE_ALL,
|
2023-07-12 21:03:20 +03:00
|
|
|
},
|
|
|
|
),
|
2021-10-28 23:39:47 +03:00
|
|
|
).toEqual([
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: true,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: true,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Unmark if all todos are currently completed
|
|
|
|
expect(
|
|
|
|
todos(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: true,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: true,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
{
|
|
|
|
type: types.COMPLETE_ALL,
|
2023-07-12 21:03:20 +03:00
|
|
|
},
|
|
|
|
),
|
2021-10-28 23:39:47 +03:00
|
|
|
).toEqual([
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: false,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle CLEAR_COMPLETED', () => {
|
|
|
|
expect(
|
|
|
|
todos(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: 'Run the tests',
|
|
|
|
completed: true,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
{
|
|
|
|
type: types.CLEAR_COMPLETED,
|
2023-07-12 21:03:20 +03:00
|
|
|
},
|
|
|
|
),
|
2021-10-28 23:39:47 +03:00
|
|
|
).toEqual([
|
|
|
|
{
|
|
|
|
text: 'Use Redux',
|
|
|
|
completed: false,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not generate duplicate ids after CLEAR_COMPLETED', () => {
|
|
|
|
expect(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.COMPLETE_TODO,
|
|
|
|
id: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: types.CLEAR_COMPLETED,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: types.ADD_TODO,
|
|
|
|
text: 'Write more tests',
|
|
|
|
},
|
|
|
|
].reduce(todos, [
|
|
|
|
{
|
|
|
|
id: 0,
|
|
|
|
completed: false,
|
|
|
|
text: 'Use Redux',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
completed: false,
|
|
|
|
text: 'Write tests',
|
|
|
|
},
|
2023-07-12 21:03:20 +03:00
|
|
|
]),
|
2021-10-28 23:39:47 +03:00
|
|
|
).toEqual([
|
|
|
|
{
|
|
|
|
text: 'Write more tests',
|
|
|
|
completed: false,
|
|
|
|
id: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'Write tests',
|
|
|
|
completed: false,
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|