|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import { LoginPage } from '../../../Page objects/Login.page'; |
| 3 | +import { generateRandmString } from '../../../helper-functions'; |
| 4 | +import { CalendarUiEnhancementsPage } from '../calendar-ui-enhancements.page'; |
| 5 | +import { BackendConfigurationPropertiesPage, PropertyCreateUpdate } from '../BackendConfigurationProperties.page'; |
| 6 | + |
| 7 | +// Regression for the user report: the create-task modal pre-selected the |
| 8 | +// lowest-id board (first created) whenever more than one board was active, |
| 9 | +// ignoring the board the user had just activated. PropertyCreateUpdate fields: |
| 10 | +// name?, chrNumber?, cvrNumber?, address?, workOrderFlow?. |
| 11 | +const property: PropertyCreateUpdate = { |
| 12 | + name: 'cal-board-' + generateRandmString(5), |
| 13 | + chrNumber: generateRandmString(5), |
| 14 | + address: generateRandmString(5), |
| 15 | + cvrNumber: '1111111', |
| 16 | +}; |
| 17 | + |
| 18 | +// Board A is created first (lower id, the "Miljøtilsyn" analogue); board B is |
| 19 | +// created + activated last. With both active, the modal must default to B. |
| 20 | +const boardA = 'A-' + generateRandmString(5); |
| 21 | +const boardB = 'B-' + generateRandmString(5); |
| 22 | + |
| 23 | +// --- helpers -------------------------------------------------------------- |
| 24 | + |
| 25 | +async function createBoard(page: import('@playwright/test').Page, name: string) { |
| 26 | + await page.locator('a.sidebar-action-link', { hasText: 'Opret tavle' }).click(); |
| 27 | + const dialog = page.locator('mat-dialog-container'); |
| 28 | + await dialog.locator('input[formcontrolname="name"]').fill(name); |
| 29 | + await dialog.locator('button.btn-primary', { hasText: 'Opret' }).click(); |
| 30 | + await dialog.waitFor({ state: 'detached', timeout: 10000 }); |
| 31 | + await expect(page.locator('.board-list .board-name', { hasText: name })).toBeVisible({ timeout: 10000 }); |
| 32 | +} |
| 33 | + |
| 34 | +function boardItem(page: import('@playwright/test').Page, name: string) { |
| 35 | + return page.locator('.board-item', { has: page.locator('.board-name', { hasText: name }) }); |
| 36 | +} |
| 37 | + |
| 38 | +async function activateBoard(page: import('@playwright/test').Page, name: string) { |
| 39 | + await boardItem(page, name).locator('.board-name').click(); |
| 40 | + await expect(boardItem(page, name).locator('.board-checkbox.active')).toBeVisible({ timeout: 5000 }); |
| 41 | +} |
| 42 | + |
| 43 | +async function deactivateBoard(page: import('@playwright/test').Page, name: string) { |
| 44 | + await boardItem(page, name).locator('.board-name').click(); |
| 45 | + await expect(boardItem(page, name).locator('.board-checkbox.active')).toHaveCount(0, { timeout: 5000 }); |
| 46 | +} |
| 47 | + |
| 48 | +// The mtx-select displays the selected board's name as its value label. |
| 49 | +async function selectedBoardLabel(page: import('@playwright/test').Page): Promise<string> { |
| 50 | + return (await page.locator('#calendarEventBoard .mtx-select__value, #calendarEventBoard .ng-value-label') |
| 51 | + .first().innerText()).trim(); |
| 52 | +} |
| 53 | + |
| 54 | +// --- tests ---------------------------------------------------------------- |
| 55 | + |
| 56 | +test.describe.serial('Calendar new-task default board', () => { |
| 57 | + test.beforeEach(async ({ page }) => { |
| 58 | + await page.goto('http://localhost:4200'); |
| 59 | + await new LoginPage(page).login(); |
| 60 | + }); |
| 61 | + |
| 62 | + test('seed: property + two boards, activate A then B', async ({ page }) => { |
| 63 | + const propertiesPage = new BackendConfigurationPropertiesPage(page); |
| 64 | + await propertiesPage.goToProperties(); |
| 65 | + await propertiesPage.createProperty(property); |
| 66 | + |
| 67 | + const calendarPage = new CalendarUiEnhancementsPage(page); |
| 68 | + await calendarPage.goToCalendar(); |
| 69 | + await calendarPage.selectProperty(property.name as string); |
| 70 | + |
| 71 | + await createBoard(page, boardA); |
| 72 | + await createBoard(page, boardB); |
| 73 | + |
| 74 | + // Activate A first, then B — both stay checked, B is the last activated. |
| 75 | + await activateBoard(page, boardA); |
| 76 | + await activateBoard(page, boardB); |
| 77 | + await expect(boardItem(page, boardA).locator('.board-checkbox.active')).toBeVisible(); |
| 78 | + await expect(boardItem(page, boardB).locator('.board-checkbox.active')).toBeVisible(); |
| 79 | + }); |
| 80 | + |
| 81 | + test('create modal defaults to the last-activated board (B), not the lowest-id board (A)', async ({ page }) => { |
| 82 | + const calendarPage = new CalendarUiEnhancementsPage(page); |
| 83 | + await calendarPage.goToCalendar(); |
| 84 | + await calendarPage.selectProperty(property.name as string); |
| 85 | + |
| 86 | + // Re-activate A then B (a fresh page load reset the in-memory filter). |
| 87 | + await activateBoard(page, boardA); |
| 88 | + await activateBoard(page, boardB); |
| 89 | + |
| 90 | + await calendarPage.clickEmptyTimeSlot(1, 9); // Tuesday 09:00 next week |
| 91 | + await expect(page.locator('#calendarEventTitle')).toBeVisible({ timeout: 10000 }); |
| 92 | + |
| 93 | + expect(await selectedBoardLabel(page)).toBe(boardB); |
| 94 | + }); |
| 95 | + |
| 96 | + test('falls back when the last-activated board is deactivated', async ({ page }) => { |
| 97 | + const calendarPage = new CalendarUiEnhancementsPage(page); |
| 98 | + await calendarPage.goToCalendar(); |
| 99 | + await calendarPage.selectProperty(property.name as string); |
| 100 | + |
| 101 | + await activateBoard(page, boardA); |
| 102 | + await activateBoard(page, boardB); |
| 103 | + await deactivateBoard(page, boardB); // B (the last-activated) is no longer active |
| 104 | + |
| 105 | + await calendarPage.clickEmptyTimeSlot(1, 9); |
| 106 | + await expect(page.locator('#calendarEventTitle')).toBeVisible({ timeout: 10000 }); |
| 107 | + |
| 108 | + // The guard drops the no-longer-active last-activated board: the modal must |
| 109 | + // NOT default to B. It falls back to the existing behavior (the lowest-id |
| 110 | + // board — here the property's auto-created "Default" board, which stays |
| 111 | + // active alongside A). The board select is [clearable]="false", so a real |
| 112 | + // board is always shown — assert it's non-empty and specifically not B. |
| 113 | + const label = await selectedBoardLabel(page); |
| 114 | + expect(label.length).toBeGreaterThan(0); |
| 115 | + expect(label).not.toBe(boardB); |
| 116 | + }); |
| 117 | +}); |
0 commit comments