Skip to content
Snippets Groups Projects
Commit 3b14cec0 authored by Jack Reed's avatar Jack Reed
Browse files

Add back reducer UPDATE_VIEWPORT test and test window cleanup

parent a5909ebe
No related branches found
No related tags found
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) => { ...@@ -12,6 +12,13 @@ export const viewersReducer = (state = {}, action) => {
...action.payload, ...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: default:
return state; return state;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment