forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UrlManager.test.js
60 lines (52 loc) · 2.06 KB
/
UrlManager.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
/* 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 * as React from 'react';
import { Provider } from 'react-redux';
import { mount } from 'enzyme';
import { getIsUrlSetupDone } from '../../selectors/app';
import UrlManager from '../../components/app/UrlManager';
import { blankStore } from '../fixtures/stores';
import { getDataSource } from '../../selectors/url-state';
describe('UrlManager', function() {
function setup(urlPath: ?string) {
if (typeof urlPath === 'string') {
// jsdom doesn't allow us to rewrite window.location. Instead, use the
// History API to properly set the current location.
window.history.pushState(undefined, 'perf.html', urlPath);
}
const store = blankStore();
const { dispatch, getState } = store;
const createUrlManager = () =>
mount(
<Provider store={store}>
<UrlManager>Contents</UrlManager>
</Provider>
);
return { dispatch, getState, createUrlManager };
}
it('sets up the URL', function() {
const { getState, createUrlManager } = setup();
expect(getIsUrlSetupDone(getState())).toBe(false);
createUrlManager();
expect(getIsUrlSetupDone(getState())).toBe(true);
});
it('has no data source by default', function() {
const { getState, createUrlManager } = setup();
createUrlManager();
expect(getDataSource(getState())).toMatch('none');
});
it('sets the data source to from-addon', function() {
const { getState, createUrlManager } = setup('/from-addon/');
expect(getDataSource(getState())).toMatch('none');
createUrlManager();
expect(getDataSource(getState())).toMatch('from-addon');
});
it('redirects from-file back to no data source', function() {
const { getState, createUrlManager } = setup('/from-file/');
expect(getDataSource(getState())).toMatch('none');
createUrlManager();
expect(getDataSource(getState())).toMatch('none');
});
});