Skip to content

Commit

Permalink
test: Add E2E test for homepage satellite Selector and satellite pass…
Browse files Browse the repository at this point in the history
… over a certain location (#447)
  • Loading branch information
Thibault authored and GitHub committed Jun 16, 2025
1 parent b42ce45 commit f84d537
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
7 changes: 6 additions & 1 deletion frontend/src/app/_homeComponents/SatDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,12 @@ export default function SatDropdown() {
<button
className="flex w-full cursor-pointer flex-row justify-between bg-black p-4 text-left"
onClick={toggleDropdown}
data-testid="satellite-dropdown-button"
>
<div className="flex flex-col">
<div>{selectedSatelliteName || "Select a Satellite"}</div>
<div data-testid="satellite-name">
{selectedSatelliteName || "Select a Satellite"}
</div>
<p className="text-gray-400">
{selectedSatelliteName ? "Selected Satellite" : null}
</p>
Expand All @@ -144,6 +147,7 @@ export default function SatDropdown() {
animate={isOpen ? "open" : "collapsed"}
variants={variants}
transition={{ duration: 0.5 }}
data-testid="satellite-dropdown-list"
>
{Object.entries(satNumToEntry).map(([num]) => {
let satNum = Number(num) as SatelliteNumber;
Expand All @@ -157,6 +161,7 @@ export default function SatDropdown() {
onClick={() =>
handleSelect(Number(num) as SatelliteNumber)
}
role="option"
>
{satNumToEntry[satNum].name}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ export default function SatellitePassOverLocation() {
<button
className="flex w-full cursor-pointer flex-row justify-between bg-black p-4 text-left"
onClick={toggleDropdown}
data-testid="location-dropdown-button"
>
<div className="flex flex-col">
<div>
<div data-testid="location-name">
{displaeydCity ||
displayedLocation ||
"Select a Location"}
Expand Down Expand Up @@ -147,12 +148,14 @@ export default function SatellitePassOverLocation() {
animate={isOpen ? "open" : "collapsed"}
variants={variants}
transition={{ duration: 0.5 }}
data-testid="location-dropdown-list"
>
{locations.map((location, idx) => (
<div
key={idx}
className="cursor-pointer p-2 text-white hover:bg-gray-700"
onClick={() => handleSelect(location)}
role="option"
>
{location.name} ({location.latitude + "° N"},{" "}
{location.longitude + "° E"})
Expand All @@ -168,6 +171,7 @@ export default function SatellitePassOverLocation() {
onKeyDown={handleKeyDown}
className="flex-1 bg-black p-2 text-white outline-none"
placeholder="latitude"
data-testid="latitude-input"
/>
<input
type="text"
Expand All @@ -176,6 +180,7 @@ export default function SatellitePassOverLocation() {
onKeyDown={handleKeyDown}
className="flex-2 bg-black p-2 text-white outline-none"
placeholder="longitude"
data-testid="longitude-input"
/>
</div>
<button
Expand All @@ -185,6 +190,7 @@ export default function SatellitePassOverLocation() {
}
}}
className="flex-3 mr-2 whitespace-nowrap rounded-md border bg-primary p-1 text-white duration-200 ease-in-out hover:opacity-80"
data-testid="add-location-button"
>
Add Location
</button>
Expand Down
44 changes: 44 additions & 0 deletions frontend/tests/e2e/homepage.desktop.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { test, expect } from "@playwright/test";
import exp from "constants";

test.describe("Homepage Test", () => {
test("CheckSatelliteSelector", async ({ page }) => {
await page.goto("/");
await expect(
page.getByTestId("satellite-dropdown-button"),
).toBeVisible();
await page.getByTestId("satellite-dropdown-button").click();
await expect(page.getByTestId("satellite-dropdown-list")).toBeVisible();
await expect(
page.getByTestId("satellite-dropdown-list").getByRole("option"),
).toHaveCount(2); // By default, there are two options: "Hypso-1" and "Hypso-2"
await page
.getByTestId("satellite-dropdown-list")
.getByRole("option")
.nth(1)
.click();
await expect(page.getByTestId("satellite-name")).toHaveText("HYPSO-2");
});
test("CheckPassOverTimeSelector", async ({ page }) => {
await page.goto("/");
await expect(page.getByTestId("location-name")).toHaveText("Trondheim");
await expect(
page.getByTestId("location-dropdown-button"),
).toBeVisible();
await page.getByTestId("location-dropdown-button").click();
await expect(page.getByTestId("location-dropdown-list")).toHaveCount(1); // By default, only one location is available
await expect(page.getByTestId("latitude-input")).toBeVisible();
await expect(page.getByTestId("longitude-input")).toBeVisible();
await page.getByTestId("latitude-input").fill("1");
await page.getByTestId("longitude-input").fill("1");
await page.getByTestId("add-location-button").click();
await page
.getByTestId("location-dropdown-list")
.getByRole("option")
.nth(1)
.click();
await expect(page.getByTestId("location-name")).toHaveText(
"1.00° N, 1.00° E",
);
});
});

0 comments on commit f84d537

Please sign in to comment.