-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
166 additions
and
114 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,65 @@ | ||
import { EditorState } from 'applications/editor/tools/types'; | ||
import { createStoreWithoutMiddleware } from 'Store'; | ||
import editorTestDataBuilder from './editorTestDataBuilder'; | ||
import { | ||
editorInitialState, | ||
selectLayers, | ||
editorSlice, | ||
loadDataModelAction, | ||
updateTotalsIssueAction, | ||
updateFiltersIssueAction, | ||
} from '..'; | ||
|
||
const createStore = (initialStateExtra?: EditorState) => | ||
createStoreWithoutMiddleware({ | ||
[editorSlice.name]: initialStateExtra, | ||
}); | ||
|
||
describe('editorReducer', () => { | ||
const testDataBuilder = editorTestDataBuilder(); | ||
it('should return initial state', () => { | ||
const store = createStore(); | ||
const editorState = store.getState()[editorSlice.name]; | ||
expect(editorState).toEqual(editorInitialState); | ||
}); | ||
|
||
it('should handle selectLayers', () => { | ||
const store = createStore(); | ||
const editorLayers = testDataBuilder.buildEditorLayers(['catenaries', 'routes']); | ||
store.dispatch(selectLayers(editorLayers)); | ||
const editorState = store.getState()[editorSlice.name]; | ||
expect(editorState.editorLayers).toEqual(new Set(['catenaries', 'routes'])); | ||
}); | ||
|
||
describe('should handle loadDataModelAction', () => { | ||
it('should have empty array initially', () => { | ||
const store = createStore(); | ||
const editorState = store.getState()[editorSlice.name]; | ||
expect(editorState.editorSchema).toEqual([]); | ||
}); | ||
|
||
it('should update editorSchema', () => { | ||
const store = createStore(); | ||
const editorSchema = testDataBuilder.buildEditorSchema(); | ||
store.dispatch(loadDataModelAction(editorSchema)); | ||
const editorState = store.getState()[editorSlice.name]; | ||
expect(editorState.editorSchema).toEqual(editorSchema); | ||
}); | ||
}); | ||
|
||
it('should handle updateTotalIssueAction', () => { | ||
const store = createStore(); | ||
const newIssues = testDataBuilder.buildTotalIssue(5, 10); | ||
store.dispatch(updateTotalsIssueAction(newIssues)); | ||
const editorState = store.getState()[editorSlice.name]; | ||
expect(editorState.issues).toEqual({ ...editorInitialState.issues, ...newIssues }); | ||
}); | ||
|
||
it('should handle updateFiltersIssueAction', () => { | ||
const store = createStore(); | ||
const newIssues = testDataBuilder.buildFilterIssue('warnings', 'empty_object'); | ||
store.dispatch(updateFiltersIssueAction(newIssues)); | ||
const editorState = store.getState()[editorSlice.name]; | ||
expect(editorState.issues).toEqual({ ...editorInitialState.issues, ...newIssues }); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
front/src/reducers/editor/__tests__/editorTestDataBuilder.ts
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,26 @@ | ||
import { LayerType, EditorState } from 'applications/editor/tools/types'; | ||
|
||
export default function editorTestDataBuilder() { | ||
return { | ||
buildEditorLayers: (layers: Array<LayerType>): EditorState['editorLayers'] => new Set(layers), | ||
buildEditorSchema: (): EditorState['editorSchema'] => [ | ||
{ layer: 'layerA', objType: 'BufferStop', schema: {} }, | ||
{ layer: 'layerA', objType: 'Route', schema: {} }, | ||
{ layer: 'layerA', objType: 'SwitchType', schema: {} }, | ||
], | ||
buildTotalIssue: ( | ||
total: EditorState['issues']['total'], | ||
filterTotal: EditorState['issues']['filterTotal'] | ||
): Pick<EditorState['issues'], 'total' | 'filterTotal'> => ({ | ||
total, | ||
filterTotal, | ||
}), | ||
buildFilterIssue: ( | ||
filterLevel: EditorState['issues']['filterLevel'], | ||
filterType: EditorState['issues']['filterType'] | ||
): Omit<EditorState['issues'], 'total' | 'filterTotal'> => ({ | ||
filterLevel, | ||
filterType, | ||
}), | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import { EditorState } from 'applications/editor/tools/types'; | ||
import { RootState } from 'reducers'; | ||
import { makeSubSelector } from 'utils/selectors'; | ||
|
||
export const getEditorState = (state: RootState) => state.editor; | ||
export const getEditorIssue = (state: RootState) => state.editor.issues; | ||
const makeEditorSelector = makeSubSelector<EditorState>(getEditorState); | ||
|
||
export const getEditorIssue = makeEditorSelector('issues'); |
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