|
| 1 | +// SPDX-FileCopyrightText: Copyright (C) 2023-2026 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)<lichtblick@bmwgroup.com> |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +import { test, expect } from "@playwright/test"; |
| 5 | + |
| 6 | +import { loadFiles } from "../../fixtures/load-files"; |
| 7 | + |
| 8 | +const MCAP_FILENAME = "example.mcap"; |
| 9 | + |
| 10 | +/** |
| 11 | + * GIVEN a .mcap file and layout are loaded |
| 12 | + * AND the player time is initialized |
| 13 | + * WHEN the playback timestamp is manually edited in the player input |
| 14 | + * AND the new timestamp is confirmed |
| 15 | + * THEN the URL time parameter should update to the new ISO timestamp |
| 16 | + */ |
| 17 | + |
| 18 | +test("is able to manually edit the timestamp display on the player", async ({ page }) => { |
| 19 | + // Given |
| 20 | + const getTimeParam = () => new URL(page.url()).searchParams.get("time"); |
| 21 | + |
| 22 | + await page.goto("/"); |
| 23 | + await loadFiles({ mainWindow: page, filenames: MCAP_FILENAME }); |
| 24 | + const urlInitialTimestamp = "2025-02-26T10:37:15.547000000Z"; |
| 25 | + |
| 26 | + // When |
| 27 | + await page.evaluate((time) => { |
| 28 | + const url = new URL(window.location.href); |
| 29 | + url.searchParams.set("time", time); |
| 30 | + window.history.replaceState({}, "", url.toString()); |
| 31 | + }, urlInitialTimestamp); |
| 32 | + await page.waitForURL(() => getTimeParam() === urlInitialTimestamp); |
| 33 | + |
| 34 | + // Then |
| 35 | + expect(getTimeParam()).toBe(urlInitialTimestamp); |
| 36 | + |
| 37 | + // When |
| 38 | + const timestampInput = page.getByTestId("PlaybackTime-text").locator("input"); |
| 39 | + const newTimestamp = "2025-02-26 10:37:18.499 AM WET"; |
| 40 | + await timestampInput.click(); |
| 41 | + await timestampInput.fill(newTimestamp); |
| 42 | + await timestampInput.press("Enter"); |
| 43 | + await timestampInput.blur(); |
| 44 | + |
| 45 | + // Then |
| 46 | + const urlNewTimestamp = "2025-02-26T10:37:18.499000000Z"; |
| 47 | + await page.waitForURL(() => getTimeParam() === urlNewTimestamp); |
| 48 | + expect(getTimeParam()).toBe(urlNewTimestamp); |
| 49 | +}); |
| 50 | + |
| 51 | +/** |
| 52 | + * GIVEN a .mcap file and layout are loaded |
| 53 | + * AND the playback time display is switched to epoch format |
| 54 | + * AND the player time is initialized |
| 55 | + * WHEN the playback timestamp is manually edited using an epoch value |
| 56 | + * AND the new timestamp is confirmed |
| 57 | + * THEN the URL time parameter should update to the corresponding ISO timestamp |
| 58 | + */ |
| 59 | + |
| 60 | +test("is able to manually edit the timestamp display (epoch format) on the player", async ({ |
| 61 | + page, |
| 62 | +}) => { |
| 63 | + // Given |
| 64 | + const getTimeParam = () => new URL(page.url()).searchParams.get("time"); |
| 65 | + |
| 66 | + await page.goto("/"); |
| 67 | + await loadFiles({ mainWindow: page, filenames: MCAP_FILENAME }); |
| 68 | + const urlInitialTimestamp = "2025-02-26T10:37:15.547000000Z"; |
| 69 | + |
| 70 | + // When |
| 71 | + const playerStartingTime = page.getByTestId("PlaybackTime-text").locator("div"); |
| 72 | + // Playback time display needs to be hovered first so clicking on it is possible |
| 73 | + await playerStartingTime.hover(); |
| 74 | + await page.getByTestId("playback-time-display-toggle-button").click(); |
| 75 | + await page.getByTestId("playback-time-display-option-SEC").click(); |
| 76 | + |
| 77 | + // When |
| 78 | + await page.evaluate((time) => { |
| 79 | + const url = new URL(window.location.href); |
| 80 | + url.searchParams.set("time", time); |
| 81 | + window.history.replaceState({}, "", url.toString()); |
| 82 | + }, urlInitialTimestamp); |
| 83 | + await page.waitForURL(() => getTimeParam() === urlInitialTimestamp); |
| 84 | + |
| 85 | + // Then |
| 86 | + expect(getTimeParam()).toBe(urlInitialTimestamp); |
| 87 | + |
| 88 | + // When |
| 89 | + const timestampInput = page.getByTestId("PlaybackTime-text").locator("input"); |
| 90 | + const newEpochTimestamp = "1740566238.499000000"; |
| 91 | + await timestampInput.click(); |
| 92 | + await timestampInput.fill(newEpochTimestamp); |
| 93 | + await timestampInput.press("Enter"); |
| 94 | + await timestampInput.blur(); |
| 95 | + |
| 96 | + // Then |
| 97 | + const urlNewTimestamp = "2025-02-26T10:37:18.499000000Z"; |
| 98 | + await page.waitForURL(() => getTimeParam() === urlNewTimestamp); |
| 99 | + expect(getTimeParam()).toBe(urlNewTimestamp); |
| 100 | +}); |
0 commit comments