forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.test.js
150 lines (136 loc) · 4.99 KB
/
app.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import { storeWithSimpleProfile } from '../fixtures/stores';
import * as ProfileViewSelectors from '../../reducers/profile-view';
import * as UrlStateSelectors from '../../reducers/url-state';
import * as AppSelectors from '../../reducers/app';
import createStore from '../../create-store';
import { withAnalyticsMock } from '../fixtures/mocks/analytics';
import * as AppActions from '../../actions/app';
describe('app actions', function() {
describe('changeSelectedTab', function() {
it('can change tabs', function() {
const { dispatch, getState } = storeWithSimpleProfile();
expect(UrlStateSelectors.getSelectedTab(getState())).toEqual('calltree');
dispatch(AppActions.changeSelectedTab('stack-chart'));
expect(UrlStateSelectors.getSelectedTab(getState())).toEqual(
'stack-chart'
);
});
it('records an analytics event when changing tabs', function() {
withAnalyticsMock(() => {
const { dispatch } = storeWithSimpleProfile();
dispatch(AppActions.changeSelectedTab('stack-chart'));
expect(self.ga.mock.calls).toEqual([
[
'send',
{
hitType: 'pageview',
page: 'stack-chart',
},
],
]);
});
});
});
describe('profilePublished', function() {
const hash = 'de0ecf545819a95caa4c4d55b7a9cedb';
it('changes the data source to public', function() {
const { dispatch, getState } = storeWithSimpleProfile();
expect(UrlStateSelectors.getDataSource(getState())).toBe('none');
dispatch(AppActions.profilePublished(hash));
expect(UrlStateSelectors.getDataSource(getState())).toBe('public');
});
it('changes the hash', function() {
const { dispatch, getState } = storeWithSimpleProfile();
expect(UrlStateSelectors.getHash(getState())).toBe('');
dispatch(AppActions.profilePublished(hash));
expect(UrlStateSelectors.getHash(getState())).toBe(hash);
});
});
describe('changeTabOrder', function() {
it('can change the saved tab order', function() {
const { dispatch, getState } = storeWithSimpleProfile();
expect(ProfileViewSelectors.getTabOrder(getState())).toEqual([
0,
1,
2,
3,
4,
]);
dispatch(AppActions.changeTabOrder([2, 3, 1, 4, 0]));
expect(ProfileViewSelectors.getTabOrder(getState())).toEqual([
2,
3,
1,
4,
0,
]);
});
});
describe('urlSetupDone', function() {
it('will remember when url setup is done', function() {
const { dispatch, getState } = storeWithSimpleProfile();
expect(AppSelectors.getIsUrlSetupDone(getState())).toEqual(false);
dispatch(AppActions.urlSetupDone());
expect(AppSelectors.getIsUrlSetupDone(getState())).toEqual(true);
});
it('records analytics events for pageview and datasource', function() {
withAnalyticsMock(() => {
const { dispatch } = storeWithSimpleProfile();
dispatch(AppActions.urlSetupDone());
expect(self.ga.mock.calls).toEqual([
[
'send',
{
hitType: 'pageview',
page: 'home',
},
],
[
'send',
{
eventAction: 'none',
eventCategory: 'datasource',
hitType: 'event',
},
],
]);
});
});
});
describe('show404', function() {
it('tracks when the route is not found', function() {
const { dispatch, getState } = createStore();
expect(AppSelectors.getView(getState())).toEqual({
phase: 'INITIALIZING',
});
dispatch(AppActions.show404('http://foobar.com'));
expect(AppSelectors.getView(getState())).toEqual({
phase: 'ROUTE_NOT_FOUND',
});
});
});
describe('updateUrlState', function() {
it('can swap out to a different URL state', function() {
const { dispatch, getState } = storeWithSimpleProfile();
// The URL state starts out on the calltree tab.
const originalUrlState = UrlStateSelectors.getUrlState(getState());
expect(UrlStateSelectors.getSelectedTab(getState())).toEqual('calltree');
// Change it, and make sure the URL state updates.
dispatch(AppActions.changeSelectedTab('stack-chart'));
expect(UrlStateSelectors.getSelectedTab(getState())).toEqual(
'stack-chart'
);
expect(UrlStateSelectors.getUrlState(getState())).not.toBe(
originalUrlState
);
// Now revert it to the original, and make sure everything resets.
dispatch(AppActions.updateUrlState(originalUrlState));
expect(UrlStateSelectors.getUrlState(getState())).toBe(originalUrlState);
expect(UrlStateSelectors.getSelectedTab(getState())).toEqual('calltree');
});
});
});