forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfileViewer.test.js
75 lines (62 loc) · 2.39 KB
/
ProfileViewer.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
/* 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 ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { render } from 'firefox-profiler/test/fixtures/testing-library';
import { ProfileViewer } from 'firefox-profiler/components/app/ProfileViewer';
import { getTimelineHeight } from 'firefox-profiler/selectors/app';
import { updateUrlState } from 'firefox-profiler/actions/app';
import { viewProfile } from 'firefox-profiler/actions/receive-profile';
import { stateFromLocation } from 'firefox-profiler/app-logic/url-handling';
import { blankStore } from '../fixtures/stores';
import { getProfileWithNiceTracks } from '../fixtures/profiles/tracks';
import { autoMockCanvasContext } from '../fixtures/mocks/canvas-context';
import { mockRaf } from '../fixtures/mocks/request-animation-frame';
import {
autoMockElementSize,
getElementWithFixedSize,
} from '../fixtures/mocks/element-size';
import { autoMockIntersectionObserver } from '../fixtures/mocks/intersection-observer';
describe('ProfileViewer', function () {
autoMockCanvasContext();
autoMockElementSize({ width: 200, height: 300 });
autoMockIntersectionObserver();
beforeEach(() => {
jest
.spyOn(ReactDOM, 'findDOMNode')
.mockImplementation(() =>
getElementWithFixedSize({ width: 300, height: 300 })
);
});
function setup() {
// WithSize uses requestAnimationFrame
const flushRafCalls = mockRaf();
const store = blankStore();
store.dispatch(
updateUrlState(
stateFromLocation({
pathname: '/from-browser',
search: '',
hash: '',
})
)
);
store.dispatch(viewProfile(getProfileWithNiceTracks()));
const renderResult = render(
<Provider store={store}>
<ProfileViewer />
</Provider>
);
// Flushing the requestAnimationFrame calls so we can see the actual height of tracks.
flushRafCalls();
return { ...renderResult, ...store };
}
it('calculates the full timeline height correctly', () => {
const { getState } = setup();
// Note: You should update this total height if you changed the height calculation algorithm.
expect(getTimelineHeight(getState())).toBe(1224);
});
});