* WindowLevel preset code changes * Remove localStorage code as its already being saved and some small refactor on reducer/action * Creating unit tests for preferences reducer * Fix cypress after class naming change * Make hidden false as default for tab components * Remove addUserPreferences * Small refactor to use commandsManager from getCommandsModule instead of getting it from App.js
This commit is contained in:
1 parent
4fd0c6dfcb
commit
ebc01a8ca2
18 files changed
+510
-119
No files matched your search
@@ -10,6 +10,7 @@ import {
|
||||
SET_VIEWPORT_ACTIVE,
|
||||
SET_VIEWPORT_LAYOUT,
|
||||
SET_VIEWPORT_LAYOUT_AND_DATA,
|
||||
SET_USER_PREFERENCES,
|
||||
} from './constants/ActionTypes.js';
|
||||
|
||||
/**
|
||||
@@ -89,7 +90,7 @@ export const clearStudyLoadingProgress = progressId => ({
|
||||
});
|
||||
|
||||
export const setUserPreferences = state => ({
|
||||
type: 'SET_USER_PREFERENCES',
|
||||
type: SET_USER_PREFERENCES,
|
||||
state,
|
||||
});
|
||||
|
||||
|
||||
@@ -20,3 +20,8 @@ export const SET_SERVERS = 'SET_SERVERS';
|
||||
* EXTENSIONS
|
||||
*/
|
||||
export const SET_EXTENSION_DATA = 'SET_EXTENSION_DATA';
|
||||
|
||||
/**
|
||||
* PREFERENCES
|
||||
* */
|
||||
export const SET_USER_PREFERENCES = 'SET_USER_PREFERENCES';
|
||||
@@ -1,25 +1,30 @@
|
||||
import cloneDeep from 'lodash.clonedeep';
|
||||
|
||||
const defaultState = {
|
||||
windowLevelData: {
|
||||
// order, description, window (int), level (int)
|
||||
// 0: { description: 'Soft tissue', window: '', level: '' },
|
||||
1: { description: 'Soft tissue', window: '550', level: '40' },
|
||||
2: { description: 'Lung', window: '150', level: '-600' },
|
||||
3: { description: 'Liver', window: '150', level: '90' },
|
||||
4: { description: 'Bone', window: '2500', level: '480' },
|
||||
5: { description: 'Brain', window: '80', level: '40' },
|
||||
6: { description: 'Trest', window: '1', level: '1' },
|
||||
7: { description: '', window: '', level: '' },
|
||||
8: { description: '', window: '', level: '' },
|
||||
9: { description: '', window: '', level: '' },
|
||||
10: { description: '', window: '', level: '' },
|
||||
},
|
||||
generalPreferences: {
|
||||
// language: 'en-US'
|
||||
},
|
||||
};
|
||||
|
||||
const preferences = (state, action) => {
|
||||
const preferences = (state = defaultState, action) => {
|
||||
switch (action.type) {
|
||||
case 'SET_USER_PREFERENCES': {
|
||||
const newState = action.state || cloneDeep(defaultState);
|
||||
|
||||
return Object.assign({}, state, newState);
|
||||
return Object.assign({}, state, action.state);
|
||||
}
|
||||
default:
|
||||
return cloneDeep(state) || cloneDeep(defaultState);
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export { defaultState };
|
||||
export default preferences;
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Reducer } from 'redux-testkit';
|
||||
|
||||
import reducer, { defaultState } from './preferences';
|
||||
import { SET_USER_PREFERENCES } from './../constants/ActionTypes.js';
|
||||
|
||||
describe('preferences reducer', () => {
|
||||
it('should return the initial state', () => {
|
||||
expect(reducer(undefined, {})).toEqual(defaultState);
|
||||
});
|
||||
|
||||
it('should set user preferences state and properly merge with current state', () => {
|
||||
const initialState = defaultState;
|
||||
|
||||
const action = {
|
||||
type: SET_USER_PREFERENCES,
|
||||
state: { generalPreferences: { language: 'es' } },
|
||||
};
|
||||
|
||||
const expectedState = {
|
||||
windowLevelData: defaultState.windowLevelData,
|
||||
generalPreferences: {
|
||||
language: 'es',
|
||||
},
|
||||
};
|
||||
|
||||
Reducer(reducer)
|
||||
.withState(initialState)
|
||||
.expect(action)
|
||||
.toReturnState(expectedState);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user