From e69d7ff98cf095485413d14c04b8744226ea6c42 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Thu, 11 Jun 2015 12:44:28 +0200 Subject: [PATCH] test to show back browsing is broken after selecting a node --- .../stores/__tests__/app-store-test.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/client/app/scripts/stores/__tests__/app-store-test.js b/client/app/scripts/stores/__tests__/app-store-test.js index acc7065c0..bcca13750 100644 --- a/client/app/scripts/stores/__tests__/app-store-test.js +++ b/client/app/scripts/stores/__tests__/app-store-test.js @@ -5,8 +5,17 @@ describe('AppStore', function() { let AppStore; let registeredCallback; + // fixtures + + const NODE_SET = {n1: {id: 'n1'}, n2: {id: 'n2'}}; + // actions + const ClickNodeAction = { + type: ActionTypes.CLICK_NODE, + nodeId: 'n1' + }; + const ClickTopologyAction = { type: ActionTypes.CLICK_TOPOLOGY, topologyId: 'topo1' @@ -17,6 +26,21 @@ describe('AppStore', function() { grouping: 'grouped' }; + const HitEscAction = { + type: ActionTypes.HIT_ESC_KEY + }; + + const ReceiveNodesDeltaAction = { + type: ActionTypes.RECEIVE_NODES_DELTA, + delta: { + add: [{ + id: 'n1' + }, { + id: 'n2' + }] + } + }; + const ReceiveTopologiesAction = { type: ActionTypes.RECEIVE_TOPOLOGIES, topologies: [{ @@ -26,6 +50,11 @@ describe('AppStore', function() { }] }; + const RouteAction = { + type: ActionTypes.ROUTE_TOPOLOGY, + state: {} + }; + beforeEach(function() { AppStore = require('../app-store'); registeredCallback = AppStore.registeredCallback; @@ -58,4 +87,42 @@ describe('AppStore', function() { expect(AppStore.getCurrentTopologyUrl()).toBe('/topo1grouped'); }); + // browsing + + it('shows nodes that were received', function() { + registeredCallback(ReceiveNodesDeltaAction); + expect(AppStore.getNodes()).toEqual(NODE_SET); + }); + + it('gets selected node after click', function() { + registeredCallback(ReceiveNodesDeltaAction); + + registeredCallback(ClickNodeAction); + expect(AppStore.getSelectedNodeId()).toBe('n1'); + expect(AppStore.getNodes()).toEqual(NODE_SET); + + registeredCallback(HitEscAction) + expect(AppStore.getSelectedNodeId()).toBe(null); + expect(AppStore.getNodes()).toEqual(NODE_SET); + }); + + it('keeps showing nodes on navigating back after node click', function() { + registeredCallback(ReceiveNodesDeltaAction); + // TODO clear AppStore cache + expect(AppStore.getAppState()) + .toEqual({"topologyId":"topo1","grouping":"grouped","selectedNodeId": null}); + + registeredCallback(ClickNodeAction); + expect(AppStore.getAppState()) + .toEqual({"topologyId":"topo1","grouping":"grouped","selectedNodeId": 'n1'}); + + // go back in browsing + RouteAction.state = {"topologyId":"topo1","grouping":"grouped","selectedNodeId": null}; + registeredCallback(RouteAction); + expect(AppStore.getSelectedNodeId()).toBe(null); + expect(AppStore.getNodes()).toEqual(NODE_SET); + + }); + + }); \ No newline at end of file