From 4237fafdff77195115c35854348283278a01b232 Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 13 Jul 2024 19:58:13 +0100 Subject: [PATCH 1/2] fix error, where log entries can't be added with boats with only steering --- frontend/main.ts | 4 +- frontend/tests/log.spec.ts | 54 ++++++++++++++++++++++++++ seeds.sql | 1 + templates/includes/forms/log.html.tera | 2 +- templates/includes/macros.html.tera | 7 ++-- 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/frontend/main.ts b/frontend/main.ts index 88bbd54..1cb7271 100644 --- a/frontend/main.ts +++ b/frontend/main.ts @@ -158,9 +158,9 @@ function selectBoatChange() { } if (event.detail.customProperties.convert_handoperated_possible) { - only_steering.removeAttribute('disabled'); + only_steering.removeAttribute('readonly'); }else { - only_steering.setAttribute('disabled', 'disabled'); + only_steering.setAttribute('readonly', 'readonly'); } const destination = ( diff --git a/frontend/tests/log.spec.ts b/frontend/tests/log.spec.ts index bc74ec4..890762b 100644 --- a/frontend/tests/log.spec.ts +++ b/frontend/tests/log.spec.ts @@ -190,3 +190,57 @@ test("Kiosk can start and finish trip", async ({ page }, testInfo) => { await expect(page.locator('body')).toContainText('Ottensheim (25 km)'); await expect(page.locator('body')).toContainText('Ruderer: cox2, rower2'); }); + +test("Cox can start and finish trip with cox steering only", async ({ page }, testInfo) => { + await page.goto("/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("/"); + await page.getByRole("link", { name: "Ausfahrt eintragen" }).click(); + if (testInfo.project.name.includes("Mobile")) { + // No left boat selector on mobile views + await page.getByText('-- Wähle ein Boot aus ---').nth(1).click(); + await page.getByRole("option", { name: "cox_only_steering_boat" }).click(); + } else { + await page.getByText('2+', { exact: true }).click(); + await page.getByText("cox_only_steering_boat", { exact: true }).click(); + } + + // Trip starts 2 hours ago + const datetimeSelector = '#departure'; + const currentValue = await page.$eval(datetimeSelector, el => el.value); + const currentDate = new Date(currentValue); + currentDate.setMinutes(currentDate.getMinutes()); + currentDate.setHours(currentDate.getHours() - new Date().getTimezoneOffset()/60 - 2); + const newDatetime = currentDate.toISOString().slice(0, 16); + await page.$eval(datetimeSelector, (el, value) => el.value = value, newDatetime); + + 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("cox_only_steering_boat"); + + await page.goto("/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.getByRole("button", { name: "Ausfahrt beenden" }).click(); + await expect(page.locator("body")).toContainText( + "Ausfahrt korrekt eingetragen", + ); + + await page.goto('/log/show'); + await expect(page.locator('body')).toContainText('cox_only_steering_boat'); + await expect(page.locator('body')).toContainText('(cox2)'); + await expect(page.locator('body')).toContainText('Ottensheim (25 km)'); +}); diff --git a/seeds.sql b/seeds.sql index ceb2296..d832416 100644 --- a/seeds.sql +++ b/seeds.sql @@ -55,6 +55,7 @@ INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Kaputtes Boot :-(' INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Sehr kaputtes Boot :-((', 7, 1); INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Ottensheim Boot', 7, 2); INSERT INTO "boat" (name, amount_seats, location_id, owner) VALUES ('second_private_boat_from_rower', 1, 1, 2); +INSERT INTO "boat" (name, amount_seats, location_id, default_shipmaster_only_steering) VALUES ('cox_only_steering_boat', 3, 1, true); INSERT INTO "logbook_type" (name) VALUES ('Wanderfahrt'); INSERT INTO "logbook_type" (name) VALUES ('Regatta'); INSERT INTO "logbook" (boat_id, shipmaster,steering_person, shipmaster_only_steering, departure) VALUES (2, 2, 2, false, strftime('%Y', 'now') || '-12-24 10:00'); diff --git a/templates/includes/forms/log.html.tera b/templates/includes/forms/log.html.tera index 7395747..6a5fb50 100644 --- a/templates/includes/forms/log.html.tera +++ b/templates/includes/forms/log.html.tera @@ -36,7 +36,7 @@
Bootssteuerung
- {{ macros::checkbox(label='handgesteuert', name='shipmaster_only_steering', disabled=true) }} + {{ macros::checkbox(label='handgesteuert', name='shipmaster_only_steering', readonly=true) }}
{{ log::rower_select(id="newrower", selected=[], class="col-span-4", init=true) }} diff --git a/templates/includes/macros.html.tera b/templates/includes/macros.html.tera index d8c2b8e..0549f5b 100644 --- a/templates/includes/macros.html.tera +++ b/templates/includes/macros.html.tera @@ -137,14 +137,15 @@ {% if readonly %}readonly{% endif %}> {% endmacro input %} -{% macro checkbox(label, name, id='', checked=false, class='', disabled=false) %} +{% macro checkbox(label, name, id='', checked=false, class='', disabled=false, readonly=false) %} -- 2.45.2 From 088fe989957d77a02318b337de419b164a63deff Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 13 Jul 2024 20:03:10 +0100 Subject: [PATCH 2/2] fix test --- 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 890762b..942d196 100644 --- a/frontend/tests/log.spec.ts +++ b/frontend/tests/log.spec.ts @@ -221,7 +221,7 @@ test("Cox can start and finish trip with cox steering only", async ({ page }, te await expect(page.locator("#shipmaster-newrowerjs")).toContainText("cox"); await expect(page.locator("#steering_person-newrowerjs")).toContainText( - "rower2 cox", + "cox", ); await page.getByRole("button", { name: "Ausfahrt eintragen" }).click(); await expect(page.locator("body")).toContainText( -- 2.45.2