From 3927f188635123014597dad779fcc0292cc8971b Mon Sep 17 00:00:00 2001 From: philipp Date: Sun, 3 Mar 2024 20:47:26 +0100 Subject: [PATCH 1/7] add tests and fix npm build --- frontend/main.ts | 6 ++-- frontend/tests/log.spec.ts | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 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/tests/log.spec.ts b/frontend/tests/log.spec.ts new file mode 100644 index 0000000..0a19224 --- /dev/null +++ b/frontend/tests/log.spec.ts @@ -0,0 +1,60 @@ +import { test, expect } from '@playwright/test'; + +test('Cox can start and cancel trip', async ({ page }) => { + 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(); + 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 => { + console.log(`Dialog message: ${dialog.message()}`); + dialog.dismiss().catch(() => {}); + }); + await page.getByRole('link', { name: 'Löschen' }).click(); +}); + +test('Cox can start and finish trip', async ({ page }) => { + 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(); + 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.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.waitForTimeout(60000); + await page.getByRole('button', { name: 'Ausfahrt beenden' }).click(); + await expect(page.locator('body')).toContainText('Ausfahrt korrekt eingetragen'); +}); -- 2.45.2 From 6f8958937c070ac114e9c0a1263d30aec0f482af Mon Sep 17 00:00:00 2001 From: philipp Date: Sun, 3 Mar 2024 21:11:38 +0100 Subject: [PATCH 2/7] accept deleting trip --- frontend/tests/log.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/tests/log.spec.ts b/frontend/tests/log.spec.ts index 0a19224..d7a2cba 100644 --- a/frontend/tests/log.spec.ts +++ b/frontend/tests/log.spec.ts @@ -24,7 +24,7 @@ test('Cox can start and cancel trip', async ({ page }) => { await page.getByRole('link', { name: 'Joe' }).click(); page.once('dialog', dialog => { console.log(`Dialog message: ${dialog.message()}`); - dialog.dismiss().catch(() => {}); + dialog.accept().catch(() => {}); }); await page.getByRole('link', { name: 'Löschen' }).click(); }); -- 2.45.2 From f0e98667696476b4a354f194bcb0d205aed659bc Mon Sep 17 00:00:00 2001 From: philipp Date: Sun, 3 Mar 2024 21:16:01 +0100 Subject: [PATCH 3/7] increase frontend test timeout --- frontend/playwright.config.ts | 1 + 1 file changed, 1 insertion(+) 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, -- 2.45.2 From 87388ae18adba7c09ca22d76210469037f5b8a58 Mon Sep 17 00:00:00 2001 From: philipp Date: Sun, 3 Mar 2024 21:35:42 +0100 Subject: [PATCH 4/7] increase waiting... --- frontend/tests/log.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/tests/log.spec.ts b/frontend/tests/log.spec.ts index d7a2cba..b2a740a 100644 --- a/frontend/tests/log.spec.ts +++ b/frontend/tests/log.spec.ts @@ -54,7 +54,7 @@ test('Cox can start and finish trip', async ({ page }) => { 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.waitForTimeout(60000); + await page.waitForTimeout(120000); await page.getByRole('button', { name: 'Ausfahrt beenden' }).click(); await expect(page.locator('body')).toContainText('Ausfahrt korrekt eingetragen'); }); -- 2.45.2 From 554242b65c9abb111969e1541e1bc590123ba179 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 4 Mar 2024 08:19:51 +0100 Subject: [PATCH 5/7] fix tests --- frontend/tests/log.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/tests/log.spec.ts b/frontend/tests/log.spec.ts index b2a740a..6643b03 100644 --- a/frontend/tests/log.spec.ts +++ b/frontend/tests/log.spec.ts @@ -52,9 +52,9 @@ test('Cox can start and finish trip', async ({ page }) => { await page.goto('http://localhost:8000/log'); await page.locator('div:nth-child(2) > .border-0').click(); + await page.waitForTimeout(60000); await page.getByRole('combobox', { name: 'Destination' }).click(); await page.getByRole('combobox', { name: 'Destination' }).fill('Ottensheim'); - await page.waitForTimeout(120000); await page.getByRole('button', { name: 'Ausfahrt beenden' }).click(); await expect(page.locator('body')).toContainText('Ausfahrt korrekt eingetragen'); }); -- 2.45.2 From 92518642d4437e7ea038eb4d083c3e56bddf7389 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 4 Mar 2024 08:25:57 +0100 Subject: [PATCH 6/7] fix tests --- frontend/tests/log.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/tests/log.spec.ts b/frontend/tests/log.spec.ts index 6643b03..27b011d 100644 --- a/frontend/tests/log.spec.ts +++ b/frontend/tests/log.spec.ts @@ -51,8 +51,8 @@ test('Cox can start and finish trip', async ({ page }) => { await expect(page.locator('body')).toContainText('Joe'); await page.goto('http://localhost:8000/log'); - await page.locator('div:nth-child(2) > .border-0').click(); 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(); -- 2.45.2 From 971b98bf58c0bc429d0a185327367fe81fb4d73a Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 4 Mar 2024 09:49:04 +0100 Subject: [PATCH 7/7] make frontend tests work @ mobile view --- frontend/tests/log.spec.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/frontend/tests/log.spec.ts b/frontend/tests/log.spec.ts index 27b011d..f714b5c 100644 --- a/frontend/tests/log.spec.ts +++ b/frontend/tests/log.spec.ts @@ -1,6 +1,6 @@ import { test, expect } from '@playwright/test'; -test('Cox can start and cancel trip', async ({ page }) => { +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'); @@ -10,7 +10,12 @@ test('Cox can start and cancel trip', async ({ page }) => { await page.goto('http://localhost:8000/'); await page.getByRole('link', { name: 'Ausfahrt eintragen' }).click(); - await page.getByText('Joe', { exact: true }).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(); @@ -23,13 +28,12 @@ test('Cox can start and cancel trip', async ({ page }) => { await page.getByRole('link', { name: 'Joe' }).click(); page.once('dialog', dialog => { - console.log(`Dialog message: ${dialog.message()}`); dialog.accept().catch(() => {}); }); await page.getByRole('link', { name: 'Löschen' }).click(); }); -test('Cox can start and finish trip', async ({ page }) => { +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'); @@ -39,7 +43,12 @@ test('Cox can start and finish trip', async ({ page }) => { await page.goto('http://localhost:8000/'); await page.getByRole('link', { name: 'Ausfahrt eintragen' }).click(); - await page.getByText('Joe', { exact: true }).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(); -- 2.45.2