forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmptyThreadIndicator.test.js
253 lines (223 loc) · 8.94 KB
/
EmptyThreadIndicator.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/* 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 { render } from 'firefox-profiler/test/fixtures/testing-library';
import {
EmptyThreadIndicator,
getIndicatorPositions,
} from '../../components/timeline/EmptyThreadIndicator';
import { getProfileFromTextSamples } from '../fixtures/profiles/processed-profile';
import { mockRaf } from '../fixtures/mocks/request-animation-frame';
import { getElementWithFixedSize } from '../fixtures/mocks/element-size';
import type { StartEndRange } from 'firefox-profiler/types';
describe('EmptyThreadIndicator', function () {
// Sizing for the containing dom node.
const width = 100;
const height = 10;
beforeEach(() => {
jest
.spyOn(ReactDOM, 'findDOMNode')
.mockImplementation(() => getElementWithFixedSize({ width, height }));
});
const { profile } = getProfileFromTextSamples(`
A A A
`);
const thread = profile.threads[0];
thread.processStartupTime = 2;
thread.processShutdownTime = 10;
thread.registerTime = 3;
thread.unregisterTime = 9;
thread.samples.time = [5, 6, 7];
// Make it really easy to generate the component's props.
function propsFromViewportRange(viewport: StartEndRange) {
return {
rangeStart: viewport.start,
rangeEnd: viewport.end,
thread: thread,
interval: 0.1,
unfilteredSamplesRange: { start: 5, end: 8 },
width,
height: 10,
};
}
describe('rendering', function () {
it('matches the snapshot when rendering all three types of indicators', () => {
const props = propsFromViewportRange({ start: 0, end: 10 });
const flushRafCalls = mockRaf(); // WithSize uses requestAnimationFrame
const { container } = render(
// The props have to be passed in manually to avoid adding the SizeProps.
<EmptyThreadIndicator
rangeStart={props.rangeStart}
rangeEnd={props.rangeEnd}
thread={props.thread}
interval={props.interval}
unfilteredSamplesRange={props.unfilteredSamplesRange}
/>
);
flushRafCalls();
expect(container.firstChild).toMatchSnapshot();
});
it('matches the snapshot when rendering no indicators', () => {
// This range has samples throughout it.
const props = propsFromViewportRange({ start: 5.5, end: 6.5 });
const flushRafCalls = mockRaf(); // WithSize uses requestAnimationFrame
const { container } = render(
// The props have to be passed in manually to avoid adding the SizeProps.
<EmptyThreadIndicator
rangeStart={props.rangeStart}
rangeEnd={props.rangeEnd}
thread={props.thread}
interval={props.interval}
unfilteredSamplesRange={props.unfilteredSamplesRange}
/>
);
flushRafCalls();
expect(container.firstChild).toMatchSnapshot();
});
});
describe('startup empty thread indicator', function () {
// Thread startup is between 0 and 3 seconds in the mock data. In addition the space
// is 100px wide.
it('is 30% on screen when zoomed all the way out', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// viewport |------------------------------|
// startup |--------|
const { startup } = getIndicatorPositions(
propsFromViewportRange({ start: 0, end: 10 })
);
expect(startup).toEqual({ left: 0, width: 30 });
});
it('is 100% on screen zoomed far into the startup time', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// viewport |-----|
// startup |--------|
const { startup } = getIndicatorPositions(
propsFromViewportRange({ start: 0, end: 2 })
);
expect(startup).toEqual({ left: 0, width: 100 });
});
it('is not shown when the viewport isn’t in range', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// viewport |------------------|
// startup |--------|
const { startup } = getIndicatorPositions(
propsFromViewportRange({ start: 4, end: 10 })
);
expect(startup).toEqual(null);
});
});
describe('shutdown empty thread indicator', function () {
// Thread startup is between 0 and 3 seconds in the mock data. In addition the space
// is 100px wide.
it('is on screen when zoomed all the way out', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// viewport |------------------------------|
// shutdown |---|
const { shutdown } = getIndicatorPositions(
propsFromViewportRange({ start: 0, end: 10 })
);
// It takes up 30% of the view.
expect(shutdown).toEqual({ right: 0, width: 10 });
});
it('is 100% on screen zoomed far into shutdown time', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// viewport |-|
// shutdown |---|
const { shutdown } = getIndicatorPositions(
propsFromViewportRange({ start: 9.2, end: 9.8 })
);
// It takes up 100% of the view.
expect(shutdown).toEqual({ right: 0, width: 100 });
});
it('is not shown when the viewport isn’t in range', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// viewport |--------------|
// shutdown |---|
const { shutdown } = getIndicatorPositions(
propsFromViewportRange({ start: 0, end: 5 })
);
// It takes up 100% of the view.
expect(shutdown).toEqual(null);
});
});
describe('empty buffer start indicator', function () {
// Thread startup is between 0 and 3 seconds in the mock data. In addition the space
// is 100px wide.
it('in range during and after', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// registered |-----------------|
// samples |--------|
// viewport |-----------------|
// empty |--|
const { emptyBufferStart } = getIndicatorPositions(
propsFromViewportRange({ start: 4, end: 10 })
);
// Break the assertion down
expect(emptyBufferStart && emptyBufferStart.left).toEqual(0);
expect(emptyBufferStart && emptyBufferStart.width).toBeCloseTo(16.66666);
});
it('in range during and before', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// registered |-----------------|
// samples |--------|
// viewport |--------------|
// empty |-----|
const { emptyBufferStart } = getIndicatorPositions(
propsFromViewportRange({ start: 0, end: 5 })
);
// Break the assertion down
expect(emptyBufferStart).toEqual({ left: 60, width: 40 });
});
it('is on screen when zoomed all the way out', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// registered |-----------------|
// samples |--------|
// viewport |------------------------------|
// empty |-----|
const { emptyBufferStart } = getIndicatorPositions(
propsFromViewportRange({ start: 0, end: 10 })
);
// It takes up 30% of the view.
expect(emptyBufferStart).toEqual({ left: 30, width: 20 });
});
it('is 100% on screen zoomed far into emptyBufferStart time', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// registered |-----------------|
// samples |--------|
// viewport |--|
// empty |--|
const { emptyBufferStart } = getIndicatorPositions(
propsFromViewportRange({ start: 3.5, end: 4.5 })
);
// It takes up 100% of the view.
expect(emptyBufferStart).toEqual({ left: 0, width: 100 });
});
it('is not shown when the viewport isn’t in range before', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// registered |-----------------|
// samples |--------|
// viewport |-----|
// empty none in range
const { emptyBufferStart } = getIndicatorPositions(
propsFromViewportRange({ start: 0, end: 2 })
);
// It takes up 100% of the view.
expect(emptyBufferStart).toEqual(null);
});
it('is not shown when the viewport isn’t in range after', () => {
// 0 1 2 3 4 5 6 7 8 9 10
// registered |-----------------|
// samples |--------|
// viewport |-----|
// empty none in range
const { emptyBufferStart } = getIndicatorPositions(
propsFromViewportRange({ start: 6, end: 8 })
);
// It takes up 100% of the view.
expect(emptyBufferStart).toEqual(null);
});
});
});