forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatistics.spec.js
102 lines (83 loc) · 3.53 KB
/
statistics.spec.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
const { test, expect } = require("@playwright/test");
const { start, stop } = require("./evcc");
test.beforeAll(async () => {
await start("statistics.evcc.yaml", "statistics.sql");
});
test.afterAll(async () => {
await stop();
});
test.describe("footer", async () => {
test("default 30d solar percentage in footer and change on period switch", async ({ page }) => {
await page.goto("/");
// last 30 days
await expect(page.getByTestId("savings-button")).toContainText("60% solar energy");
// last 365 days
await page.getByTestId("savings-button").click();
await page
.getByTestId("savings-period-select")
.getByRole("combobox")
.selectOption("last 365 days");
await page.getByRole("button", { name: "Close" }).click();
await expect(page.getByTestId("savings-button")).toContainText("30% solar energy");
// all time
await page.getByTestId("savings-button").click();
await page.getByTestId("savings-period-select").getByRole("combobox").selectOption("all time");
await page.getByRole("button", { name: "Close" }).click();
await expect(page.getByTestId("savings-button")).toContainText("50% solar energy");
});
});
test.describe.skip("statistics values", async () => {
test("last 30 days", async ({ page }) => {
await page.goto("/");
await page.getByTestId("savings-button").click();
await page
.getByTestId("savings-period-select")
.getByRole("combobox")
.selectOption("last 30 days");
const solar = await page.getByTestId("savings-tile-solar");
expect(solar).toContainText("60.0%");
expect(solar).toContainText("30 kWh solar");
expect(solar).toContainText("20 kWh grid");
const price = await page.getByTestId("savings-tile-price");
expect(price).toContainText("18.0rp/kWh");
expect(price).toContainText("6 CHF saved");
const co2 = await page.getByTestId("savings-tile-co2");
expect(co2).toContainText("8g/kWh");
expect(co2).toContainText("19 kg saved");
});
test("last 365 days", async ({ page }) => {
await page.goto("/");
await page.getByTestId("savings-button").click();
await page
.getByTestId("savings-period-select")
.getByRole("combobox")
.selectOption("last 365 days");
const solar = await page.getByTestId("savings-tile-solar");
expect(solar).toContainText("30.0%");
expect(solar).toContainText("30 kWh solar");
expect(solar).toContainText("70 kWh grid");
const price = await page.getByTestId("savings-tile-price");
expect(price).toContainText("24.0rp/kWh");
expect(price).toContainText("6 CHF saved");
const co2 = await page.getByTestId("savings-tile-co2");
expect(co2).toContainText("14g/kWh");
expect(co2).toContainText("37 kg saved");
});
test("reference data", async ({ page }) => {
await page.goto("/");
await page.getByTestId("savings-button").click();
const reference = await page.getByTestId("savings-reference");
expect(reference).toContainText("Reference data:");
expect(reference).toContainText("30.0 rp/kWh (grid)");
expect(reference).toContainText("⌀ 385 g/kWh");
expect(reference).toContainText("Germany");
expect(await page.getByTestId("savings-tile-co2")).toContainText("19 kg saved");
await page
.getByTestId("savings-region-select")
.getByRole("combobox")
.selectOption("Switzerland");
expect(reference).toContainText("⌀ 46 g/kWh");
expect(reference).toContainText("Switzerland");
expect(await page.getByTestId("savings-tile-co2")).toContainText("2 kg saved");
});
});