forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStackSettings.test.js
95 lines (77 loc) · 3 KB
/
StackSettings.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
/* 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 { fireEvent } from '@testing-library/react';
import { Provider } from 'react-redux';
import { render, act } from 'firefox-profiler/test/fixtures/testing-library';
import { StackSettings } from '../../components/shared/StackSettings';
import { storeWithProfile } from '../fixtures/stores';
import {
getImplementationFilter,
getCurrentSearchString,
} from '../../selectors/url-state';
import { fireFullClick } from '../fixtures/utils';
describe('StackSettings', function () {
function setup() {
jest.useFakeTimers();
const store = storeWithProfile();
const renderResult = render(
<Provider store={store}>
<StackSettings />
</Provider>
);
return {
...renderResult,
...store,
};
}
it('matches the snapshot', () => {
const { container } = setup();
expect(container).toMatchSnapshot();
});
/**
* Get around the type constraints of refining an HTMLElement into a radio input.
*/
function getCheckedState(element: HTMLElement): mixed {
return (element: any).checked;
}
it('can change the implementation filter to JavaScript', async function () {
const { getByLabelText, getState } = setup();
expect(getImplementationFilter(getState())).toEqual('combined');
const radioButton = getByLabelText(/JavaScript/);
fireFullClick(radioButton);
expect(getCheckedState(radioButton)).toBe(true);
expect(getImplementationFilter(getState())).toEqual('js');
});
it('can change the implementation filter to Native', function () {
const { getByLabelText, getState } = setup();
expect(getImplementationFilter(getState())).toEqual('combined');
const radioButton = getByLabelText(/Native/);
fireFullClick(radioButton);
expect(getCheckedState(radioButton)).toBe(true);
expect(getImplementationFilter(getState())).toEqual('cpp');
});
it('can change the implementation filter to All frames', function () {
const { getByLabelText, getState } = setup();
fireFullClick(getByLabelText(/Native/));
expect(getImplementationFilter(getState())).toEqual('cpp');
const radioButton = getByLabelText(/All frames/);
fireFullClick(radioButton);
expect(getCheckedState(radioButton)).toBe(true);
expect(getImplementationFilter(getState())).toEqual('combined');
});
it('can change the search', function () {
const { getByLabelText, getState } = setup();
expect(getCurrentSearchString(getState())).toEqual('');
const searchText = 'some search';
const input: HTMLInputElement = (getByLabelText(/Filter stacks/): any);
fireEvent.change(input, {
target: { value: searchText },
});
act(() => jest.runAllTimers());
expect(getCurrentSearchString(getState())).toEqual(searchText);
expect(input.value).toEqual(searchText);
});
});