Skip to content

Commit

Permalink
Create map fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Nov 30, 2024
1 parent 8c2da94 commit 4e19d54
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion testing/e2e/fixtures/auth.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from "@playwright/test";

type Account = {
export type Account = {
eveId: number;
name: string;
};
Expand Down
3 changes: 2 additions & 1 deletion testing/e2e/fixtures/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mergeTests } from "@playwright/test";
import { authFixture } from "./auth.fixture";
import { mapFixture } from "./map/map.fixture";

export const test = mergeTests(authFixture);
export const test = mergeTests(authFixture, mapFixture);
10 changes: 10 additions & 0 deletions testing/e2e/fixtures/map/map.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { authFixture } from "../auth.fixture";
import { Map } from "./map";

export const mapFixture = authFixture.extend<{ map: Map }>({
map: async ({ page, account }, use) => {
const map = new Map(page, account);
await map.create();
await use(map);
},
});
31 changes: 31 additions & 0 deletions testing/e2e/fixtures/map/map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect, Page } from "@playwright/test";
import { Account } from "../auth.fixture";

export class Map {
constructor(
public readonly page: Page,
public readonly account: Account,
) {}

async create() {
const mapName = `E2E Map ${this.account.eveId}`;
await this.page.goto("/system/J104809");
await this.page.getByRole("button", { name: "Select active map" }).click();
await this.page.getByRole("menuitem", { name: "New Map" }).click();
await this.page.getByLabel("Name").fill(mapName);
await this.page.getByLabel("Root System").fill("J100001");
await this.page
.getByRole("option", { name: "J100001", exact: true })
.click();
await this.page.getByRole("button", { name: "Save" }).click();
await this.page.getByRole("menuitem", { name: mapName }).click();

await expect(
this.page.getByRole("button", { name: "Select active map" }),
).toContainText(mapName);
}

asd() {
// Dummy method for testing map fixture.
}
}
18 changes: 5 additions & 13 deletions testing/e2e/tests/example.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@ test("has title", async ({ page }) => {
await expect(page.getByText("Welcome to Holenav!")).toBeVisible();
});

test("Create map", async ({ page, account }) => {
const mapName = `E2E Map ${account.eveId}`;
await page.goto("/system/J104809");
await page.getByRole("button", { name: "Select active map" }).click();
await page.getByRole("menuitem", { name: "New Map" }).click();
await page.getByLabel("Name").fill(mapName);
await page.getByLabel("Root System").fill("J100001");
await page.getByRole("option", { name: "J100001", exact: true }).click();
await page.getByRole("button", { name: "Save" }).click();
await page.getByRole("menuitem", { name: mapName }).click();
test("Create map", async ({ map }) => {
map.asd();
});

await expect(
page.getByRole("button", { name: "Select active map" }),
).toContainText(mapName);
test("test if map fixture breaks", async ({ map }) => {
map.asd();
});

0 comments on commit 4e19d54

Please sign in to comment.