forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-vehicles.spec.js
185 lines (142 loc) Β· 7.82 KB
/
config-vehicles.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
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
import { test, expect } from "@playwright/test";
import { start, stop, restart, baseUrl } from "./evcc";
import { enableExperimental } from "./utils";
const CONFIG_GRID_ONLY = "config-grid-only.evcc.yaml";
const CONFIG_WITH_VEHICLE = "config-with-vehicle.evcc.yaml";
test.use({ baseURL: baseUrl() });
test.describe.configure({ mode: "parallel" });
test.afterEach(async () => {
await stop();
});
test.describe("vehicles", async () => {
test("create, edit and delete vehicles", async ({ page }) => {
await start(CONFIG_GRID_ONLY);
await page.goto("/#/config");
await enableExperimental(page);
await expect(page.getByTestId("vehicle")).toHaveCount(0);
const vehicleModal = page.getByTestId("vehicle-modal");
// create #1
await page.getByTestId("add-vehicle").click();
await vehicleModal.getByLabel("Manufacturer").selectOption("Generic vehicle");
await vehicleModal.getByLabel("Title").fill("Green Car");
await vehicleModal.getByRole("button", { name: "Validate & save" }).click();
await expect(page.getByTestId("vehicle")).toHaveCount(1);
// create #2
await page.getByTestId("add-vehicle").click();
await vehicleModal.getByLabel("Manufacturer").selectOption("Generic vehicle");
await vehicleModal.getByLabel("Title").fill("Yellow Van");
await vehicleModal.getByRole("button", { name: "Validate & save" }).click();
await expect(page.getByTestId("vehicle")).toHaveCount(2);
await expect(page.getByTestId("vehicle").nth(0)).toHaveText(/Green Car/);
await expect(page.getByTestId("vehicle").nth(1)).toHaveText(/Yellow Van/);
// edit #1
await page.getByTestId("vehicle").nth(0).getByRole("button", { name: "edit" }).click();
await expect(vehicleModal.getByLabel("Title")).toHaveValue("Green Car");
await vehicleModal.getByLabel("Title").fill("Fancy Car");
await vehicleModal.getByRole("button", { name: "Validate & save" }).click();
await expect(page.getByTestId("vehicle")).toHaveCount(2);
await expect(page.getByTestId("vehicle").nth(0)).toHaveText(/Fancy Car/);
// delete #1
await page.getByTestId("vehicle").nth(0).getByRole("button", { name: "edit" }).click();
await vehicleModal.getByRole("button", { name: "Delete" }).click();
await expect(page.getByTestId("vehicle")).toHaveCount(1);
await expect(page.getByTestId("vehicle").nth(0)).toHaveText(/Yellow Van/);
// delete #2
await page.getByTestId("vehicle").nth(0).getByRole("button", { name: "edit" }).click();
await vehicleModal.getByRole("button", { name: "Delete" }).click();
await expect(page.getByTestId("vehicle")).toHaveCount(0);
});
test("config should survive restart", async ({ page }) => {
await start(CONFIG_GRID_ONLY);
await page.goto("/#/config");
await enableExperimental(page);
await expect(page.getByTestId("vehicle")).toHaveCount(0);
const vehicleModal = page.getByTestId("vehicle-modal");
// create #1 & #2
await page.getByTestId("add-vehicle").click();
await vehicleModal.getByLabel("Manufacturer").selectOption("Generic vehicle");
await vehicleModal.getByLabel("Title").fill("Green Car");
await vehicleModal.getByRole("button", { name: "Validate & save" }).click();
await page.getByTestId("add-vehicle").click();
await vehicleModal.getByLabel("Manufacturer").selectOption("Generic vehicle");
await vehicleModal.getByLabel("Title").fill("Yellow Van");
await vehicleModal.getByLabel("car").click();
await vehicleModal.getByLabel("van").check();
await vehicleModal.getByRole("button", { name: "Validate & save" }).click();
await expect(page.getByTestId("vehicle")).toHaveCount(2);
// restart evcc
await restart(CONFIG_GRID_ONLY);
await page.reload();
await expect(page.getByTestId("vehicle")).toHaveCount(2);
await expect(page.getByTestId("vehicle").nth(0)).toHaveText(/Green Car/);
await expect(page.getByTestId("vehicle").nth(1)).toHaveText(/Yellow Van/);
});
test("mixed config (yaml + db)", async ({ page }) => {
await start(CONFIG_WITH_VEHICLE);
await page.goto("/#/config");
await enableExperimental(page);
await expect(page.getByTestId("vehicle")).toHaveCount(1);
const vehicleModal = page.getByTestId("vehicle-modal");
// create #2
await page.getByTestId("add-vehicle").click();
await vehicleModal.getByLabel("Manufacturer").selectOption("Generic vehicle");
await vehicleModal.getByLabel("Title").fill("Green Car");
await vehicleModal.getByRole("button", { name: "Validate & save" }).click();
await expect(page.getByTestId("vehicle")).toHaveCount(2);
await expect(page.getByTestId("vehicle").nth(0)).toHaveText(/YAML Bike/);
await expect(page.getByTestId("vehicle").nth(1)).toHaveText(/Green Car/);
});
test("advanced fields", async ({ page }) => {
await start(CONFIG_GRID_ONLY);
await page.goto("/#/config");
await enableExperimental(page);
await page.getByTestId("add-vehicle").click();
const vehicleModal = page.getByTestId("vehicle-modal");
// generic
await vehicleModal.getByLabel("Manufacturer").selectOption("Generic vehicle");
await expect(vehicleModal.getByLabel("Title")).toBeVisible();
await expect(vehicleModal.getByLabel("Car")).toBeVisible(); // icon
await expect(vehicleModal.getByLabel("Battery capacity")).toBeVisible();
await page.getByRole("button", { name: "Show advanced settings" }).click();
await expect(vehicleModal.getByLabel("Default mode")).toBeVisible();
await expect(vehicleModal.getByLabel("Maximum phases")).toBeVisible();
await expect(vehicleModal.getByLabel("Minimum current")).toBeVisible();
await expect(vehicleModal.getByLabel("Maximum current")).toBeVisible();
await expect(vehicleModal.getByLabel("Priority")).toBeVisible();
await expect(vehicleModal.getByLabel("RFID identifiers")).toBeVisible();
await page.getByRole("button", { name: "Hide advanced settings" }).click();
await expect(vehicleModal.getByLabel("Default mode")).not.toBeVisible();
// polestar template
await vehicleModal.getByLabel("Manufacturer").selectOption("Polestar");
await expect(vehicleModal.getByLabel("Username")).toBeVisible();
await expect(vehicleModal.getByLabel("Password")).toBeVisible();
await expect(vehicleModal.getByLabel("Cache optional")).not.toBeVisible();
await expect(vehicleModal.getByLabel("Default mode")).not.toBeVisible();
await page.getByRole("button", { name: "Show advanced settings" }).click();
await expect(vehicleModal.getByLabel("Cache optional")).toBeVisible();
await expect(vehicleModal.getByLabel("Default mode")).toBeVisible();
});
test("save and restore rfid identifiers", async ({ page }) => {
await start(CONFIG_GRID_ONLY);
await page.goto("/#/config");
await enableExperimental(page);
await page.getByTestId("add-vehicle").click();
const vehicleModal = page.getByTestId("vehicle-modal");
// generic
await vehicleModal.getByLabel("Manufacturer").selectOption("Generic vehicle");
await vehicleModal.getByLabel("Title").fill("RFID Car");
await page.getByRole("button", { name: "Show advanced settings" }).click();
await vehicleModal.getByLabel("RFID identifiers").fill("aaa\nbbb \n ccc\n\nddd\n");
await vehicleModal.getByRole("button", { name: "Validate & save" }).click();
await expect(page.getByTestId("restart-needed")).toBeVisible();
// restart evcc
await restart(CONFIG_GRID_ONLY);
await page.reload();
await expect(page.getByTestId("vehicle")).toHaveCount(1);
await page.getByTestId("vehicle").getByRole("button", { name: "edit" }).click();
await vehicleModal.getByRole("button", { name: "Show advanced settings" }).click();
await expect(vehicleModal.getByLabel("RFID identifiers")).toHaveValue("aaa\nbbb\nccc\nddd");
await vehicleModal.getByLabel("Close").click();
await expect(page.getByTestId("fatal-error")).not.toBeVisible();
});
});