-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathwebstatus-stats-missing-one-impl-chart-panel.test.ts
More file actions
293 lines (264 loc) · 9.23 KB
/
webstatus-stats-missing-one-impl-chart-panel.test.ts
File metadata and controls
293 lines (264 loc) · 9.23 KB
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/**
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {fixture, html as testHtml, expect} from '@open-wc/testing';
import {SinonStub, SinonStubbedInstance, stub} from 'sinon';
import {WebstatusStatsMissingOneImplChartPanel} from '../webstatus-stats-missing-one-impl-chart-panel.js'; // Path to your component
import {APIClient, BrowserReleaseFeatureMetric} from '../../api/client.js';
import {WebstatusLineChartPanel} from '../webstatus-line-chart-panel.js';
import {ChartSelectPointEvent} from '../webstatus-gchart.js';
import '../webstatus-stats-missing-one-impl-chart-panel.js';
describe('WebstatusStatsMissingOneImplChartPanel', () => {
let el: WebstatusStatsMissingOneImplChartPanel;
let apiClientStub: SinonStubbedInstance<APIClient>;
let setDisplayDataFromMapStub: SinonStub;
let fetchAndAggregateDataStub: SinonStub;
const startDate = new Date('2024-01-01');
const endDate = new Date('2024-01-31');
beforeEach(async () => {
apiClientStub = stub(new APIClient(''));
setDisplayDataFromMapStub = stub(
WebstatusLineChartPanel.prototype,
'setDisplayDataFromMap',
);
fetchAndAggregateDataStub = stub(
WebstatusLineChartPanel.prototype,
'_fetchAndAggregateData',
);
el = await fixture<WebstatusStatsMissingOneImplChartPanel>(
testHtml`<webstatus-stats-missing-one-impl-chart-panel
.startDate=${startDate}
.endDate=${endDate}
></webstatus-stats-missing-one-impl-chart-panel>`,
);
el.apiClient = apiClientStub;
await el.updateComplete;
});
afterEach(() => {
setDisplayDataFromMapStub.restore();
fetchAndAggregateDataStub.restore();
});
it('renders the card', async () => {
const card = el.shadowRoot!.querySelector('sl-card');
expect(card).to.exist;
});
it('renders the panel header', async () => {
const header = el.shadowRoot!.querySelector('[slot="header"]');
expect(header).to.exist;
expect(header!.textContent).to.contain(
'Features missing in only one browser',
);
});
it('uses the correct dataFetchStartDate and dataFetchEndDate', async () => {
// Start date should use the default dataFetchStartDateOffsetMsec and dataFetchEndDateOffsetMsec
// Default dataFetchStartDateOffsetMsec is 30 days
// Default dataFetchEndDateOffsetMsec is 0 days
expect(el.dataFetchStartDate).to.deep.equal(new Date('2023-12-02'));
expect(el.dataFetchEndDate).to.deep.equal(new Date('2024-01-31'));
});
it('calls _fetchAndAggregateData with correct configurations', async () => {
expect(fetchAndAggregateDataStub).to.have.been.calledOnce;
const [fetchFunctionConfigs] = fetchAndAggregateDataStub.getCall(0).args;
expect(fetchFunctionConfigs.length).to.equal(3); // 3 browsers
// Test Chrome configuration
const chromeConfig = fetchFunctionConfigs[0];
expect(chromeConfig.label).to.equal('Chromium');
expect(chromeConfig.fetchFunction).to.be.a('function');
const chromeTestDataPoint: BrowserReleaseFeatureMetric = {
timestamp: '2024-01-01',
count: 10,
};
expect(chromeConfig.timestampExtractor(chromeTestDataPoint)).to.deep.equal(
new Date('2024-01-01'),
);
expect(chromeConfig.valueExtractor(chromeTestDataPoint)).to.equal(10);
// Test Firefox configuration
const firefoxConfig = fetchFunctionConfigs[1];
expect(firefoxConfig.label).to.equal('Firefox');
expect(firefoxConfig.fetchFunction).to.be.a('function');
const firefoxTestDataPoint: BrowserReleaseFeatureMetric = {
timestamp: '2024-01-01',
count: 9,
};
expect(
firefoxConfig.timestampExtractor(firefoxTestDataPoint),
).to.deep.equal(new Date('2024-01-01'));
expect(firefoxConfig.valueExtractor(firefoxTestDataPoint)).to.equal(9);
// Test Safari configuration
const safariConfig = fetchFunctionConfigs[2];
expect(safariConfig.label).to.equal('Safari');
expect(safariConfig.fetchFunction).to.be.a('function');
const safariTestDataPoint: BrowserReleaseFeatureMetric = {
timestamp: '2024-01-01',
count: 7,
};
expect(safariConfig.timestampExtractor(safariTestDataPoint)).to.deep.equal(
new Date('2024-01-01'),
);
expect(safariConfig.valueExtractor(safariTestDataPoint)).to.equal(7);
});
it('generates chart options correctly', () => {
const options = el.generateDisplayDataChartOptions();
expect(options.vAxis?.title).to.equal('Number of features missing');
// Only browsers (except Edge).
expect(options.colors).eql(['#FF0000', '#F48400', '#4285F4']);
expect(options.hAxis?.viewWindow?.min).to.deep.equal(el.startDate);
const expectedEndDate = new Date(
el.endDate.getTime() + 1000 * 60 * 60 * 24,
);
expect(options.hAxis?.viewWindow?.max).to.deep.equal(expectedEndDate);
});
it('renders missing one implementation features footer', async () => {
apiClientStub.getMissingOneImplementationFeatures.resolves([
{
feature_id: 'css',
},
{
feature_id: 'html',
},
{
feature_id: 'js',
},
{
feature_id: 'bluetooth',
},
]);
const chart = el.shadowRoot!.querySelector(
'#missing-one-implementation-chart',
)!;
const chartClickEvent: ChartSelectPointEvent = new CustomEvent(
'point-selected',
{
detail: {
label: 'Chromium',
timestamp: new Date('2024-01-01'),
value: 123,
},
bubbles: true,
},
);
// Simulate point-selected event on the chart component
chart.dispatchEvent(chartClickEvent);
await el.updateComplete;
// Assert that the task and renderer are set (no need to wait for the event)
expect(el._pointSelectedTask).to.exist;
await el._pointSelectedTask?.taskComplete;
await el.updateComplete;
expect(el._renderCustomPointSelectedSuccess).to.exist;
await el.updateComplete;
const header = el.shadowRoot!.querySelector(
'#missing-one-implementation-list-header',
);
expect(header).to.exist;
// Note: \n before chrome due to a complaint from lint in the html.
expect(header!.textContent?.trim()).to.contain(
'The missing feature IDs on 2024-01-01 for\n chrome',
);
const table = el.shadowRoot!.querySelector('.missing-features-table');
expect(table).to.exist;
const rows = table!
.getElementsByTagName('tbody')[0]
.getElementsByTagName('tr');
expect(rows.length).to.equal(10, 'should have 10 rows');
const firstRowCells = rows[0].querySelectorAll('td');
expect(firstRowCells[0].textContent?.trim()).to.equal(
'css',
'first row ID',
);
});
it('assert correct getMissingOneImplementationFeatures calls', async () => {
apiClientStub.getMissingOneImplementationFeatures.resolves([
{
feature_id: 'css',
},
{
feature_id: 'html',
},
{
feature_id: 'js',
},
{
feature_id: 'bluetooth',
},
]);
const chart = el.shadowRoot!.querySelector(
'#missing-one-implementation-chart',
)!;
const chartClickEvent: ChartSelectPointEvent = new CustomEvent(
'point-selected',
{
detail: {
label: 'Safari',
timestamp: new Date('2024-01-01'),
value: 123,
},
bubbles: true,
},
);
// Simulate point-selected event on the chart component
chart.dispatchEvent(chartClickEvent);
await el.updateComplete;
expect(el._pointSelectedTask).to.exist;
expect(
apiClientStub.getMissingOneImplementationFeatures,
).to.have.been.calledWith(
'safari',
['chrome', 'firefox'],
new Date('2024-01-01'),
);
const chartClickEventOne: ChartSelectPointEvent = new CustomEvent(
'point-selected',
{
detail: {
label: 'Firefox',
timestamp: new Date('2024-01-01'),
value: 123,
},
bubbles: true,
},
);
chart.dispatchEvent(chartClickEventOne);
await el.updateComplete;
expect(el._pointSelectedTask).to.exist;
expect(
apiClientStub.getMissingOneImplementationFeatures,
).to.have.been.calledWith(
'firefox',
['chrome', 'safari'],
new Date('2024-01-01'),
);
const chartClickEventTwo: ChartSelectPointEvent = new CustomEvent(
'point-selected',
{
detail: {
label: 'Chromium',
timestamp: new Date('2024-01-01'),
value: 123,
},
bubbles: true,
},
);
chart.dispatchEvent(chartClickEventTwo);
await el.updateComplete;
expect(el._pointSelectedTask).to.exist;
expect(
apiClientStub.getMissingOneImplementationFeatures,
).to.have.been.calledWith(
'chrome',
['firefox', 'safari'],
new Date('2024-01-01'),
);
});
});