evcc-io/tests/config-tariffs.spec.ts
2025-12-20 23:52:07 +01:00

94 lines
2.6 KiB
TypeScript

import { test, expect } from "@playwright/test";
import { start, stop, restart, baseUrl } from "./evcc";
import { expectModalHidden, expectModalVisible, editorClear, editorPaste } from "./utils";
const CONFIG_WITH_TARIFFS = "config-with-tariffs.evcc.yaml";
test.use({ baseURL: baseUrl() });
test.describe.configure({ mode: "parallel" });
test.afterEach(async () => {
await stop();
});
test.describe("tariffs", async () => {
test("tariffs not configured", async ({ page }) => {
await start();
await page.goto("/#/config");
await expect(page.getByTestId("tariffs")).toBeVisible();
await expect(page.getByTestId("tariffs")).toContainText(["Configured", "no"].join(""));
});
test("tariffs via ui", async ({ page }) => {
await start();
await page.goto("/#/config");
await page.getByTestId("tariffs").getByRole("button", { name: "edit" }).click();
const modal = await page.getByTestId("tariffs-modal");
await expectModalVisible(modal);
await page.waitForLoadState("networkidle");
// default content
const editor = modal.getByTestId("yaml-editor");
await expect(editor).toContainText("#currency: EUR");
// clear and enter invalid yaml
await editorClear(editor);
await editorPaste(editor, page, "foo: bar");
await page.getByRole("button", { name: "Save" }).click();
await expect(modal.getByTestId("error")).toContainText("invalid keys: foo");
// clear and enter valid yaml
await editorClear(editor);
await editorPaste(
editor,
page,
`currency: CHF
grid:
type: fixed
price: 0.123`
);
await page.getByRole("button", { name: "Save" }).click();
await expect(modal.getByTestId("error")).not.toBeVisible();
// modal closes
await expectModalHidden(modal);
// restart button appears
const restartButton = await page
.getByTestId("bottom-banner")
.getByRole("button", { name: "Restart" });
await expect(restartButton).toBeVisible();
await restart();
// restart done
await expect(restartButton).not.toBeVisible();
await expect(page.getByTestId("tariffs")).toContainText(
["Currency", "CHF", "Grid price", "12.3 rp"].join("")
);
});
test("tariffs from evcc.yaml", async ({ page }) => {
await start(CONFIG_WITH_TARIFFS);
await page.goto("/#/config");
await expect(page.getByTestId("tariffs")).toBeVisible();
await expect(page.getByTestId("tariffs")).toContainText(
[
"Tariffs",
"Currency",
"SEK",
"Grid price",
"30.0 öre",
"Feed-in price",
"-10.0 öre",
"Grid CO₂",
"300 g",
].join("")
);
});
});