Add schedule for planner (#16091)

This commit is contained in:
Maschga 2024-12-01 12:53:11 +01:00 • committed by GitHub
parent 35c9452d76
commit a35a705e48
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 1771 additions and 421 deletions

View file

@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import { start, stop, baseUrl } from "./evcc";
import { start, stop, baseUrl, restart } from "./evcc";
test.use({ baseURL: baseUrl() });
test.describe.configure({ mode: "parallel" });
@ -14,25 +14,41 @@ test.afterEach(async () => {
await stop();
});
function getWeekday(offset = 1) {
const date = new Date();
date.setDate(date.getDate() + offset);
return date.toLocaleDateString("en-US", { weekday: "long" });
}
async function setAndVerifyPlan(page, lp, { soc, energy }) {
await lp.getByTestId("charging-plan").getByRole("button", { name: "none" }).click();
await lp.getByTestId("charging-plan-button").click();
if (soc) {
await page.getByTestId("plan-soc").selectOption(soc);
await page.getByTestId("static-plan-soc").selectOption(soc);
}
if (energy) {
// select "25 kWh (+50%)" by providing "25 kWh" as option text
const optionText = await page
.getByTestId("plan-energy")
.getByTestId("static-plan-energy")
.locator("option", { hasText: energy })
.textContent();
await page.getByTestId("plan-energy").selectOption(optionText);
await page.getByTestId("static-plan-energy").selectOption(optionText);
}
await page.getByTestId("plan-active").click();
await page.getByTestId("static-plan-active").click();
await page.getByRole("button", { name: "Close" }).click();
await expect(lp.getByTestId("charging-plan")).toContainText(soc || energy);
}
async function verifyRepeatingPlanAvailable(page, lp, expected) {
await lp.getByTestId("charging-plan-button").click();
if (expected) {
await expect(page.getByTestId("repeating-plan-add")).toBeVisible();
} else {
await expect(page.getByTestId("repeating-plan-add")).not.toBeVisible();
}
await page.getByRole("button", { name: "Close" }).click();
}
test.describe("basic functionality", async () => {
test("vehicle with soc and capacity, set and restart", async ({ page }) => {
await page.goto("/");
@ -52,10 +68,10 @@ test.describe("basic functionality", async () => {
await lp1.getByRole("button", { name: "Solar", exact: true }).click();
await lp1.getByTestId("charging-plan").getByRole("button", { name: "none" }).click();
await page.getByTestId("plan-day").selectOption({ index: 1 });
await page.getByTestId("plan-time").fill("09:30");
await page.getByTestId("plan-soc").selectOption("80%");
await page.getByTestId("plan-active").click();
await page.getByTestId("static-plan-day").selectOption({ index: 1 });
await page.getByTestId("static-plan-time").fill("09:30");
await page.getByTestId("static-plan-soc").selectOption("80%");
await page.getByTestId("static-plan-active").click();
await page.getByRole("button", { name: "Close" }).click();
await expect(lp1.getByTestId("plan-marker")).toBeVisible();
@ -70,13 +86,13 @@ test.describe("basic functionality", async () => {
"tomorrow 9:30 AM80%"
);
await lp1.getByTestId("charging-plan").getByRole("button").click();
await expect(page.getByTestId("plan-soc")).toHaveValue("80");
await expect(page.getByTestId("static-plan-soc")).toHaveValue("80");
});
});
test.describe("vehicle variations", async () => {
test.describe("guest vehicle", async () => {
test("kWh based plan and limit", async ({ page }) => {
test("kWh based plan and limit, no repeats", async ({ page }) => {
await page.goto("/");
const lp1 = await page.getByTestId("loadpoint").first();
@ -88,11 +104,14 @@ test.describe("vehicle variations", async () => {
// kWh based plan
await setAndVerifyPlan(page, lp1, { energy: "25 kWh" });
// no repeating plans option
await verifyRepeatingPlanAvailable(page, lp1, false);
});
});
test.describe("vehicle no soc no capacity", async () => {
test("kWh based plan and limit", async ({ page }) => {
test("kWh based plan and limit, no repeats", async ({ page }) => {
await page.goto("/");
const lp1 = await page.getByTestId("loadpoint").first();
@ -108,11 +127,14 @@ test.describe("vehicle variations", async () => {
// kWh based plan
await setAndVerifyPlan(page, lp1, { energy: "25 kWh" });
// no repeating plans option
await verifyRepeatingPlanAvailable(page, lp1, false);
});
});
test.describe("vehicle no soc with capacity", async () => {
test("kWh based plan and limit", async ({ page }) => {
test("kWh based plan and limit, no repeats", async ({ page }) => {
await page.goto("/");
const lp1 = await page.getByTestId("loadpoint").first();
@ -128,11 +150,14 @@ test.describe("vehicle variations", async () => {
// kWh based plan
await setAndVerifyPlan(page, lp1, { energy: "25 kWh" });
// no repeating plans option
await verifyRepeatingPlanAvailable(page, lp1, false);
});
});
test.describe("vehicle with soc no capacity", async () => {
test("kWh based plan and soc based limit", async ({ page }) => {
test("kWh based plan and soc based limit, no repeats", async ({ page }) => {
await page.goto("/");
const lp1 = await page.getByTestId("loadpoint").first();
@ -148,11 +173,14 @@ test.describe("vehicle variations", async () => {
// soc based plan
await setAndVerifyPlan(page, lp1, { energy: "50 kWh" });
// no repeating plans option
await verifyRepeatingPlanAvailable(page, lp1, false);
});
});
test.describe("vehicle with soc with capacity", async () => {
test("soc based plan and limit", async ({ page }) => {
test("soc based plan and limit, with repeats", async ({ page }) => {
await page.goto("/");
const lp1 = await page.getByTestId("loadpoint").first();
@ -168,11 +196,14 @@ test.describe("vehicle variations", async () => {
// soc based plan
await setAndVerifyPlan(page, lp1, { soc: "60%" });
// repeating plans option
await verifyRepeatingPlanAvailable(page, lp1, true);
});
});
test.describe("loadpoint with soc, guest vehicle", async () => {
test("kWh based plan and soc based limit", async ({ page }) => {
test("kWh based plan and soc based limit, no repeats", async ({ page }) => {
await page.goto("/");
const lp2 = await page.getByTestId("loadpoint").last();
@ -185,11 +216,14 @@ test.describe("vehicle variations", async () => {
// soc based plan
await setAndVerifyPlan(page, lp2, { energy: "50 kWh" });
// no repeating plans option
await verifyRepeatingPlanAvailable(page, lp2, false);
});
});
test.describe("loadpoint with soc, vehicle with capacity", async () => {
test("soc based plan and limit", async ({ page }) => {
test("soc based plan and limit, with repeats", async ({ page }) => {
await page.goto("/");
const lp2 = await page.getByTestId("loadpoint").last();
@ -205,6 +239,9 @@ test.describe("vehicle variations", async () => {
// soc based plan
await setAndVerifyPlan(page, lp2, { soc: "60%" });
// repeating plans option
await verifyRepeatingPlanAvailable(page, lp2, true);
});
});
});
@ -214,12 +251,12 @@ test.describe("preview", async () => {
{
szenario: "kWh based plan",
vehicle: "Vehicle no SoC with Capacity",
goalId: "plan-energy",
goalId: "static-plan-energy",
},
{
szenario: "soc based plan",
vehicle: "Vehicle with SoC with Capacity",
goalId: "plan-soc",
goalId: "static-plan-soc",
},
];
@ -235,29 +272,29 @@ test.describe("preview", async () => {
await lp1.getByTestId("charging-plan").getByRole("button", { name: "none" }).click();
// initial set -> preview plan
await page.getByTestId("plan-day").selectOption({ index: 1 });
await page.getByTestId("plan-time").fill("09:30");
await page.getByTestId("static-plan-day").selectOption({ index: 1 });
await page.getByTestId("static-plan-time").fill("09:30");
await page.getByTestId(c.goalId).selectOption("80");
await expect(page.getByTestId("plan-preview-title")).toHaveText("Preview plan");
// activate -> active plan
await page.getByTestId("plan-active").click();
await page.getByTestId("static-plan-active").click();
await expect(page.getByTestId("plan-preview-title")).toHaveText("Active plan");
// change -> preview plan
await page.getByTestId(c.goalId).selectOption("90");
await expect(page.getByTestId("plan-preview-title")).toHaveText("Preview plan");
await expect(page.getByTestId("plan-preview-title")).toHaveText("Active plan");
// apply -> active plan
await expect(page.getByTestId("plan-apply")).toBeVisible();
await page.getByTestId("plan-apply").click();
await expect(page.getByTestId("static-plan-apply")).toBeVisible();
await page.getByTestId("static-plan-apply").click();
await expect(page.getByTestId("plan-preview-title")).toHaveText("Active plan");
// deactivate -> stay in preview
await page.getByTestId("plan-time").fill("23:30");
await expect(page.getByTestId("plan-preview-title")).toHaveText("Preview plan");
await expect(page.getByTestId("plan-apply")).toBeVisible();
await page.getByTestId("plan-active").click();
await page.getByTestId("static-plan-time").fill("23:30");
await expect(page.getByTestId("plan-preview-title")).toHaveText("Active plan");
await expect(page.getByTestId("static-plan-apply")).toBeVisible();
// deactivate
await page.getByTestId("static-plan-active").click();
await expect(page.getByTestId("plan-preview-title")).toHaveText("Preview plan");
});
});
@ -277,7 +314,7 @@ test.describe("warnings", async () => {
await lp1.getByTestId("charging-plan").getByRole("button", { name: "none" }).click();
await page.getByTestId("plan-active").click();
await page.getByTestId("static-plan-active").click();
// match this text but with fuzzy date "getByText('Goal will be reached 52:10 h')"
await expect(page.getByTestId("plan-warnings")).toHaveText(/Goal will be reached .* later/);
@ -297,12 +334,258 @@ test.describe("warnings", async () => {
await expect(page.getByTestId("plan-entry-warnings")).not.toBeVisible();
await page.getByTestId("plan-day").selectOption({ index: 0 });
await page.getByTestId("plan-time").fill("00:01");
await page.getByTestId("static-plan-day").selectOption({ index: 0 });
await page.getByTestId("static-plan-time").fill("00:01");
await expect(page.getByTestId("plan-entry-warnings")).toContainText(
"Pick a time in the future, Marty."
);
await page.getByTestId("plan-time").fill("00:01");
await page.getByTestId("static-plan-time").fill("00:01");
});
});
test.describe("repeating", async () => {
test("add and remove plans", async ({ page }) => {
await page.goto("/");
const lp1 = await page.getByTestId("loadpoint").first();
await lp1
.getByTestId("change-vehicle")
.locator("select")
.selectOption("Vehicle with SoC with Capacity");
await lp1.getByTestId("charging-plan").getByRole("button", { name: "none" }).click();
const modal = await page.getByTestId("charging-plan-modal");
// one static plan, no number
await expect(modal.getByTestId("plan-entry")).toHaveCount(1);
await expect(modal.getByTestId("plan-entry").first()).not.toContainText("#1");
// add plan
await modal.getByRole("button", { name: "Add repeating plan" }).click();
await expect(modal.getByTestId("plan-entry")).toHaveCount(2);
await expect(modal.getByTestId("plan-entry").first()).toContainText("#1");
await expect(modal.getByTestId("plan-entry").last()).toContainText("#2");
// remove plan
await modal.getByTestId("plan-entry").last().getByRole("button", { name: "Remove" }).click();
await expect(modal.getByTestId("plan-entry")).toHaveCount(1);
await expect(modal.getByTestId("plan-entry").first()).not.toContainText("#1");
});
test("preview static and repeating plan", async ({ page }) => {
await page.goto("/");
const lp1 = await page.getByTestId("loadpoint").first();
await lp1
.getByTestId("change-vehicle")
.locator("select")
.selectOption("Vehicle with SoC with Capacity");
await lp1.getByTestId("charging-plan").getByRole("button", { name: "none" }).click();
const modal = await page.getByTestId("charging-plan-modal");
// one static plan
await expect(modal.getByTestId("plan-entry")).toHaveCount(1);
await modal.getByTestId("static-plan-day").selectOption({ index: 1 }); // tomorrow
await modal.getByTestId("static-plan-time").fill("09:00");
await expect(modal.getByTestId("plan-preview-title")).toHaveText("Preview plan");
await expect(modal.getByTestId("target-text")).toContainText("9:00 AM");
// add repeating plan
await modal.getByRole("button", { name: "Add repeating plan" }).click();
await modal.getByTestId("repeating-plan-weekdays").click();
await modal.getByRole("checkbox", { name: "Select all" }).check();
await modal.getByTestId("repeating-plan-time").fill("11:11");
// switch between previews
await modal
.getByTestId("plan-preview-title")
.getByRole("combobox")
.selectOption("Preview plan #2");
await expect(modal.getByTestId("target-text")).toContainText("11:11 AM");
await modal
.getByTestId("plan-preview-title")
.getByRole("combobox")
.selectOption("Preview plan #1");
await expect(modal.getByTestId("target-text")).toContainText("9:00 AM");
// activate #1
await modal.getByTestId("static-plan-active").click();
await expect(modal.getByTestId("plan-preview-title")).toHaveText("Next plan #1");
await expect(modal.getByTestId("target-text")).toContainText("9:00 AM");
// activate #2
await modal.getByTestId("static-plan-active").click();
await modal.getByTestId("repeating-plan-active").click();
await expect(modal.getByTestId("plan-preview-title")).toHaveText("Next plan #2");
await expect(modal.getByTestId("target-text")).toContainText("11:11 AM");
// back to preview if no active plan
await modal.getByTestId("repeating-plan-active").click();
await expect(modal.getByTestId("plan-preview-title").locator("option:checked")).toHaveText(
"Preview plan #1"
);
await expect(modal.getByTestId("target-text")).toContainText("9:00 AM");
});
test("weekday selection", async ({ page }) => {
await page.goto("/");
const lp1 = await page.getByTestId("loadpoint").first();
await lp1
.getByTestId("change-vehicle")
.locator("select")
.selectOption("Vehicle with SoC with Capacity");
await lp1.getByTestId("charging-plan").getByRole("button", { name: "none" }).click();
const modal = await page.getByTestId("charging-plan-modal");
await modal.getByRole("button", { name: "Add repeating plan" }).click();
// weekday select should have value "Mo-Fr"
await expect(modal.getByTestId("repeating-plan-weekdays").getByRole("button")).toHaveText(
"Mon – Fri"
);
// select all weekdays
await modal.getByTestId("repeating-plan-weekdays").click();
await modal.getByRole("checkbox", { name: "Select all" }).click();
await expect(modal.getByTestId("repeating-plan-weekdays").getByRole("button")).toHaveText(
"Mon – Sun"
);
// select none
await modal.getByRole("checkbox", { name: "Select all" }).click();
await expect(modal.getByTestId("repeating-plan-weekdays").getByRole("button")).toHaveText("–");
// select specific weekdays
await modal.getByRole("checkbox", { name: "Thursday" }).check();
await expect(modal.getByTestId("repeating-plan-weekdays").getByRole("button")).toHaveText(
"Thu"
);
await modal.getByTestId("repeating-plan-weekdays").click(); // close
// activate
await modal.getByTestId("repeating-plan-time").fill("02:22");
await modal.getByTestId("repeating-plan-active").click();
// specific weekday and time
await expect(modal.getByTestId("plan-preview-title")).toHaveText("Next plan #2");
await expect(modal.getByTestId("target-text")).toContainText("Thu 2:22 AM");
});
test("next plan", async ({ page }) => {
await page.goto("/");
const yesterday = getWeekday(-1);
const tomorrow = getWeekday(1);
const lp1 = await page.getByTestId("loadpoint").first();
await lp1
.getByTestId("change-vehicle")
.locator("select")
.selectOption("Vehicle with SoC with Capacity");
await lp1.getByTestId("charging-plan").getByRole("button", { name: "none" }).click();
const modal = await page.getByTestId("charging-plan-modal");
// configure static plan for tomorrow
const plan1 = modal.getByTestId("plan-entry").nth(0);
await plan1.getByTestId("static-plan-day").selectOption({ index: 1 });
await plan1.getByTestId("static-plan-time").fill("09:30");
await plan1.getByTestId("static-plan-active").click();
// add repeating plan for tomorrow
await modal.getByRole("button", { name: "Add repeating plan" }).click();
const plan2 = modal.getByTestId("plan-entry").nth(1);
const days2 = plan2.getByTestId("repeating-plan-weekdays");
await days2.click();
await days2.getByRole("checkbox", { name: "Select all" }).click();
await days2.getByRole("checkbox", { name: "Select all" }).click();
await days2.getByRole("checkbox", { name: tomorrow }).check();
await days2.click(); // close
await plan2.getByTestId("repeating-plan-time").fill("09:20");
await plan2.getByTestId("repeating-plan-active").click();
// add repeating plan for every day
await modal.getByRole("button", { name: "Add repeating plan" }).click();
const plan3 = modal.getByTestId("plan-entry").last();
const days3 = plan3.getByTestId("repeating-plan-weekdays");
await days3.click();
await days3.getByRole("checkbox", { name: "Select all" }).check();
await days3.click(); // close
await plan3.getByTestId("repeating-plan-time").fill("09:10");
await plan3.getByTestId("repeating-plan-active").click();
// check next plans
await expect(modal.getByTestId("plan-preview-title")).toHaveText("Next plan #3");
await expect(modal.getByTestId("target-text")).toContainText("9:10 AM");
// disable plan #3
await plan3.getByTestId("repeating-plan-active").click();
await expect(modal.getByTestId("plan-preview-title")).toHaveText("Next plan #2");
await expect(modal.getByTestId("target-text")).toContainText("9:20 AM");
// change plan #2 to yesterday
await days2.click();
await days2.getByRole("checkbox", { name: tomorrow }).click(); // uncheck
await days2.getByRole("checkbox", { name: yesterday }).click(); // check
await days2.click(); // close
// no changes yet
await expect(modal.getByTestId("plan-preview-title")).toHaveText("Next plan #2");
await expect(modal.getByTestId("target-text")).toContainText("9:20 AM");
// apply
await plan2.getByTestId("repeating-plan-apply").click();
await expect(modal.getByTestId("plan-preview-title")).toHaveText("Next plan #1");
await expect(modal.getByTestId("target-text")).toContainText("9:30 AM");
});
test("repeating plan persistence", async ({ page }) => {
await page.goto("/");
const tomorrow = getWeekday(1);
let lp1 = await page.getByTestId("loadpoint").first();
await lp1
.getByTestId("change-vehicle")
.locator("select")
.selectOption("Vehicle with SoC with Capacity");
await lp1.getByTestId("charging-plan").getByRole("button", { name: "none" }).click();
let modal = await page.getByTestId("charging-plan-modal");
await modal.getByRole("button", { name: "Add repeating plan" }).click();
const plan = modal.getByTestId("plan-entry").nth(1);
await plan.getByTestId("repeating-plan-weekdays").click();
await plan.getByRole("checkbox", { name: "Select all" }).click(); // check all
await plan.getByRole("checkbox", { name: "Select all" }).click(); // uncheck all
await plan.getByRole("checkbox", { name: tomorrow }).check();
await plan.getByTestId("repeating-plan-time").fill("09:20");
await plan.getByTestId("repeating-plan-active").click();
await expect(modal.getByTestId("plan-preview-title")).toHaveText("Next plan #2");
await expect(modal.getByTestId("target-text")).toContainText("9:20 AM");
await restart(CONFIG);
await page.goto("/");
lp1 = await page.getByTestId("loadpoint").first();
await lp1
.getByTestId("change-vehicle")
.locator("select")
.selectOption("Vehicle with SoC with Capacity");
await lp1
.getByTestId("charging-plan")
.getByRole("button", { name: "tomorrow 9:20 AM" })
.click();
modal = await page.getByTestId("charging-plan-modal");
await expect(modal.getByTestId("plan-entry")).toHaveCount(2);
await expect(modal.getByTestId("plan-preview-title")).toHaveText("Next plan #2");
await expect(modal.getByTestId("target-text")).toContainText("9:20 AM");
});
});