Skip to content

Commit ff2ae49

Browse files
committed
Unit tests for TraceTimelineViewer/duck
1 parent f45d360 commit ff2ae49

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// Copyright (c) 2017 Uber Technologies, Inc.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
import { createStore } from 'redux';
22+
23+
import reducer, { actions, newInitialState } from './duck';
24+
import DetailState from './SpanDetail/DetailState';
25+
import { transformTrace } from './transforms';
26+
import traceGenerator from '../../../demo/trace-generators';
27+
28+
describe('TraceTimelineViewer/duck', () => {
29+
const xformedTrace = transformTrace(traceGenerator.trace({ numberOfSpans: 10 }));
30+
let store;
31+
32+
beforeEach(() => {
33+
store = createStore(reducer, newInitialState(xformedTrace));
34+
});
35+
36+
describe('initial state', () => {
37+
it('retains a provided trace', () => {
38+
const state = store.getState();
39+
expect(state.trace).toBe(xformedTrace);
40+
});
41+
42+
it('has no details, collapsed children or text search', () => {
43+
const state = store.getState();
44+
expect(state.childrenHiddenIDs).toEqual(new Set());
45+
expect(state.findMatches).not.toBeDefined();
46+
expect(state.detailStates).toEqual(new Map());
47+
});
48+
});
49+
50+
describe('toggles children and details', () => {
51+
const parentID = xformedTrace.spans[0].spanID;
52+
const tests = [
53+
{
54+
msg: 'toggles children',
55+
action: actions.childrenToggle(parentID),
56+
propName: 'childrenHiddenIDs',
57+
initial: new Set(),
58+
resultant: new Set([parentID]),
59+
},
60+
{
61+
msg: 'toggles details',
62+
action: actions.detailToggle(parentID),
63+
propName: 'detailStates',
64+
initial: new Map(),
65+
resultant: new Map([[parentID, new DetailState()]]),
66+
},
67+
];
68+
69+
tests.forEach(info => {
70+
const { msg, action, propName, initial, resultant } = info;
71+
72+
it(msg, () => {
73+
const st0 = store.getState();
74+
expect(st0[propName]).toEqual(initial);
75+
76+
store.dispatch(action);
77+
const st1 = store.getState();
78+
expect(st0[propName]).toEqual(initial);
79+
expect(st1[propName]).toEqual(resultant);
80+
81+
store.dispatch(action);
82+
const st2 = store.getState();
83+
expect(st1[propName]).toEqual(resultant);
84+
expect(st2[propName]).toEqual(initial);
85+
});
86+
});
87+
});
88+
89+
describe("toggles a detail's sub-sections", () => {
90+
const id = xformedTrace.spans[0].spanID;
91+
const baseDetail = new DetailState();
92+
const tests = [
93+
{
94+
msg: 'toggles tags',
95+
action: actions.detailTagsToggle(id),
96+
get: state => state.detailStates.get(id),
97+
unchecked: new DetailState(),
98+
checked: baseDetail.toggleTags(),
99+
},
100+
{
101+
msg: 'toggles process',
102+
action: actions.detailProcessToggle(id),
103+
get: state => state.detailStates.get(id),
104+
unchecked: new DetailState(),
105+
checked: baseDetail.toggleProcess(),
106+
},
107+
{
108+
msg: 'toggles logs',
109+
action: actions.detailLogsToggle(id),
110+
get: state => state.detailStates.get(id),
111+
unchecked: new DetailState(),
112+
checked: baseDetail.toggleLogs(),
113+
},
114+
];
115+
116+
beforeEach(() => {
117+
store.dispatch(actions.detailToggle(id));
118+
});
119+
120+
tests.forEach(info => {
121+
const { msg, action, get, unchecked, checked } = info;
122+
123+
it(msg, () => {
124+
const st0 = store.getState();
125+
expect(get(st0)).toEqual(unchecked);
126+
127+
store.dispatch(action);
128+
const st1 = store.getState();
129+
expect(get(st0)).toEqual(unchecked);
130+
expect(get(st1)).toEqual(checked);
131+
132+
store.dispatch(action);
133+
const st2 = store.getState();
134+
expect(get(st1)).toEqual(checked);
135+
expect(get(st2)).toEqual(unchecked);
136+
});
137+
});
138+
});
139+
140+
// TODO(joe): test toggling log items
141+
});

0 commit comments

Comments
 (0)