Files
pleno-vue/tests/e2e/workfeed-config.smoke.spec.js
T
Jeppe Bundgaard b39b458f4f Add .prettierrc.json and refactor test files for improved formatting consistency:
- Introduced `.prettierrc.json` to enforce consistent code formatting across the project.
- Updated unit and e2e test files to address formatting issues, improve readability, and ensure alignment with the new Prettier configuration.
2026-04-13 09:13:27 +02:00

105 lines
4.6 KiB
JavaScript

import { expect, test } from "@playwright/test";
import { mockApi, seedAuthenticatedState } from "./support/network.js";
async function primeSuperuserSession(page) {
const token = "superuser-workfeed-token";
await seedAuthenticatedState(page, token);
await page.goto("/login");
await page.evaluate(async (sessionToken) => {
const sessionModule = await import("/src/components/session/token/SessionUser.vue");
window.localStorage.setItem("token", sessionToken);
sessionModule.SessionUser.token.value = sessionToken;
sessionModule.SessionUser.authenticated.value = true;
sessionModule.SessionUser.permissions.value = ["superuser", "user"];
sessionModule.SessionUser.initiated.value = true;
}, token);
}
async function runDiagnostic(page, testId, inputValue = "") {
await page.locator(`[data-testid="${testId}"]:visible`).first().click();
await expect(page.locator(".swal2-popup")).toBeVisible();
const input = page.locator(".swal2-input");
if (await input.isVisible()) {
await input.fill(inputValue);
}
await page.locator(".swal2-confirm").click();
await expect(page.locator(".swal2-popup pre")).toBeVisible();
}
async function runShiftDiagnostic(page, { startFrom, startTo, employeeID = "", released = "" }) {
await page.locator('[data-testid="workfeed-diagnostics-list-shifts"]:visible').first().click();
await expect(page.locator(".swal2-popup")).toBeVisible();
await page.locator("#workfeed-start-from").fill(startFrom);
await page.locator("#workfeed-start-to").fill(startTo);
if (employeeID) {
await page.locator("#workfeed-employee-id").selectOption(employeeID);
}
if (released !== "") {
await page.locator("#workfeed-released").selectOption(released);
}
await page.locator(".swal2-confirm").click();
await expect(page.locator(".swal2-popup pre")).toBeVisible();
}
async function closeResultModal(page) {
await page.locator(".swal2-confirm").click();
await expect(page.locator(".swal2-popup")).toBeHidden();
}
async function expandCategory(page, title) {
await page.locator(".card-header.is-clickable:visible").filter({ hasText: title }).first().click();
}
test.describe("Workfeed configuration smoke", () => {
test.beforeEach(async ({ page }) => {
await mockApi(page, {
authenticated: true,
permissions: ["superuser", "user"],
});
await primeSuperuserSession(page);
});
test("@smoke renders workfeed config page and runs diagnostics", async ({ page }) => {
await page.goto("/superuser/configuration/workfeed");
await expect(page).toHaveURL(/\/superuser\/configuration\/workfeed$/);
await expect(page.locator("body")).toContainText("Workfeed configuration");
await expandCategory(page, "General settings");
await expect(page.locator("body")).toContainText("Enable Workfeed");
await expandCategory(page, "API connection settings");
await expect(page.locator("body")).toContainText("Company ID");
await expandCategory(page, "Diagnostics");
await expect(page.locator('[data-testid="workfeed-diagnostics-list-departments"]:visible').first()).toBeVisible();
await expect(page.locator('[data-testid="workfeed-diagnostics-list-employees"]:visible').first()).toBeVisible();
await expect(page.locator('[data-testid="workfeed-diagnostics-list-shifts"]:visible').first()).toBeVisible();
await expect(page.locator('[data-testid="workfeed-diagnostics-get-employee"]:visible').first()).toBeVisible();
await expect(page.locator('[data-testid="workfeed-diagnostics-get-shift"]:visible').first()).toBeVisible();
await runDiagnostic(page, "workfeed-diagnostics-list-departments");
await expect(page.locator(".swal2-popup pre")).toContainText("North Facility");
await closeResultModal(page);
await runDiagnostic(page, "workfeed-diagnostics-list-employees");
await expect(page.locator(".swal2-popup pre")).toContainText("Anne Nielsen");
await closeResultModal(page);
await runShiftDiagnostic(page, {
startFrom: "2026-03-24T00:00",
startTo: "2026-03-25T00:00",
employeeID: "emp_01J5P2F2A0CQKBBX4P8M3Y7R5P",
released: "true",
});
await expect(page.locator(".swal2-popup pre")).toContainText("Morning Shift");
await closeResultModal(page);
await runDiagnostic(page, "workfeed-diagnostics-get-employee", "emp_01J5P2F2A0CQKBBX4P8M3Y7R5P");
await expect(page.locator(".swal2-popup pre")).toContainText("Anne Nielsen");
await closeResultModal(page);
await runDiagnostic(page, "workfeed-diagnostics-get-shift", "shf_01J5P3X9D35R9C6BDZ1S0R4V6Q");
await expect(page.locator(".swal2-popup pre")).toContainText("Morning Shift");
await closeResultModal(page);
});
});