diff --git a/src/reducers/__tests__/pluginStates.node.js b/src/reducers/__tests__/pluginStates.node.js index e7ab88fd5..57c5a7bd2 100644 --- a/src/reducers/__tests__/pluginStates.node.js +++ b/src/reducers/__tests__/pluginStates.node.js @@ -6,11 +6,27 @@ */ import {default as reducer, setPluginState} from '../pluginStates'; +import type {Action} from '../pluginStates'; test('reduce setPluginState', () => { - const res = reducer( + const result = reducer( {}, setPluginState({pluginKey: 'myPlugin', state: {a: 1}}), ); - expect(res).toEqual({myPlugin: {a: 1}}); + expect(result).toEqual({myPlugin: {a: 1}}); +}); + +test('CLEAR_PLUGIN_STATE removes plugin state', () => { + const clientId = 'app1#device1'; + const pluginKey = 'app1#device1#plugin1'; + + const action: Action = { + type: 'CLEAR_PLUGIN_STATE', + payload: {id: clientId, devicePlugins: new Set()}, + }; + const result = reducer( + {[pluginKey]: {a: 1}, 'anotherPlugin#key': {b: 2}}, + action, + ); + expect(result).toEqual({'anotherPlugin#key': {b: 2}}); }); diff --git a/src/reducers/pluginStates.js b/src/reducers/pluginStates.js index c08ca0cfd..6f899971a 100644 --- a/src/reducers/pluginStates.js +++ b/src/reducers/pluginStates.js @@ -49,8 +49,9 @@ export default function reducer( return Object.keys(state).reduce((newState, pluginKey) => { // Only add the pluginState, if its from a plugin other than the one that // was removed. pluginKeys are in the form of ${clientID}#${pluginID}. + const clientId = pluginKey.slice(0, pluginKey.lastIndexOf('#')); const pluginId = pluginKey.split('#').pop(); - if (pluginId !== payload.id || payload.devicePlugins.has(pluginId)) { + if (clientId !== payload.id || payload.devicePlugins.has(pluginId)) { newState[pluginKey] = state[pluginKey]; } return newState;