All checks were successful
PR Checks / lint-test-and-docker-build (pull_request) Successful in 2m18s
75 lines
2.9 KiB
TypeScript
75 lines
2.9 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { TEST_USERS } from './setup/test-users.js';
|
|
import { ensureSelfProfile, loginAsLocalUser } from './helpers/auth.js';
|
|
import {
|
|
addTraveller,
|
|
createTrip,
|
|
openAddToTripMenuItem,
|
|
openAddTraveller,
|
|
uniqueSuffix
|
|
} from './helpers/trip.js';
|
|
|
|
test.beforeEach(async ({ context }) => {
|
|
await context.clearCookies();
|
|
});
|
|
|
|
test('lodging guest selection and access boundaries are enforced', async ({ page }) => {
|
|
const suffix = uniqueSuffix();
|
|
const tripName = `E2E Lodging ${suffix}`;
|
|
const guestFirst = 'Jordan';
|
|
const guestLast = 'Guest';
|
|
const guestEmail = `jordan.${suffix}@test.local`;
|
|
const lodgingName = `E2E Lodge ${suffix}`;
|
|
|
|
await loginAsLocalUser(page, TEST_USERS.regular.username, TEST_USERS.regular.password);
|
|
await ensureSelfProfile(page);
|
|
const { tripUrl } = await createTrip(page, { name: tripName, description: 'Lodging guest coverage' });
|
|
|
|
const selfName = 'E2E User';
|
|
await openAddTraveller(page);
|
|
const travellerDialog = page.getByRole('dialog', { name: 'Add traveller' });
|
|
await expect(travellerDialog).toBeVisible();
|
|
const selfButton = travellerDialog.getByRole('button', { name: /You/ }).first();
|
|
if (await selfButton.isVisible().catch(() => false)) {
|
|
await selfButton.click();
|
|
await expect(travellerDialog).toBeHidden();
|
|
} else {
|
|
const selfNameButton = travellerDialog.getByRole('button', { name: selfName }).first();
|
|
if (await selfNameButton.isVisible().catch(() => false)) {
|
|
await selfNameButton.click();
|
|
await expect(travellerDialog).toBeHidden();
|
|
}
|
|
}
|
|
|
|
await addTraveller(page, {
|
|
firstName: guestFirst,
|
|
lastName: guestLast,
|
|
email: guestEmail
|
|
});
|
|
|
|
await openAddToTripMenuItem(page, 'Lodgings');
|
|
const lodgingDialog = page.getByRole('dialog', { name: 'Add lodging' });
|
|
await expect(lodgingDialog).toBeVisible();
|
|
|
|
const guestName = `${guestFirst} ${guestLast}`;
|
|
await expect(lodgingDialog.getByRole('checkbox', { name: selfName })).toBeVisible();
|
|
await expect(lodgingDialog.getByRole('checkbox', { name: guestName })).toBeVisible();
|
|
|
|
await lodgingDialog.getByLabel('Name', { exact: false }).fill(lodgingName);
|
|
await lodgingDialog.getByRole('checkbox', { name: guestName }).check();
|
|
await lodgingDialog.getByRole('button', { name: 'Add lodging' }).click();
|
|
await expect(lodgingDialog).toBeHidden();
|
|
|
|
await expect(page.getByText(lodgingName, { exact: true })).toBeVisible();
|
|
await page.getByRole('button', { name: 'Edit lodging' }).click();
|
|
const editDialog = page.getByRole('dialog', { name: 'Edit lodging' });
|
|
await expect(editDialog).toBeVisible();
|
|
await expect(editDialog.getByRole('checkbox', { name: guestName })).toBeChecked();
|
|
await editDialog.getByRole('button', { name: 'Close' }).click();
|
|
|
|
await page.context().clearCookies();
|
|
await loginAsLocalUser(page, TEST_USERS.admin.username, TEST_USERS.admin.password);
|
|
await page.goto(tripUrl);
|
|
await expect(page.getByText(/Trip not found|Not found/i)).toBeVisible();
|
|
});
|