-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathlegend_stories.test.ts
More file actions
417 lines (370 loc) · 20.7 KB
/
legend_stories.test.ts
File metadata and controls
417 lines (370 loc) · 20.7 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { test, expect } from '@playwright/test';
import { PartitionLayout, Position } from '../constants';
import { pwEach } from '../helpers';
import { common } from '../page_objects';
test.describe('Legend stories', () => {
test('should render non-split series', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--changing-specs&knob-split series=',
);
});
test('should hide line series legend item', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--hide-legend-items-by-series&knob-hide bar series in legend=&knob-hide line series in legend=true',
);
});
test('should hide bar series legend item', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--hide-legend-items-by-series&knob-hide bar series in legend=true&knob-hide line series in legend=',
);
});
test('should 0 legend buffer', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--legend-spacing-buffer&knob-legend buffer value=0&knob-max legend label lines=1',
);
});
test('should have the same order as nested with no indent even if there are repeated labels', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--piechart-repeated-labels&knob-flatLegend=true&knob-legendMaxDepth=2',
);
});
test('should correctly render multiline nested legend labels', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--piechart&globals=theme:light&knob-Hide color picker=true&knob-Hide color picker_Legend=true&knob-Legend position=right&knob-Legend position_Legend=right&knob-max legend label lines=0&knob-Number of series=5&knob-Popover position=leftCenter&knob-Popover position_Legend=leftCenter&knob-Series with long name=3&knob-direction_Legend=vertical&knob-floating columns_Legend=2&knob-hAlign_Legend=right&knob-legend buffer value=80&knob-legend margins=20&knob-long label text_Legend=Non do aliqua veniam dolore ipsum eu aliquip. Culpa in duis amet non velit qui non ullamco sit adipisicing. Ut sunt Lorem mollit exercitation deserunt officia sunt ipsum eu amet.&knob-multiline Legend labels=true&knob-vAlign_Legend=bottom&knob-Partition Layout=sunburst&knob-flatLegend=&knob-showLegendExtra=&knob-legendMaxDepth=2&knob-legendStrategy=key',
);
});
test('should correctly render very long multiline legend labels', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--legend-spacing-buffer&knob-Hide color picker=true&knob-Hide color picker_Legend=true&knob-Legend position=right&knob-Legend position_Legend=right&knob-Number of series=5&knob-Partition Layout=sunburst&knob-Popover position=leftCenter&knob-Popover position_Legend=leftCenter&knob-Series with long name=3&knob-direction_Legend=vertical&knob-flatLegend=true&knob-floating columns_Legend=2&knob-hAlign_Legend=right&knob-legend buffer value=80&knob-legend margins=20&knob-legendMaxDepth=3&knob-legendStrategy=key&knob-long label text_Legend=Non do aliqua veniam dolore ipsum eu aliquip. Culpa in duis amet non velit qui non ullamco sit adipisicing. Ut sunt Lorem mollit exercitation deserunt officia sunt ipsum eu amet.&knob-max legend label lines=0&knob-showLegendExtra=true&knob-use long labels=true&knob-vAlign_Legend=bottom',
);
});
test('should breakup multiline legend labels with long continous words', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--inside-chart&knob-Inside chart_Legend=false&knob-Legend position_Legend=right&knob-max label lines_Legend=0&knob-Number of series=5&knob-Popover position_Legend=leftCenter&knob-Series with long name=3&knob-direction_Legend=vertical&knob-floating columns_Legend=2&knob-hAlign_Legend=right&knob-long label_Legend=a few separate words then averyongcontinuouswordthatneedstobebrokenup&knob-vAlign_Legend=bottom',
);
});
test('should break multiline legends with long url characters', async ({ page }) => {
await common.expectChartWithMouseAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--inside-chart&globals=theme:light&knob-Number of series=5&knob-Series with long name=3&knob-Inside chart_Legend=false&knob-Show legend action_Legend=true&knob-floating columns_Legend=1&knob-vAlign_Legend=bottom&knob-hAlign_Legend=right&knob-direction_Legend=vertical&knob-max label lines_Legend=0&knob-long label_Legend=/people/type:astronauts/name:gregory-chamitoff/profile',
{ left: 182, top: 178 },
);
});
test('should render long floating legends inside chart', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--inside-chart&globals=theme:light&knob-Number of series=40&knob-Series with long name=0&knob-Inside chart_Legend=true&knob-floating columns_Legend=1&knob-vAlign_Legend=bottom&knob-hAlign_Legend=right&knob-direction_Legend=vertical&knob-max label lines_Legend=1&knob-long label_Legend=long name',
);
});
test('should render color picker on mouse click', async ({ page }) => {
const action = async () => {
await common.clickMouseRelativeToDOMElement(page)({ left: 0, top: 0 }, '.echLegendItem__color');
};
await common.expectElementAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--color-picker',
'body',
{
action,
waitSelector: common.chartWaitSelector,
},
);
});
test('should render legend action on mouse hover', async ({ page }) => {
const action = async () => {
await common.moveMouseRelativeToDOMElement(page)({ left: 30, top: 10 }, '.echLegendItem');
};
await common.expectChartAtUrlToMatchScreenshot(page)('http://localhost:9001/?path=/story/legend--actions', {
action,
});
});
test('should adjust legend width for scrollbar', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/small-multiples-alpha--grid-lines&knob-Debug=true&knob-Show Legend=true',
);
});
test.describe('Tooltip placement with legend', () => {
test('should render tooltip with left legend', async ({ page }) => {
await common.expectChartWithMouseAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--positioning&knob-position=left',
{
bottom: 190,
left: 310,
},
);
});
test('should render tooltip with top legend', async ({ page }) => {
await common.expectChartWithMouseAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--positioning&knob-position=top',
{
top: 150,
left: 320,
},
);
});
test('should render tooltip with right legend', async ({ page }) => {
await common.expectChartWithMouseAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--positioning&knob-position=right',
{
bottom: 180,
left: 330,
},
);
});
test('should render tooltip with bottom legend', async ({ page }) => {
await common.expectChartWithMouseAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--positioning&knob-position=bottom',
{
top: 150,
left: 320,
},
);
});
});
test.describe('keyboard navigation', () => {
// eslint-disable-next-line jest/expect-expect
test('should navigate to legend item with tab', async ({ page }) => {
// puts mouse to the bottom left
await common.moveMouse(page)(0, 0);
await common.expectChartWithKeyboardEventsAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--positioning&knob-position=right',
[
{
key: 'tab',
count: 2,
},
{
key: `${await common.getModifierKey(page)()}+Enter`,
count: 1,
},
],
);
});
test('should change aria label to hidden when clicked', async ({ page }) => {
await common.loadElementFromURL(page)(
'http://localhost:9001/?path=/story/legend--positioning&knob-position=right',
'.echLegendItem__label',
);
await common.clickMouseRelativeToDOMElement(page)(
{
bottom: 180,
left: 330,
},
'.echChartStatus[data-ech-render-complete=true]',
);
// Make the first index legend item hidden
await page.keyboard.press('Tab');
await page.keyboard.press('Tab');
await page.keyboard.press(`${await common.getModifierKey(page)()}+Enter`);
const hiddenResults: number[] = [];
// Filter the labels
const labels = page.evaluate(() =>
Array.from(document.getElementsByClassName('echLegendItem'), (e) => e.outerHTML),
);
(await labels).forEach((label, index) => {
const ariaInteractionLabel = label.split('; ')[1];
if (ariaInteractionLabel && /show/.test(ariaInteractionLabel)) {
hiddenResults.push(index);
}
});
expect(hiddenResults).toEqual([1]);
});
test('title interactive help should change according to the legend context for the item', async ({ page }) => {
await common.loadElementFromURL(page)(
'http://localhost:9001/?path=/story/legend--positioning&knob-position=right',
'.echLegendItem__label',
);
// check that the first item has a "show" title as third line
const initialLabels = await page.evaluate(() =>
Array.from(document.getElementsByClassName('echLegendItem__label'), (e) => e.getAttribute('title')),
);
expect(initialLabels.map((label) => (label ? label.split('\n')[2] : ''))).toEqual(
new Array(initialLabels.length).fill('Click to show'),
);
// click on the first item
await page.keyboard.press('Tab');
await page.keyboard.press(`Enter`);
// now check that it has a "show all" title this time
// check that all the other items (hidden) have a "show" title
const secondRoundLabels = await page.evaluate(() =>
Array.from(document.getElementsByClassName('echLegendItem__label'), (e) => e.getAttribute('title')),
);
expect(secondRoundLabels.map((label) => (label ? label.split('\n')[2] : ''))).toEqual(
['Click to show all'].concat(new Array(secondRoundLabels.length - 1).fill('Click to show')),
);
// now click on the second item (hidden)
await page.keyboard.press('Tab');
await page.keyboard.press(`Enter`);
// check that the first two items have a "hide" title and the rest have a "show" title
const thirdRoundLabels = await page.evaluate(() =>
Array.from(document.getElementsByClassName('echLegendItem__label'), (e) => e.getAttribute('title')),
);
expect(thirdRoundLabels.map((label) => (label ? label.split('\n')[2] : ''))).toEqual(
['Click to hide', 'Click to hide'].concat(new Array(secondRoundLabels.length - 2).fill('Click to show')),
);
});
});
test.describe('Extra values', () => {
pwEach.test([PartitionLayout.sunburst, PartitionLayout.treemap])(
(l) => `should display flat legend extra values on ${l}`,
async (page, layout) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
`http://localhost:9001/?path=/story/legend--piechart&knob-Partition Layout=${layout}&knob-flatLegend=true&knob-showLegendExtra=true&knob-legendMaxDepth=2`,
);
},
);
pwEach.test([PartitionLayout.sunburst, PartitionLayout.treemap])(
(l) => `should display nested legend extra values on ${l}`,
async (page, layout) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
`http://localhost:9001/?path=/story/legend--piechart&knob-Partition Layout=${layout}&knob-flatLegend=false&knob-showLegendExtra=true&knob-legendMaxDepth=2`,
);
},
);
});
test.describe('Legend inside chart', () => {
const getPositionalUrl = (p1: string, p2: string, others: string = '') =>
`http://localhost:9001/?path=/story/legend--inside-chart&knob-vAlign_Legend=${p1}&knob-hAlign_Legend=${p2}${others}`;
pwEach.test<[Position, Position]>([
[Position.Top, Position.Left],
[Position.Top, Position.Right],
[Position.Bottom, Position.Left],
[Position.Bottom, Position.Right],
])(
([p1, p2]) => `should correctly display ${p1} ${p2}`,
async (page, [p1, p2]) => {
await common.expectChartAtUrlToMatchScreenshot(page)(getPositionalUrl(p1, p2, '&globals=theme:light'));
},
);
pwEach.test<[Position, Position]>([
[Position.Top, Position.Left],
[Position.Top, Position.Right],
[Position.Bottom, Position.Left],
[Position.Bottom, Position.Right],
])(
([p1, p2]) => `should correctly display ${p1} ${p2} in dark mode`,
async (page, [p1, p2]) => {
await common.expectChartAtUrlToMatchScreenshot(page)(getPositionalUrl(p1, p2, '&globals=theme:dark'));
},
);
const longLabel =
'Non do aliqua veniam dolore ipsum eu aliquip. Culpa in duis amet non velit qui non ullamco sit adipisicing. Ut sunt Lorem mollit exercitation deserunt officia sunt ipsum eu amet.';
pwEach.test<[Position, Position]>([
[Position.Top, Position.Left],
[Position.Top, Position.Right],
[Position.Bottom, Position.Left],
[Position.Bottom, Position.Right],
])(
([p1, p2]) => `should correctly display ${p1} ${p2} in multiline mode`,
async (page, [p1, p2]) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
getPositionalUrl(p1, p2, `&knob-max label lines_Legend=0&knob-long label_Legend=${longLabel}`),
);
},
);
pwEach.test([0, 1, 3])(
(l) => `should correctly truncate multiline labels up to maxLines set to ${l}`,
async (page, maxLines) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
`http://localhost:9001/?path=/story/legend--inside-chart&knob-Number of series=5&knob-Series with long name=3&knob-Inside chart_Legend=false&knob-floating columns_Legend=2&knob-vAlign_Legend=bottom&knob-hAlign_Legend=right&knob-direction_Legend=vertical&knob-max label lines_Legend=${maxLines}&knob-long label_Legend=${longLabel}`,
);
},
);
});
test.describe('Custom width', () => {
// eslint-disable-next-line unicorn/consistent-function-scoping
const getUrl = (position: string, size: number) =>
`http://localhost:9001/?path=/story/legend--positioning&knob-position=${position}&knob-enable legend size=true&knob-legend size=${size}`;
pwEach.describe(['top', 'right', 'bottom', 'left'])(
(p) => `position ${p}`,
(position) => {
const isVertical = position === 'left' || position === 'right';
if (isVertical) {
test('should respect very small legend size', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(getUrl(position, 1));
});
}
test('should limit size to max 70% of chart dimension', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(getUrl(position, 100000));
});
test('should set exact size of legend within constraints', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(getUrl(position, isVertical ? 400 : 300));
});
},
);
});
test('should all values in stacked chart with filtered series - nick', async ({ page }) => {
const action = async () => {
await page.locator(':nth-match(.echLegendItem__label, 3)').click();
await page.locator(':nth-match(.echLegendItem__label, 4)').click();
await page.locator(':nth-match(.echLegendItem__label, 6)').click();
await page.locator(':nth-match(.echLegendItem__label, 8)').click();
};
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--tabular-data&globals=toggles.showHeader:true;toggles.showChartTitle:false;toggles.showChartDescription:false;toggles.showChartBoundary:false;theme:light&knob-Blue groupId_Annotations=primary&knob-Dataset_Legend=defaultDataset&knob-Domain axis_Annotations=y&knob-Enable debug state=true&knob-FadeOnFocusingOthers_Animations=true&knob-Hide color picker_Legend=true&knob-Legend Value_Legend[0]=median&knob-Legend Value_Legend[1]=min&knob-Legend Value_Legend[2]=max&knob-Legend position_Legend=right&knob-Number formatting precision_Legend=2&knob-Outside dimension_Annotations=4&knob-Popover position_Legend=leftCenter&knob-Red groupId_Annotations=primary&knob-Render outside chart_Annotations=true&knob-Scale type=linear&knob-SeriesType=bar&knob-Tick size=10&knob-annotation count_Styles=6&knob-annotation opacity_Styles=0.5&knob-annotation zIndex_Styles=0&knob-chartRotation=180&knob-data polarity=Mixed&knob-delay (ms)_Animations=50&knob-duration (ms)_Animations=250&knob-enable y0 and y1 values=true&knob-enabled_Animations=true&knob-max label lines_Label options=1&knob-stackMode=wiggle&knob-stacked=true&knob-Hide legend action_Legend=&knob-Hide legend extra_Legend=&knob-Legend title_Legend=&knob-enable legend size=',
{
action,
},
);
});
test.describe('Label truncation', () => {
test('should correctly render middle truncation in layout story', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--layout&knob-Legend position=top&knob-Legend Layout=list&knob-truncationPosition_Label options=middle',
);
});
test('should correctly render middle truncation with floating legend and multiline', async ({ page }) => {
await common.expectChartAtUrlToMatchScreenshot(page)(
'http://localhost:9001/?path=/story/legend--label-truncation&knob-Inside chart (floating)_Legend options=true&knob-Horizontal alignment_Legend options=left&knob-maxLines_Label options=2&knob-Hide short labels_Data=true&knob-enable legend size_Legend options=true&knob-legend size_Legend options=600',
);
});
});
http: test.describe('Legend tabular data', () => {
const disableActionOnHover = '&knob-Show legend action on hover_Legend=false';
const datasetKnob = (p1: string, p2: string) => `&globals=&knob-Dataset_Legend=${p1}&knob-dataset=${p2}`;
const getDatasetUrl = (p1: string, p2: string, others = '') => {
return `http://localhost:9001/?path=/story/legend--tabular-data${datasetKnob(p1, p2)}${disableActionOnHover}${others}`;
};
const legendPositionKnob = (position: string) => `&knob-Legend position_Legend=${position}`;
const getPositionUrl = (p1: string, others = '') => {
return `http://localhost:9001/?path=/story/legend--tabular-data${legendPositionKnob(p1)}${disableActionOnHover}${others}`;
};
const legendValueKnob = (values: string[]) => values.map((v, i) => `&knob-Legend Value_Legend[${i}]=${v}`).join('');
const getlegendValueUrl = (values: string[], others = '') => {
return `http://localhost:9001/?path=/story/legend--tabular-data${legendValueKnob(values)}${disableActionOnHover}${others}`;
};
pwEach.test<[string, string]>([
['shortCopyDataset', 'short copy'],
['longCopyDataset', 'long copy'],
['defaultDataset', 'default'],
])(
([p2]) => `should correctly display ${p2} dataset`,
async (page, [p1, p2]) => {
await common.expectChartAtUrlToMatchScreenshot(page)(getDatasetUrl(p1, p2));
},
);
pwEach.test<string>(['right', 'left', 'top', 'bottom'])(
(p) => `should correctly display ${p} positon`,
async (page, p) => {
await common.expectChartAtUrlToMatchScreenshot(page)(getPositionUrl(p));
},
);
pwEach.test<string[]>([
['median'],
['differencePercent'],
['lastNonNullValue'],
['currentAndLastValue', 'median'],
['median', 'max', 'min', 'average', 'firstNonNullValue'],
['median', 'max', 'min', 'average', 'firstNonNullValue', 'stdDeviation', 'firstValue', 'currentAndLastValue'],
])(
(p) => `should correctly display ${p} values`,
async (page, p) => {
await common.expectChartAtUrlToMatchScreenshot(page)(getlegendValueUrl(p));
},
);
});
});