Files
pleno-vue/tests/e2e/userVehicles.spec.ts
T
Jeppe Bundgaard 60742bf947 Refactor and migrate Playwright E2E tests:
- Remove `playwright.config.js` to clean up configuration.
- Add new E2E test suites (`admin-pos-orders`, `admin-module-goals`, `admin-module-pos-mobile-order-flow`) to structure Admin module tests.
- Introduce reusable authentication and data seeding utilities in `fixtures` for streamlined test flows and maintainability.
2026-03-19 12:46:47 +01:00

107 lines
4.2 KiB
TypeScript

import { test, expect } from '@playwright/test';
import {
userCredentials,
subuserPhoneCredentials,
subuserUsernameCredentials,
operatorCredentials,
customerRegistrationData,
driverRegistrationData,
invalidCredentials,
loginAsUser,
loginAsSubuserByPhone,
loginAsSubuserByUsername,
loginAsOperator,
goToUserLogin,
goToSubuserLogin,
goToOperatorLogin,
vehicleTestData,
} from './fixtures';
/** User vehicles Tests */
// User vehicles page content tests
test('[PAGES][User][/user/vehicles] should display the title', async ({ page }) => {
await loginAsUser(page);
await page.goto('/user/vehicles');
// Check if the "Oversigt over registrerede køretøjer" message is displayed
await expect(page.locator('.title')).toContainText('Oversigt over registrerede køretøjer');
});
// Add vehicle button visibility test
test('[PAGES][User][/user/vehicles] should display the add vehicle button', async ({ page }) => {
await loginAsUser(page);
await page.goto('/user/vehicles');
// Check if the "Tilføj køretøj" add button is visible
await expect(page.locator('text="Tilføj køretøj"')).toBeVisible();
});
// Add vehicle form tests
// Delete a vehicle tests
// Search vehicles tests
// Pagination tests
// Vehicle details page tests
//...
test('DEBUG: inspect vehicles page buttons', async ({ page }) => {
await loginAsUser(page);
await page.goto('/user/vehicles');
await expect(page.locator('.title')).toContainText('Oversigt over registrerede køretøjer');
const buttons = page.locator('button, [role="button"]');
const count = await buttons.count();
console.log('Total buttons: ' + count);
for (let i = 0; i < Math.min(count, 10); i++) {
const btn = buttons.nth(i);
const text = await btn.textContent() || '';
const visible = await btn.isVisible();
console.log('Button ' + i + ': visible=' + visible + ', text="' + text.trim() + '"');
}
const addBtn = page.locator('text="Tilføj køretøj"');
const addCount = await addBtn.count();
console.log('Add button count: ' + addCount);
const table = page.locator('table');
const tableCount = await table.count();
console.log('Table count: ' + tableCount);
});
test('[DEBUG] click add vehicle and inspect', async ({ page }) => {
await loginAsUser(page);
await page.goto('/user/vehicles');
const addBtn = page.locator('text="Tilføj køretøj"');
await expect(addBtn).toBeVisible();
await addBtn.click();
await page.waitForTimeout(3000);
console.log('Current URL: ' + page.url());
const inputs = page.locator('input');
const inputCount = await inputs.count();
console.log('Input count after click: ' + inputCount);
for (let i = 0; i < inputCount; i++) {
const inp = inputs.nth(i);
const ph = await inp.getAttribute('placeholder') || '';
console.log('Input ' + i + ': placeholder="' + ph + '"');
}
const modals = page.locator('.modal, .is-active.modal, [class*="modal"]');
const modalCount = await modals.count();
console.log('Modal count: ' + modalCount);
if (modalCount > 0) {
const modalContent = await modals.first().textContent() || '';
console.log('Modal preview: ' + modalContent.substring(0, 500));
const modalClass = await modals.first().getAttribute('class') || '';
console.log('Modal class: ' + modalClass);
}
});
test('[User Vehicles] should open add vehicle modal', async ({ page }) => {
await loginAsUser(page);
await page.goto('/user/vehicles');
await page.locator('text=\"Tilføj køretøj\"').click();
await expect(page.locator('.modal.is-active')).toBeVisible();
await expect(page.locator('text=\"Opret køretøj\"')).toBeVisible();
});
test('[User Vehicles] add new vehicle - valid', async ({ page }) => {
await loginAsUser(page);
await page.goto('/user/vehicles');
const regNr = vehicleTestData.validRegNr;
await page.locator('text=\"Tilføj køretøj\"').click();
await expect(page.locator('.modal.is-active')).toBeVisible();
await page.getByLabel('Type').selectOption('Trækker');
await page.getByLabel('Reg. 1.').fill(regNr);
await page.getByLabel('Vaskeabonnement').check();
await page.locator('.modal.is-active >> text=\"Opret køretøj\"').click();
await expect(page.locator('.modal.is-active')).not.toBeVisible({ timeout: 5000 });
await expect(page.locator('text=' + regNr)).toBeVisible();
});