Skip to content

Commit ad852cd

Browse files
committed
4565: Fixed tests
1 parent 7279552 commit ad852cd

13 files changed

+110
-38
lines changed

assets/tests/admin/admin-campaign.spec.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import { test, expect } from "@playwright/test";
2-
import { loginTest } from "./admin-helper.js";
2+
import { abortUnhandledRoutes, loginTest } from "./admin-helper.js";
33
import { emptyJson, slidesJson1 } from "./data-fixtures.js";
44

55
test.describe("Campaign pages work", () => {
6+
test.beforeEach(async ({ page }) => {
7+
await abortUnhandledRoutes(page);
8+
});
9+
610
test.beforeEach(async ({ page }) => {
711
await loginTest({ page });
812

913
await page.route("**/playlists*", async (route) => {
1014
await route.fulfill({ json: emptyJson });
1115
});
16+
await page.route("**/screens*", async (route) => {
17+
await route.fulfill({ json: emptyJson });
18+
});
19+
await page.route("**/screen-groups*", async (route) => {
20+
await route.fulfill({ json: emptyJson });
21+
});
1222

1323
await page.locator(".sidebar-nav .nav-link").getByText("Kampagner").click();
1424
await expect(page.locator("h1").getByText("Kampagner")).toBeVisible();
@@ -53,7 +63,7 @@ test.describe("Campaign pages work", () => {
5363
).toHaveCount(6);
5464

5565
// Remove slide
56-
await page.locator(".remove-from-list").click({ force: false });
66+
await page.locator(".remove-from-list").click();
5767

5868
// See that slides section is removed.
5969
await expect(page.getByText("Afspilningsrækkefølge")).not.toBeVisible();

assets/tests/admin/admin-content-string.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { test, expect } from "@playwright/test";
22
import contentString from "../../admin/components/util/helpers/content-string.jsx";
3+
import { abortUnhandledRoutes } from "./admin-helper.js";
34

45
test.describe("Content string", () => {
6+
test.beforeEach(async ({ page }) => {
7+
await abortUnhandledRoutes(page);
8+
});
9+
510
test("It creates a string: 'test and test'", async ({ page }) => {
611
expect(contentString([{ name: "test" }, { name: "test" }], "and")).toBe(
712
"test and test",

assets/tests/admin/admin-feed-sources.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import {
55
feedSourcesJson2,
66
feedSourcesJson3,
77
} from "./data-fixtures.js";
8-
import { loginTest } from "./admin-helper.js";
8+
import { abortUnhandledRoutes, loginTest } from "./admin-helper.js";
99

1010
test.describe("feed sources", () => {
11+
test.beforeEach(async ({ page }) => {
12+
await abortUnhandledRoutes(page);
13+
});
14+
1115
test.beforeEach(async ({ page }) => {
1216
await loginTest({ page });
1317

assets/tests/admin/admin-helper.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import {
66
} from "./data-fixtures.js";
77
import { expect } from "@playwright/test";
88

9-
const loginTest = async ({ page }) => {
10-
await page.goto("/admin/slides/list");
11-
9+
const abortUnhandledRoutes = async(page) => {
1210
// Abort all routes that are not registered.
13-
await page.route("**/*", async (route) => {
11+
await page.route("*", async (route) => {
1412
await route.abort();
1513
});
14+
};
15+
16+
const loginTest = async ({ page }) => {
17+
await page.goto("/admin/slides/list");
1618

1719
await page.route("**/token", async (route) => {
1820
await route.fulfill({ json: tokenJson });
@@ -37,4 +39,4 @@ const loginTest = async ({ page }) => {
3739
await expect(page.locator("h1").getByText("Slides")).toBeVisible();
3840
};
3941

40-
export { loginTest };
42+
export { loginTest, abortUnhandledRoutes };

assets/tests/admin/admin-login.spec.js

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { test, expect } from "@playwright/test";
22
import { accessConfigJson, adminConfigJson, emptyJson } from "./data-fixtures.js";
3+
import { abortUnhandledRoutes } from "./admin-helper.js";
34

45
test.describe("Login works", () => {
6+
test.beforeEach(async ({ page }) => {
7+
await abortUnhandledRoutes(page);
8+
});
9+
510
test.beforeEach(async ({ page }) => {
611
await page.route("**/access-config.json", async (route) => {
712
await route.fulfill({ json: accessConfigJson });
813
});
914

10-
await page.route('**/config/admin', async (route) => {
15+
await page.route("**/config/admin", async (route) => {
1116
await route.fulfill({ json: adminConfigJson });
12-
})
17+
});
1318
});
1419

1520
test("Login one tenant works", async ({ page }) => {
@@ -111,33 +116,32 @@ test.describe("Login works", () => {
111116
);
112117
});
113118

114-
test("Role editor should not be able to visit restricted route", async ({
115-
page
116-
}) => {
117-
await page.goto("/admin/playlist/list");
118-
await page.route("**/token", async (route) => {
119-
const json = {
120-
token: "1",
121-
refresh_token: "2",
122-
tenants: [
123-
{
124-
tenantKey: "ABC",
125-
title: "ABC Tenant",
126-
description: "Description",
127-
roles: ["ROLE_EDITOR"]
119+
test("Role editor should not be able to visit restricted route",
120+
async ({ page }) => {
121+
await page.goto("/admin/playlist/list");
122+
await page.route("**/token", async (route) => {
123+
const json = {
124+
token: "1",
125+
refresh_token: "2",
126+
tenants: [
127+
{
128+
tenantKey: "ABC",
129+
title: "ABC Tenant",
130+
description: "Description",
131+
roles: ["ROLE_EDITOR"]
132+
}
133+
],
134+
user: {
135+
fullname: "John Doe",
136+
email: "johndoe@example.com"
128137
}
129-
],
130-
user: {
131-
fullname: "John Doe",
132-
email: "johndoe@example.com"
133-
}
134-
};
135-
await route.fulfill({ json });
138+
};
139+
await route.fulfill({ json });
140+
});
141+
await page.goto("/admin/shared/list");
142+
await page.locator("#login").click();
143+
await expect(page.locator("main").locator("div")).toHaveText(
144+
"Du har ikke adgang til denne side"
145+
);
136146
});
137-
await page.goto("/admin/shared/list");
138-
await page.locator("#login").click();
139-
await expect(page.locator("main").locator("div")).toHaveText(
140-
"Du har ikke adgang til denne side"
141-
);
142-
});
143147
});

assets/tests/admin/admin-media.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { test, expect } from "@playwright/test";
2+
import { abortUnhandledRoutes } from "./admin-helper.js";
23

34
test.describe("media list tests", () => {
5+
test.beforeEach(async ({ page }) => {
6+
await abortUnhandledRoutes(page);
7+
});
8+
49
test.beforeEach(async ({ page }) => {
510
await page.goto("/admin/media/list");
611
await page.route("**/media*", async (route) => {

assets/tests/admin/admin-playlist.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { test, expect } from "@playwright/test";
2+
import { abortUnhandledRoutes } from "./admin-helper.js";
23

34
test.describe("Playlist create tests", () => {
5+
test.beforeEach(async ({ page }) => {
6+
await abortUnhandledRoutes(page);
7+
});
8+
49
test.beforeEach(async ({ page }) => {
510
await page.goto("/admin/playlist/create");
611
await page.route("**/token", async (route) => {

assets/tests/admin/admin-screen-groups.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { test, expect } from "@playwright/test";
2+
import { abortUnhandledRoutes } from "./admin-helper.js";
23

34
test.describe("Create group page works", () => {
5+
test.beforeEach(async ({ page }) => {
6+
await abortUnhandledRoutes(page);
7+
});
8+
49
test.beforeEach(async ({ page }) => {
510
await page.goto("/admin/group/create");
611
await page.route("**/token", async (route) => {

assets/tests/admin/admin-screens.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { test, expect } from "@playwright/test";
2+
import { adminConfigJson } from "./data-fixtures.js";
3+
import { abortUnhandledRoutes } from "./admin-helper.js";
24

35
test.describe("Screen list tests", () => {
6+
test.beforeEach(async ({ page }) => {
7+
await abortUnhandledRoutes(page);
8+
});
9+
410
test("Test list", async ({ page }) => {
511
await page.goto("/admin/screen/list");
612
await page.route("**/token", async (route) => {
@@ -22,6 +28,7 @@ test.describe("Screen list tests", () => {
2228
};
2329
await route.fulfill({ json });
2430
});
31+
2532
await page.route("**/screens*", async (route) => {
2633
const json = {
2734
"@id": "/v2/screens",
@@ -73,6 +80,7 @@ test.describe("Screen list tests", () => {
7380
};
7481
await route.fulfill({ json });
7582
});
83+
7684
await page.route("**/campaigns*", async (route) => {
7785
await route.fulfill({
7886
json: {
@@ -81,6 +89,7 @@ test.describe("Screen list tests", () => {
8189
},
8290
});
8391
});
92+
8493
await page.route("**/screen-groups*", async (route) => {
8594
await route.fulfill({
8695
json: {
@@ -90,6 +99,10 @@ test.describe("Screen list tests", () => {
9099
});
91100
});
92101

102+
await page.route('**/config/admin', async (route) => {
103+
await route.fulfill({ json: adminConfigJson });
104+
})
105+
93106
await expect(page).toHaveTitle(/OS2Display Admin/);
94107
await page.getByLabel("Email").fill("johndoe@example.com");
95108
await page.getByLabel("Kodeord").fill("password");

assets/tests/admin/admin-shared-list.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { test, expect } from "@playwright/test";
2+
import { abortUnhandledRoutes } from "./admin-helper.js";
23

34
test.describe("Shared list tests", () => {
5+
test.beforeEach(async ({ page }) => {
6+
await abortUnhandledRoutes(page);
7+
});
8+
49
test.beforeEach(async ({ page }) => {
510
await page.goto("/admin/shared/list");
611
await page.route("**/token", async (route) => {

0 commit comments

Comments
 (0)