Skip to content
Snippets Groups Projects
Unverified Commit 5edb867b authored by Chris Beer's avatar Chris Beer Committed by GitHub
Browse files

Merge pull request #1908 from ProjectMirador/test-viewer-cleanup

Add back reducer UPDATE_VIEWPORT test and test window cleanup
parents a5909ebe 3b14cec0
Branches
Tags
No related merge requests found
import { viewersReducer } from '../../../src/state/reducers/viewers';
import ActionTypes from '../../../src/state/actions/action-types';
describe('viewers reducer', () => {
it('should handle UPDATE_VIEWPORT', () => {
expect(viewersReducer({
abc123: {
x: 1,
},
def456: {
y: 1,
},
}, {
type: ActionTypes.UPDATE_VIEWPORT,
windowId: 'abc123',
payload: { x: 0, y: 1, zoom: 0.5 },
})).toEqual({
abc123: {
x: 0,
y: 1,
zoom: 0.5,
},
def456: {
y: 1,
},
});
});
it('should handle REMOVE_WINDOW', () => {
expect(viewersReducer({
abc123: {
foo: 'bar',
},
def456: {
foo: 'bar',
},
}, {
type: ActionTypes.REMOVE_WINDOW,
windowId: 'abc123',
})).toEqual({
def456: {
foo: 'bar',
},
});
});
});
......@@ -12,6 +12,13 @@ export const viewersReducer = (state = {}, action) => {
...action.payload,
},
};
case ActionTypes.REMOVE_WINDOW:
return Object.keys(state).reduce((object, key) => {
if (key !== action.windowId) {
object[key] = state[key]; // eslint-disable-line no-param-reassign
}
return object;
}, {});
default:
return state;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment