From b43682ac397d5bc9b739d8ffab82b20ce4a948ca Mon Sep 17 00:00:00 2001 From: philipp Date: Sat, 27 Jul 2024 20:48:32 +0200 Subject: [PATCH] allow instand logbook add --- frontend/tests/log.spec.ts | 46 ++++++++++++++++++++++++++++++++++++++ src/model/logbook.rs | 3 +-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/frontend/tests/log.spec.ts b/frontend/tests/log.spec.ts index 942d196..d2789c5 100644 --- a/frontend/tests/log.spec.ts +++ b/frontend/tests/log.spec.ts @@ -244,3 +244,49 @@ test("Cox can start and finish trip with cox steering only", async ({ page }, te await expect(page.locator('body')).toContainText('(cox2)'); await expect(page.locator('body')).toContainText('Ottensheim (25 km)'); }); + +test("Kiosk can start and finish trip in one stop", async ({ page }, testInfo) => { + await page.goto("/log/kiosk/ekrv2019/Linz"); + + 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: "Joe" }).click(); + } else { + await page.getByText('2x', { exact: true }).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", + ); + + // 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 page.getByLabel('Ankunftszeit').click(); + await page.locator('#destination').fill('a'); + await page.getByLabel('Distanz').fill('1'); + + 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 page.getByRole('link', { name: 'Logbuch' }).click(); + await expect(page.locator('body')).toContainText('Joe'); + await expect(page.locator('body')).toContainText('(cox2)'); + await expect(page.locator('body')).toContainText('a (1 km)'); + await expect(page.locator('body')).toContainText('Ruderer: cox2, rower2'); +}); diff --git a/src/model/logbook.rs b/src/model/logbook.rs index 7757449..752556d 100644 --- a/src/model/logbook.rs +++ b/src/model/logbook.rs @@ -353,13 +353,12 @@ ORDER BY departure DESC let mut tx = db.begin().await.unwrap(); let inserted_row = sqlx::query!( - "INSERT INTO logbook(boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype) VALUES (?,?,?,?,?,?,?,?,?,?) RETURNING id", + "INSERT INTO logbook(boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, destination, distance_in_km, comments, logtype) VALUES (?,?,?,?,?,?,?,?,?) RETURNING id", log.boat_id, log.shipmaster, log.steering_person, log.shipmaster_only_steering, log.departure, - log.arrival, log.destination, log.distance_in_km, log.comments, -- 2.45.2