Skip to content

Commit

Permalink
Fixed the jest tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarl committed Jun 19, 2017
1 parent 3ab1624 commit 19552d6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion client/app/scripts/reducers/__tests__/root-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ describe('RootReducer', () => {

// other topology w/o options dont return options, but keep in app state
nextState = reducer(nextState, ClickTopology2Action);
expect(activeTopologyOptionsSelector(nextState)).toNotExist();
expect(activeTopologyOptionsSelector(nextState).size).toEqual(0);
expect(getUrlState(nextState).topologyOptions.topo1.option1).toEqual(['off']);
});

Expand Down
3 changes: 2 additions & 1 deletion client/app/scripts/selectors/time-travel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export const isNowSelector = createSelector(
[
state => state.get('timeTravelMillisecondsInPast')
],
timeTravelMillisecondsInPast => timeTravelMillisecondsInPast === 0
// true for values 0, undefined, null, etc...
timeTravelMillisecondsInPast => !(timeTravelMillisecondsInPast > 0)
);
27 changes: 24 additions & 3 deletions client/app/scripts/utils/__tests__/web-api-utils-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import MockDate from 'mockdate';
import { Map as makeMap, OrderedMap as makeOrderedMap } from 'immutable';

import {OrderedMap as makeOrderedMap} from 'immutable';
import { buildUrlQuery, basePath, getApiPath, getWebsocketUrl } from '../web-api-utils';


describe('WebApiUtils', () => {
describe('basePath', () => {
it('should handle /scope/terminal.html', () => {
Expand All @@ -22,15 +24,34 @@ describe('WebApiUtils', () => {
});

describe('buildUrlQuery', () => {
let state = makeMap();

beforeEach(() => {
MockDate.set(1434319925275);
});

afterEach(() => {
MockDate.reset();
});

it('should handle empty options', () => {
expect(buildUrlQuery(makeOrderedMap({}))).toBe('');
expect(buildUrlQuery(makeOrderedMap([]), state)).toBe('');
});

it('should combine multiple options', () => {
state = state.set('timeTravelMillisecondsInPast', 0);
expect(buildUrlQuery(makeOrderedMap([
['foo', 2],
['bar', 4]
]), state)).toBe('foo=2&bar=4');
});

it('should combine multiple options with a timestamp', () => {
state = state.set('timeTravelMillisecondsInPast', 60 * 60 * 1000); // 1h in the past
expect(buildUrlQuery(makeOrderedMap([
['foo', 2],
['bar', 4]
]))).toBe('foo=2&bar=4');
]), state)).toBe('foo=2&bar=4&timestamp=2015-06-14T21:12:05.275Z');
});
});

Expand Down
13 changes: 5 additions & 8 deletions client/app/scripts/utils/web-api-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import debug from 'debug';
import moment from 'moment';
import reqwest from 'reqwest';
import { defaults } from 'lodash';
import { fromJS, Map as makeMap, List } from 'immutable';
import { Map as makeMap, List } from 'immutable';

import { blurSearch, clearControlError, closeWebsocket, openWebsocket, receiveError,
receiveApiDetails, receiveNodesDelta, receiveNodeDetails, receiveControlError,
Expand Down Expand Up @@ -109,11 +109,9 @@ export function getWebsocketUrl(host = window.location.host, pathname = window.l
}

function buildWebsocketUrl(topologyUrl, topologyOptions = makeMap(), state) {
const query = buildUrlQuery(fromJS({
t: updateFrequency,
...topologyOptions.toJS(),
}), state);
return `${getWebsocketUrl()}${topologyUrl}/ws?${query}`;
topologyOptions = topologyOptions.set('t', updateFrequency);
const optionsQuery = buildUrlQuery(topologyOptions, state);
return `${getWebsocketUrl()}${topologyUrl}/ws?${optionsQuery}`;
}

function createWebsocket(websocketUrl, dispatch) {
Expand Down Expand Up @@ -268,7 +266,6 @@ export function getNodeDetails(state, dispatch) {
const nodeMap = state.get('nodeDetails');
const topologyUrlsById = state.get('topologyUrlsById');
const currentTopologyId = state.get('currentTopologyId');
const options = activeTopologyOptionsSelector(state);

// get details for all opened nodes
const obj = nodeMap.last();
Expand All @@ -277,7 +274,7 @@ export function getNodeDetails(state, dispatch) {
let urlComponents = [getApiPath(), topologyUrl, '/', encodeURIComponent(obj.id)];
if (currentTopologyId === obj.topologyId) {
// Only forward filters for nodes in the current topology
const optionsQuery = buildUrlQuery(options, state);
const optionsQuery = buildUrlQuery(activeTopologyOptionsSelector(state), state);
urlComponents = urlComponents.concat(['?', optionsQuery]);
}
const url = urlComponents.join('');
Expand Down
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"immutable-devtools": "0.0.7",
"jest-cli": "19.0.2",
"json-loader": "0.5.4",
"mockdate": "^2.0.1",
"node-sass": "4.5.2",
"postcss-loader": "1.3.3",
"react-addons-perf": "15.4.2",
Expand Down
8 changes: 6 additions & 2 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,7 @@ d3-dispatch@1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/d3-dispatch/-/d3-dispatch-1.0.3.tgz#46e1491eaa9b58c358fce5be4e8bed626e7871f8"

d3-drag@1:
d3-drag@1, d3-drag@1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/d3-drag/-/d3-drag-1.0.4.tgz#a9c1609f11dd5530ae275ebd64377ec54efb9d8f"
dependencies:
Expand Down Expand Up @@ -1739,7 +1739,7 @@ d3-timer@1:
version "1.0.5"
resolved "https://registry.yarnpkg.com/d3-timer/-/d3-timer-1.0.5.tgz#b266d476c71b0d269e7ac5f352b410a3b6fe6ef0"

d3-transition@1:
d3-transition@1, d3-transition@1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/d3-transition/-/d3-transition-1.0.4.tgz#e1a9ebae3869a9d9c2874ab00841fa8313ae5de5"
dependencies:
Expand Down Expand Up @@ -4070,6 +4070,10 @@ mixin-object@^2.0.1:
dependencies:
minimist "0.0.8"

mockdate@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/mockdate/-/mockdate-2.0.1.tgz#51bc309e2c4396600d56b6c23a6a0f4182943a36"

moment@2.18.1:
version "2.18.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"
Expand Down

0 comments on commit 19552d6

Please sign in to comment.