|
1 | 1 | import undoableEditPeakReducer from "../../../reducers/reducer_edit_peak";
|
| 2 | +import { EDITPEAK, MANAGER } from "../../../constants/action_type"; |
| 3 | +import { editPeakReducer } from "../../../reducers/reducer_edit_peak"; |
2 | 4 |
|
3 | 5 | describe('Test redux reducer for edit peak', () => {
|
4 |
| - // TODO: need more test implementation |
5 |
| - it('Just a dump test', () => { |
6 |
| - expect(1).toEqual(1) |
| 6 | + interface PeaksState { |
| 7 | + selectedIdx: number, |
| 8 | + peaks: Object[] |
| 9 | + } |
| 10 | + |
| 11 | + interface PeaksAction { |
| 12 | + type: string |
| 13 | + payload: any |
| 14 | + } |
| 15 | + |
| 16 | + let peaksState: PeaksState |
| 17 | + let action: PeaksAction |
| 18 | + |
| 19 | + beforeEach(() => { |
| 20 | + peaksState = { peaks: [], selectedIdx: 0 } |
| 21 | + action = { type: "", payload: null } |
| 22 | + }) |
| 23 | + |
| 24 | + it('Get default state', () => { |
| 25 | + const newState = undoableEditPeakReducer(peaksState, action) |
| 26 | + expect(newState.present).toEqual(peaksState) |
| 27 | + }) |
| 28 | + |
| 29 | + it('Add new peak to positive peaks', () => { |
| 30 | + action.type = EDITPEAK.ADD_POSITIVE |
| 31 | + action.payload = { dataToAdd: {x: 1, y: 2}, curveIdx: 0 } |
| 32 | + |
| 33 | + const newState = editPeakReducer(peaksState, action) |
| 34 | + const expectedValue = [action.payload.dataToAdd] |
| 35 | + expect(newState.peaks[0].pos).toEqual(expectedValue) |
| 36 | + }) |
| 37 | + |
| 38 | + it('Add new peak to negative peaks', () => { |
| 39 | + action.type = EDITPEAK.ADD_NEGATIVE |
| 40 | + action.payload = { dataToAdd: {x: 1, y: 2}, curveIdx: 0 } |
| 41 | + |
| 42 | + const newState = editPeakReducer(peaksState, action) |
| 43 | + const expectedValue = [action.payload.dataToAdd] |
| 44 | + expect(newState.peaks[0].neg).toEqual(expectedValue) |
| 45 | + }) |
| 46 | + |
| 47 | + it('Remove a peak from positive peaks', () => { |
| 48 | + action.type = EDITPEAK.RM_POSITIVE |
| 49 | + action.payload = {x: 1, y: 2} |
| 50 | + |
| 51 | + peaksState = { peaks: [{pos: [{x: 1, y: 2}, {x: 3, y: 4}]}], selectedIdx: 0 } |
| 52 | + |
| 53 | + const newState = editPeakReducer(peaksState, action) |
| 54 | + const expectedValue = [{x: 3, y: 4}] |
| 55 | + expect(newState.peaks[0].pos).toEqual(expectedValue) |
| 56 | + }) |
| 57 | + |
| 58 | + it('Remove a peak from negative peaks', () => { |
| 59 | + action.type = EDITPEAK.RM_NEGATIVE |
| 60 | + action.payload = {x: 1, y: 2} |
| 61 | + |
| 62 | + peaksState = { peaks: [{neg: [{x: 1, y: 2}, {x: 3, y: 4}]}], selectedIdx: 0 } |
| 63 | + |
| 64 | + const newState = editPeakReducer(peaksState, action) |
| 65 | + const expectedValue = [{x: 3, y: 4}] |
| 66 | + expect(newState.peaks[0].neg).toEqual(expectedValue) |
| 67 | + }) |
| 68 | + |
| 69 | + it('Reset to default value', () => { |
| 70 | + action.type = MANAGER.RESETALL |
| 71 | + const expectedValue = {peaks: [{neg: [], pos: [], prevOffset: 0}], selectedIdx: 0} |
| 72 | + const newState = editPeakReducer(peaksState, action) |
| 73 | + expect(newState).toEqual(expectedValue) |
| 74 | + }) |
| 75 | + |
| 76 | + it('Clear all peaks', () => { |
| 77 | + action.type = EDITPEAK.CLEAR_ALL |
| 78 | + action.payload = { curveIdx: 0 } |
| 79 | + peaksState = { peaks: [{pos: [{x: 1, y: 2}, {x: 3, y: 4}]}], selectedIdx: 0 } |
| 80 | + const expectedValue = {peaks: [{neg: [], pos: [], prevOffset: 0}], selectedIdx: 0} |
| 81 | + const newState = editPeakReducer(peaksState, action) |
| 82 | + expect(newState).toEqual(expectedValue) |
7 | 83 | })
|
8 | 84 | })
|
0 commit comments