-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsorting.spec.ts
More file actions
222 lines (186 loc) · 5.83 KB
/
sorting.spec.ts
File metadata and controls
222 lines (186 loc) · 5.83 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
import { loadChartInLocalStorage } from "./charts-utils";
import { setup, sleep } from "./common";
import hierarchyTest13 from "./fixtures/hierarchy-test-13-municipality-population.json";
import { harReplayGraphqlEndpointQueryParam } from "./har-utils";
const { test, expect } = setup();
/**
* - Creates a chart from the photovoltaik dataset
* - For each type of chart, changes the sorting between Name and Automatic
* - Checks that the legend item order is coherent.
*/
test("Segment sorting", async ({
selectors,
actions,
within,
screen,
replayFromHAR,
}) => {
test.setTimeout(60_000);
await replayFromHAR();
await actions.chart.createFrom({
iri: "https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/10",
dataSource: "Prod",
createURLParams: harReplayGraphqlEndpointQueryParam,
});
for (const chartType of ["Columns", "Pie"] as const) {
await selectors.edition.drawerLoaded();
await actions.editor.changeRegularChartType(chartType);
await actions.editor.selectActiveField("Segmentation");
// Switch color on the first chart
if (chartType === "Columns") {
await within(selectors.edition.controlSectionByTitle("Segmentation"))
.getByLabelText("None")
.click();
await actions.mui.selectOption("Kanton");
}
await selectors.chart.loaded();
await selectors.edition.filtersLoaded();
await selectors.chart.colorLegend(undefined, { timeout: 5_000 });
const legendItems = await selectors.chart.colorLegendItems();
const legendTexts = await legendItems.allInnerTexts();
expect(legendTexts[0]).toEqual("Zurich");
await within(selectors.edition.controlSectionByTitle("Sort"))
.getByLabelText("Automatic")
.click();
await actions.mui.selectOption("Name");
await selectors.chart.loaded();
await selectors.edition.filtersLoaded();
const legendTexts2 = await legendItems.allInnerTexts();
expect(legendTexts2[0]).toBe("Aargau");
await screen.getByText("Z → A").click();
const legendTexts3 = await legendItems.allInnerTexts();
expect(legendTexts3[0]).toEqual("Zurich");
// Re-initialize for future tests
await screen.getByText("A → Z").click();
await within(selectors.edition.controlSectionByTitle("Sort"))
.getByLabelText("Name")
.click();
await actions.mui.selectOption("Automatic");
await actions.drawer.close();
}
expect(true).toBe(true);
});
test("Segment sorting with hierarchy", async ({
actions,
selectors,
screen,
within,
replayFromHAR,
}) => {
await replayFromHAR();
await actions.chart.createFrom({
iri: "https://environment.ld.admin.ch/foen/nfi/nfi_T-changes/cube/2024-1",
dataSource: "Prod",
createURLParams: harReplayGraphqlEndpointQueryParam,
});
await selectors.edition.drawerLoaded();
await actions.editor.selectActiveField("Segmentation");
await sleep(3_000);
const colorSection = selectors.edition.controlSectionByTitle("Segmentation");
await within(colorSection).getByLabelText("None").click();
await actions.mui.selectOption("Region");
await selectors.chart.loaded();
await selectors.edition.filtersLoaded();
await selectors.chart.colorLegend(undefined, { timeout: 30_000 });
await within(await selectors.chart.colorLegend()).findByText(
"Appenzell Innerrhoden",
undefined,
{ timeout: 10_000 }
);
const legendItems = await selectors.chart.colorLegendItems();
const expectedLegendItems = [
"Jura",
"Jura + Plateau",
"Western Jura",
"Zurich",
"Bern",
"Eastern Jura",
"Northwestern Alps",
"Plateau",
"Lucerne",
"Northeastern Alps",
"Pre-Alps",
"Western Plateau",
"Alps",
"Central Plateau",
"Southwestern Alps",
"Uri",
"Eastern Plateau",
"Schwyz",
"Southeastern Alps",
"Southern Alps",
"Obwalden",
"Southern Alps",
"Western Pre-Alps",
"Central Pre-Alps",
"Nidwalden",
"Eastern Pre-Alps",
"Glarus",
"Northwestern Alps",
"Zug",
"Central Alps",
"Fribourg",
"Northeastern Alps",
"Solothurn",
"Southwestern Alps",
"Southeastern Alps",
"both Basel",
"Schaffhausen",
"Southern Alps",
"Appenzell Ausserrhoden",
"Appenzell Innerrhoden",
"St Gallen",
"Graubünden",
"Aargau",
"Thurgau",
"Ticino",
"Vaud",
"Valais",
"Neuchâtel",
"Geneva",
"Jura",
];
expect(await legendItems.allInnerTexts()).toEqual(expectedLegendItems);
await screen.getByText("Z → A").click();
expect(await legendItems.allInnerTexts()).toEqual(
[...expectedLegendItems].reverse()
);
});
test.skip("Map legend preview table sorting", async ({
actions,
selectors,
replayFromHAR,
}) => {
await replayFromHAR();
await actions.chart.createFrom({
iri: "https://environment.ld.admin.ch/foen/gefahren-waldbrand-warnung/1",
dataSource: "Int",
createURLParams: harReplayGraphqlEndpointQueryParam,
});
await selectors.edition.drawerLoaded();
await actions.editor.changeRegularChartType("Map");
await selectors.chart.loaded();
await actions.chart.switchToTableView();
await actions.datasetPreview.sortBy("Danger ratings");
const cells = await selectors.datasetPreview.columnCells("Danger ratings");
});
test("Sorting with values with same label as other values in the tree", async ({
selectors,
page,
replayFromHAR,
}) => {
await replayFromHAR();
const key = "sorting-hierarchy-values-same-label.spec";
const config = hierarchyTest13;
await loadChartInLocalStorage(page, key, config);
page.goto(`/en/create/${key}?${harReplayGraphqlEndpointQueryParam}`);
await selectors.chart.loaded();
const texts = await Promise.all(
await (
await page.locator('[data-testid="axis-width-band"] text').all()
).map((loc) => {
return loc.innerHTML();
})
);
expect(texts).toEqual(["Zürich", "Bern"]);
});