-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(examples/tasks): add tasks entity
- Loading branch information
Mohammad Hasani
committed
Feb 14, 2019
1 parent
f6c8247
commit 35372da
Showing
11 changed files
with
437 additions
and
7 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
153 changes: 153 additions & 0 deletions
153
examples/tasks/src/store/__tests__/__snapshots__/tasks.spec.ts.snap
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,153 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`tasks entity action creators should create an action to add task 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"description": "Obviously a good tasks is good", | ||
"id": "5", | ||
"isFinished": false, | ||
"title": "A good task", | ||
}, | ||
"type": "[Tasks] add", | ||
} | ||
`; | ||
|
||
exports[`tasks entity action creators should create an action to add task 2`] = ` | ||
Object { | ||
"payload": Object { | ||
"description": "Obviously a good tasks is good", | ||
"id": "5", | ||
"isFinished": true, | ||
"title": "A good task", | ||
}, | ||
"type": "[Tasks] add", | ||
} | ||
`; | ||
|
||
exports[`tasks entity action creators should create an action to edit task 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"x": Object { | ||
"isFinished": true, | ||
"title": "New title for task", | ||
}, | ||
}, | ||
"type": "[Tasks] edit", | ||
} | ||
`; | ||
|
||
exports[`tasks entity action creators should create an action to remove all finished tasks 1`] = ` | ||
Object { | ||
"type": "[Tasks] remove finished", | ||
} | ||
`; | ||
|
||
exports[`tasks entity action creators should create an action to remove task 1`] = ` | ||
Object { | ||
"payload": "x", | ||
"type": "[Tasks] remove", | ||
} | ||
`; | ||
|
||
exports[`tasks entity tasks reducer should handle "[Tasks] add" 1`] = ` | ||
Object { | ||
"allIds": Array [ | ||
"5", | ||
], | ||
"byId": Object { | ||
"5": Object { | ||
"description": "Obviously a good tasks is good", | ||
"id": "5", | ||
"isFinished": false, | ||
"title": "A good task", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`tasks entity tasks reducer should handle "[Tasks] add" 2`] = ` | ||
Object { | ||
"allIds": Array [ | ||
"5", | ||
], | ||
"byId": Object { | ||
"5": Object { | ||
"description": "Obviously a good tasks is good", | ||
"id": "5", | ||
"isFinished": true, | ||
"title": "A good task", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`tasks entity tasks reducer should handle "[Tasks] edit" 1`] = ` | ||
Object { | ||
"allIds": Array [ | ||
"x", | ||
], | ||
"byId": Object { | ||
"x": Object { | ||
"description": "Obviously a good tasks is good", | ||
"id": "x", | ||
"isFinished": false, | ||
"title": "New title for task", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`tasks entity tasks reducer should handle "[Tasks] edit" 2`] = ` | ||
Object { | ||
"allIds": Array [ | ||
"x", | ||
], | ||
"byId": Object { | ||
"x": Object { | ||
"description": "New description for task", | ||
"id": "x", | ||
"isFinished": false, | ||
"title": "A good task", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`tasks entity tasks reducer should handle "[Tasks] edit" 3`] = ` | ||
Object { | ||
"allIds": Array [ | ||
"x", | ||
], | ||
"byId": Object { | ||
"x": Object { | ||
"description": "Obviously a good tasks is good", | ||
"id": "x", | ||
"isFinished": true, | ||
"title": "A good task", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`tasks entity tasks reducer should handle "[Tasks] remove finished" 1`] = ` | ||
Object { | ||
"allIds": Array [ | ||
"y", | ||
], | ||
"byId": Object { | ||
"y": Object { | ||
"description": ":|", | ||
"id": "y", | ||
"isFinished": false, | ||
"title": "Another good task", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`tasks entity tasks reducer should handle "[Tasks] remove" 1`] = ` | ||
Object { | ||
"allIds": Array [], | ||
"byId": Object {}, | ||
} | ||
`; |
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,130 @@ | ||
import { | ||
addTask, | ||
editTask, | ||
removeFinishedTasks, | ||
removeTask, | ||
tasks, | ||
} from '../tasks' | ||
|
||
describe('tasks entity', () => { | ||
describe('action creators', () => { | ||
it.each([ | ||
{ | ||
title: 'A good task', | ||
description: 'Obviously a good tasks is good', | ||
}, | ||
{ | ||
title: 'A good task', | ||
description: 'Obviously a good tasks is good', | ||
isFinished: true, | ||
}, | ||
])('should create an action to add task', task => { | ||
const now = Date.now | ||
Date.now = () => 5 | ||
|
||
expect(addTask(task)).toMatchSnapshot() | ||
|
||
Date.now = now | ||
}) | ||
|
||
it('should create an action to remove task', () => { | ||
expect(removeTask('x')).toMatchSnapshot() | ||
}) | ||
|
||
it('should create an action to edit task', () => { | ||
const id = 'x' | ||
const update = { title: 'New title for task', isFinished: true } | ||
expect(editTask(id, update)).toMatchSnapshot() | ||
}) | ||
|
||
it('should create an action to remove all finished tasks', () => { | ||
expect(removeFinishedTasks()).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('tasks reducer', () => { | ||
it.each([ | ||
{ | ||
title: 'A good task', | ||
description: 'Obviously a good tasks is good', | ||
}, | ||
{ | ||
title: 'A good task', | ||
description: 'Obviously a good tasks is good', | ||
isFinished: true, | ||
}, | ||
])('should handle "[Tasks] add"', task => { | ||
const now = Date.now | ||
Date.now = () => 5 | ||
|
||
const action = addTask(task) | ||
|
||
expect(tasks(undefined, action)).toMatchSnapshot() | ||
|
||
Date.now = now | ||
}) | ||
|
||
it('should handle "[Tasks] remove"', () => { | ||
const id = 'x' | ||
const state = { | ||
byId: { | ||
[id]: { | ||
id, | ||
title: 'A good task', | ||
description: 'Obviously a good tasks is good', | ||
isFinished: false, | ||
}, | ||
}, | ||
allIds: [id], | ||
} | ||
const action = removeTask(id) | ||
|
||
expect(tasks(state, action)).toMatchSnapshot() | ||
}) | ||
|
||
it.each([ | ||
{ title: 'New title for task' }, | ||
{ description: 'New description for task' }, | ||
{ isFinished: true }, | ||
])('should handle "[Tasks] edit"', update => { | ||
const id = 'x' | ||
const state = { | ||
byId: { | ||
[id]: { | ||
id, | ||
title: 'A good task', | ||
description: 'Obviously a good tasks is good', | ||
isFinished: false, | ||
}, | ||
}, | ||
allIds: [id], | ||
} | ||
const action = editTask(id, update) | ||
|
||
expect(tasks(state, action)).toMatchSnapshot() | ||
}) | ||
|
||
it('should handle "[Tasks] remove finished"', () => { | ||
const state = { | ||
byId: { | ||
x: { | ||
id: 'x', | ||
title: 'A good task', | ||
description: 'Obviously a good tasks is good', | ||
isFinished: true, | ||
}, | ||
y: { | ||
id: 'y', | ||
title: 'Another good task', | ||
description: ':|', | ||
isFinished: false, | ||
}, | ||
}, | ||
allIds: ['x', 'y'], | ||
} | ||
const action = removeFinishedTasks() | ||
|
||
expect(tasks(state, action)).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,3 +1,13 @@ | ||
export { configureStore } from './configure-store' | ||
|
||
export { RootState } from './root' | ||
|
||
export { | ||
addTask, | ||
removeTask, | ||
removeFinishedTasks, | ||
editTask, | ||
Task, | ||
} from './tasks' | ||
|
||
export * from './selectors' |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { combineReducers } from 'redux' | ||
|
||
import { tasks } from './tasks' | ||
|
||
export type RootState = ReturnType<typeof root> | ||
|
||
export const root = combineReducers({}) | ||
export const root = combineReducers({ tasks }) |
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,5 @@ | ||
import { RootState } from './root' | ||
import * as fromTasks from './tasks' | ||
|
||
export const getAllTasks = (state: RootState) => | ||
fromTasks.getAllTasks(state.tasks) |
Oops, something went wrong.