evcc-io/tests/smart-cost.spec.ts
2026-05-11 10:30:36 +02:00

72 lines
2.9 KiB
TypeScript

import { test, expect } from "@playwright/test";
import { start, stop, baseUrl } from "./evcc";
import { expectModalHidden, expectModalVisible } from "./utils";
import {
startSimulator,
stopSimulator,
simulatorUrl,
simulatorConfig,
simulatorApply,
} from "./simulator";
test.use({ baseURL: baseUrl() });
test.describe.configure({ mode: "parallel" });
test.beforeEach(async () => {
await startSimulator();
await start(simulatorConfig());
});
test.afterEach(async () => {
await stop();
await stopSimulator();
});
test.beforeEach(async ({ page }) => {
await page.goto(simulatorUrl());
await page.getByLabel("PV Power").fill("6000");
await page.getByTestId("loadpoint0").getByLabel("Power").fill("6000");
await page.getByTestId("loadpoint0").getByText("C (charging)").click();
await page.getByTestId("loadpoint0").getByText("Enabled").check();
await simulatorApply(page);
});
test.describe("smart cost limit", async () => {
test("no limit, normal charging", async ({ page }) => {
await page.goto("/");
await expect(page.getByTestId("vehicle-status-charger")).toHaveText("Charging…");
});
test("price below limit", async ({ page }) => {
await page.goto("/");
await page.getByTestId("loadpoint-settings-button").nth(1).click();
const modal = page.getByTestId("loadpoint-settings-modal");
await expectModalVisible(modal);
await modal.getByLabel("Enable limit").check();
await modal.getByLabel("Price limit").selectOption("≤ 40.0 ct/kWh");
await expect(modal.getByTestId("active-hours")).toHaveText(["Active time", "96 hr"].join(""));
await modal.getByLabel("Close").click();
await expectModalHidden(modal);
await expect(page.getByTestId("vehicle-status-charger")).toHaveText("Charging…");
await expect(page.getByTestId("vehicle-status-smartcost")).toHaveText(/[24]0\.0 ct ≤ 40\.0 ct/);
});
test("price above limit", async ({ page }) => {
await page.goto("/");
await page.getByTestId("loadpoint-settings-button").nth(1).click();
const modal = page.getByTestId("loadpoint-settings-modal");
await expectModalVisible(modal);
await modal.getByLabel("Enable limit").check();
await modal.getByLabel("Price limit").selectOption("≤ 0.0 ct/kWh");
await expect(modal.getByTestId("active-hours")).toHaveText("Active time");
await modal.getByLabel("Close").click();
await expectModalHidden(modal);
await expect(page.getByTestId("vehicle-status-charger")).toHaveText("Charging…");
await expect(page.getByTestId("vehicle-status-smartcost")).toHaveText("≤ 0.0 ct");
// Reload to force a fresh mount of the loadpoint components
await page.reload();
await page.getByTestId("loadpoint-settings-button").nth(1).click();
await expectModalVisible(modal);
await expect(modal.getByLabel("Enable limit")).toBeChecked();
await expect(modal.getByLabel("Price limit")).toContainText("≤ 0.0 ct/kWh");
});
});