From 0de21e9abb8a04371cf292794b54882ffa6ab996 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 4 Mar 2024 09:55:39 +0100 Subject: [PATCH] add tests and fix npm build, make frontend tests work @ mobile view Reviewed-on: https://git.hofer.link/Ruderverein-Donau-Linz/rowt/pulls/224 --- frontend/main.ts | 6 ++- frontend/playwright.config.ts | 1 + frontend/tests/log.spec.ts | 69 +++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 frontend/tests/log.spec.ts diff --git a/frontend/main.ts b/frontend/main.ts index 5a25b2b..2ddfe48 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -107,6 +107,7 @@ interface ChoiceBoatEvent extends Event{ amount_seats: number, owner: number, default_destination: string, + boat_in_ottensheim: boolean, } }; } @@ -277,6 +278,7 @@ interface ChoiceEvent extends Event{ is_cox: boolean, steers: boolean, cox_on_boat: boolean, + is_racing: boolean, } }; } @@ -323,7 +325,7 @@ function initNewChoice(select: HTMLInputElement) { }, callbackOnInit: function() { this._currentState.items.forEach(function(obj){ - if (boat_in_ottensheim) { + if (boat_in_ottensheim && obj.customProperties) { if (obj.customProperties.is_racing) { const coxSelect = document.querySelector('#shipmaster-' + select.id + 'js'); var new_option = new Option(obj.label, obj.value); @@ -359,7 +361,7 @@ function initNewChoice(select: HTMLInputElement) { const user_id = event.detail.value; const name = event.detail.label; - if (boat_in_ottensheim) { + if (boat_in_ottensheim && event.detail.customProperties.is_racing) { if (event.detail.customProperties.is_racing) { const coxSelect = document.querySelector('#shipmaster-' + select.id + 'js'); if (coxSelect){ diff --git a/frontend/playwright.config.ts b/frontend/playwright.config.ts index 3828370..691f890 100644 --- a/frontend/playwright.config.ts +++ b/frontend/playwright.config.ts @@ -10,6 +10,7 @@ import { defineConfig, devices } from '@playwright/test'; * See https://playwright.dev/docs/test-configuration. */ export default defineConfig({ + timeout: 180000, testDir: './tests', /* Run tests in files in parallel */ fullyParallel: true, diff --git a/frontend/tests/log.spec.ts b/frontend/tests/log.spec.ts new file mode 100644 index 0000000..f714b5c --- /dev/null +++ b/frontend/tests/log.spec.ts @@ -0,0 +1,69 @@ +import { test, expect } from '@playwright/test'; + +test('Cox can start and cancel trip', async ({ page }, testInfo) => { + await page.goto('http://localhost:8000/auth'); + await page.getByPlaceholder('Name').click(); + await page.getByPlaceholder('Name').fill('cox2'); + await page.getByPlaceholder('Name').press('Tab'); + await page.getByPlaceholder('Passwort').fill('cox'); + await page.getByPlaceholder('Passwort').press('Enter'); + + await page.goto('http://localhost:8000/'); + await page.getByRole('link', { name: 'Ausfahrt eintragen' }).click(); + if (testInfo.project.name.includes('Mobile')) { // No left boat selector on mobile views + await page.getByText('Kaputtes Boot :-( (7 x)').nth(1).click(); + await page.getByRole('option', { name: 'Joe' }).click(); + } else{ + await page.getByText('Joe', { exact: true }).click(); + } + await page.getByPlaceholder('Ruderer auswählen').click(); + await page.getByRole('option', { name: 'rower2' }).click(); + await page.getByRole('option', { name: 'cox2' }).click(); + await expect(page.getByRole('listbox')).toContainText('Nur 2 Ruderer können hinzugefügt werden'); + await expect(page.locator('#shipmaster-newrowerjs')).toContainText('cox'); + await expect(page.locator('#steering_person-newrowerjs')).toContainText('rower2 cox'); + await page.getByRole('button', { name: 'Ausfahrt eintragen' }).click(); + await expect(page.locator('body')).toContainText('Ausfahrt erfolgreich hinzugefügt'); + await expect(page.locator('body')).toContainText('Joe'); + + await page.getByRole('link', { name: 'Joe' }).click(); + page.once('dialog', dialog => { + dialog.accept().catch(() => {}); + }); + await page.getByRole('link', { name: 'Löschen' }).click(); +}); + +test('Cox can start and finish trip', async ({ page }, testInfo) => { + await page.goto('http://localhost:8000/auth'); + await page.getByPlaceholder('Name').click(); + await page.getByPlaceholder('Name').fill('cox2'); + await page.getByPlaceholder('Name').press('Tab'); + await page.getByPlaceholder('Passwort').fill('cox'); + await page.getByPlaceholder('Passwort').press('Enter'); + + await page.goto('http://localhost:8000/'); + await page.getByRole('link', { name: 'Ausfahrt eintragen' }).click(); + if (testInfo.project.name.includes('Mobile')) { // No left boat selector on mobile views + await page.getByText('Kaputtes Boot :-( (7 x)').nth(1).click(); + await page.getByRole('option', { name: 'Joe' }).click(); + } else{ + await page.getByText('Joe', { exact: true }).click(); + } + await page.getByPlaceholder('Ruderer auswählen').click(); + await page.getByRole('option', { name: 'rower2' }).click(); + await page.getByRole('option', { name: 'cox2' }).click(); + await expect(page.getByRole('listbox')).toContainText('Nur 2 Ruderer können hinzugefügt werden'); + await expect(page.locator('#shipmaster-newrowerjs')).toContainText('cox'); + await expect(page.locator('#steering_person-newrowerjs')).toContainText('rower2 cox'); + await page.getByRole('button', { name: 'Ausfahrt eintragen' }).click(); + await expect(page.locator('body')).toContainText('Ausfahrt erfolgreich hinzugefügt'); + await expect(page.locator('body')).toContainText('Joe'); + + await page.goto('http://localhost:8000/log'); + await page.waitForTimeout(60000); + await page.locator('div:nth-child(2) > .border-0').click(); + await page.getByRole('combobox', { name: 'Destination' }).click(); + await page.getByRole('combobox', { name: 'Destination' }).fill('Ottensheim'); + await page.getByRole('button', { name: 'Ausfahrt beenden' }).click(); + await expect(page.locator('body')).toContainText('Ausfahrt korrekt eingetragen'); +});