Files
pleno-vue/tests/e2e/userVehicles.spec.ts
T

106 lines
3.3 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { loginAsUser } from "./fixtures";
const json = (body, status = 200) => ({
status,
contentType: "application/json",
body: JSON.stringify(body),
});
const suppressVersionCheck = async (page) => {
await page.addInitScript(() => {
window.localStorage.setItem("lastVersionCheck", String(Date.now()));
});
await page.route(/\/worker\/version(\?.*)?$/i, async (route) => {
await route.fulfill(
json({
data: {
version: "test-build",
},
})
);
});
};
const mockVehicleTypeProducts = async (page) => {
await page.route(/\/products(?:\?.*)?$/i, async (route) => {
await route.fulfill(
json({
data: [
{
id: 53,
name: "Forvogn",
is_wash: true,
subscription_allowed: true,
category: 4,
},
{
id: 54,
name: "Trailer",
is_wash: true,
subscription_allowed: true,
category: 4,
},
],
})
);
});
};
test("[PAGES][User][/user/vehicles] shows the current vehicles overview shell", async ({ page }) => {
await suppressVersionCheck(page);
await loginAsUser(page);
await page.goto("/user/vehicles");
await expect(page.getByTestId("user-vehicles-add")).toBeVisible();
await expect(page.getByTestId("user-vehicles-table")).toBeVisible();
});
test("[PAGES][User][/user/vehicles] opens the add-vehicle dialog", async ({ page }) => {
await suppressVersionCheck(page);
await loginAsUser(page);
await page.goto("/user/vehicles");
await page.getByTestId("user-vehicles-add").click();
const dialog = page.getByRole("dialog");
await expect(dialog).toBeVisible();
await expect(dialog.getByRole("heading", { name: /opret/i })).toBeVisible();
await expect(dialog.locator("label").filter({ hasText: /^Type$/ })).toBeVisible();
await expect(dialog.locator("select#wash_subscription")).toHaveValue("false");
await expect(dialog.getByRole("button", { name: /gem/i })).toBeVisible();
await expect(dialog.getByRole("button", { name: /annuller/i })).toBeVisible();
});
test("[PAGES][User][/user/vehicles/new] creates a vehicle with a predefined type", async ({ page }) => {
await suppressVersionCheck(page);
await loginAsUser(page);
await mockVehicleTypeProducts(page);
await page.goto("/user/vehicles/new");
const typeSelect = page.getByTestId("user-add-vehicle-type");
await expect(page.getByTestId("user-add-vehicle-registration")).toBeVisible();
await expect(typeSelect).toBeVisible();
await expect(typeSelect).toContainText("Forvogn");
await expect(page.locator('input[placeholder="Type"]')).toHaveCount(0);
await page.getByTestId("user-add-vehicle-registration").fill("ab12345");
await typeSelect.selectOption("53");
await page.getByTestId("user-add-vehicle-reference").fill("Fleet ref");
const [request] = await Promise.all([
page.waitForRequest((request) => request.method() === "POST" && request.url().includes("/vehicles"), {
timeout: 10_000,
}),
page.getByTestId("user-add-vehicle-submit").click(),
]);
expect(request.postDataJSON()).toMatchObject({
reg: "AB12345",
type: 53,
wash_subscription: false,
reference: "Fleet ref",
});
await expect(page).toHaveURL(/\/user\/vehicles(?:[?#].*)?$/);
});