Skip to content

Commit f284d00

Browse files
committed
test: Add abbreviations e2e test
1 parent d7d98f1 commit f284d00

File tree

6 files changed

+80
-2
lines changed

6 files changed

+80
-2
lines changed

app/charts/shared/axis-width-band.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const AxisWidthBand = () => {
3434
const fontSize =
3535
xScale.bandwidth() > labelFontSize ? labelFontSize : xScale.bandwidth();
3636

37-
g.call(axis);
37+
g.call(axis).attr("data-testid", "axis-width-band");
3838

3939
g.select(".domain").remove();
4040
g.selectAll(".tick line").attr(

app/configurator/components/chart-options-selector.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ const ChartFieldAbbreviations = ({
423423

424424
return (
425425
<ChartOptionCheckboxField
426+
data-testid="use-abbreviations"
426427
label={getFieldLabel("abbreviations")}
427428
field={field}
428429
path={path ? `${path}.useAbbreviations` : "useAbbreviations"}

e2e/abbreviations.spec.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { expect, sleep, test } from "./common";
2+
3+
test("it should be possible to enable abbreviations", async ({
4+
actions,
5+
selectors,
6+
}) => {
7+
await actions.chart.createFrom(
8+
"https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/6",
9+
"Prod"
10+
);
11+
12+
await actions.editor.selectActiveField("Horizontal Axis");
13+
14+
let checkbox = await selectors.edition.useAbbreviationsCheckbox();
15+
16+
expect(await checkbox.isDisabled()).toEqual(true);
17+
18+
await (
19+
await selectors.panels.drawer().within().findByText("Jahr der Vergütung")
20+
).click();
21+
22+
await actions.mui.selectOption("Kanton");
23+
24+
// Wait for the data to load.
25+
await selectors.chart.loaded();
26+
await selectors.edition.filtersLoaded();
27+
28+
expect(await checkbox.isDisabled()).toEqual(false);
29+
30+
await checkbox.click();
31+
32+
await sleep(5_000);
33+
34+
const xAxis = await selectors.chart.axisWidthBand();
35+
const ticks = (await xAxis.textContent()) as string;
36+
expect([ticks.slice(0, 2), ticks.slice(-2)]).toEqual(["ZH", "NE"]);
37+
38+
await (await selectors.panels.drawer().within().findByText("Kanton")).click();
39+
40+
await actions.mui.selectOption("Jahr der Vergütung");
41+
42+
await sleep(5_000);
43+
44+
await actions.drawer.close();
45+
46+
await actions.editor.selectActiveField("Color");
47+
48+
await (await selectors.panels.drawer().within().findByText("None")).click();
49+
50+
await actions.mui.selectOption("Kanton");
51+
52+
checkbox = await selectors.edition.useAbbreviationsCheckbox();
53+
await checkbox.click();
54+
55+
// Wait for the data to load.
56+
await selectors.chart.loaded();
57+
await selectors.edition.filtersLoaded();
58+
await selectors.chart.colorLegend(undefined, { setTimeout: 5_000 });
59+
60+
const legendItems = await (
61+
await selectors.chart.colorLegendItems()
62+
).allInnerTexts();
63+
64+
expect([legendItems[0], legendItems[legendItems.length - 1]]).toEqual([
65+
"ZH",
66+
"JU",
67+
]);
68+
});

e2e/actions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ export const createActions = ({
8080
within,
8181
}),
8282
},
83+
drawer: {
84+
close: async () => await screen.locator('text="Back to main"').click(),
85+
},
8386
});
8487

8588
export type Actions = ReturnType<typeof createActions>;

e2e/selectors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ export const createSelectors = ({ screen, page, within }: Ctx) => {
5353
}),
5454
dataFilterInput: (label: string) =>
5555
page.locator(`div[role="button"]:has-text("${label}")`),
56+
useAbbreviationsCheckbox: () =>
57+
screen
58+
.getByTestId("panel-drawer")
59+
.within()
60+
.findByText("Use abbreviations"),
5661
},
5762
published: {
5863
interactiveFilters: () =>
5964
screen.getByTestId("published-chart-interactive-filters"),
6065
},
6166
chart: {
67+
axisWidthBand: async () => screen.findByTestId("axis-width-band"),
6268
colorLegend: (options?, waitForOptions?) =>
6369
screen.findByTestId("colorLegend", options, waitForOptions),
6470
colorLegendItems: async () =>

e2e/sorting.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test("Segment sorting", async ({
7676

7777
await actions.mui.selectOption("Automatic");
7878

79-
await page.locator('text="Back to main"').click();
79+
await actions.drawer.close();
8080
}
8181
});
8282

0 commit comments

Comments
 (0)