Skip to content

Commit 9cf6d76

Browse files
committed
4565: Worked on test refactor
1 parent ad852cd commit 9cf6d76

18 files changed

+283
-313
lines changed

assets/admin/admin-config-loader.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ const AdminConfigLoader = {
2222
resolve(configData);
2323
} else {
2424
// eslint-disable-next-line no-console
25-
console.error(
26-
"Could not load config. Will use default config."
27-
);
25+
console.error("Could not load config. Will use default config.");
2826

2927
// Default config.
3028
resolve({

assets/client/client-config-loader.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Only fetch new config if more than 15 minutes have passed.
2-
import appStorage from './util/app-storage';
2+
import appStorage from "./util/app-storage";
33

44
const configFetchIntervalDefault = 15 * 60 * 1000;
55

@@ -22,7 +22,7 @@ const ClientConfigLoader = {
2222

2323
if (
2424
latestFetchTimestamp +
25-
(configData?.configFetchInterval ?? configFetchIntervalDefault) >=
25+
(configData?.configFetchInterval ?? configFetchIntervalDefault) >=
2626
nowTimestamp
2727
) {
2828
resolve(configData);
@@ -43,15 +43,13 @@ const ClientConfigLoader = {
4343
resolve(configData);
4444
} else {
4545
// eslint-disable-next-line no-console
46-
console.error(
47-
'Could not load config. Will use default config.'
48-
);
46+
console.error("Could not load config. Will use default config.");
4947

5048
// Default config.
5149
resolve({
52-
apiEndpoint: '/api',
50+
apiEndpoint: "/api",
5351
dataStrategy: {
54-
type: 'pull',
52+
type: "pull",
5553
config: {
5654
interval: 30000,
5755
},
@@ -61,7 +59,7 @@ const ClientConfigLoader = {
6159
refreshTokenTimeout: 15000,
6260
releaseTimestampIntervalTimeout: 600000,
6361
colorScheme: {
64-
type: 'library',
62+
type: "library",
6563
lat: 56.0,
6664
lng: 10.0,
6765
},

assets/client/service/release-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ReleaseService {
7474
this.releaseCheckInterval = setInterval(
7575
this.checkForNewRelease,
7676
config.releaseTimestampIntervalTimeout ??
77-
defaults.releaseTimestampIntervalTimeoutDefault,
77+
defaults.releaseTimestampIntervalTimeoutDefault,
7878
);
7979
});
8080
};

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

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

55
test.describe("Campaign pages work", () => {
66
test.beforeEach(async ({ page }) => {
7-
await abortUnhandledRoutes(page);
7+
await beforeEachTest(page);
88
});
99

1010
test.beforeEach(async ({ page }) => {
1111
await loginTest({ page });
1212

13-
await page.route("**/playlists*", async (route) => {
14-
await route.fulfill({ json: emptyJson });
15-
});
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-
});
13+
await awaitEmptyRoutes(page, ["**/playlists*", "**/screens*", "**/screen-groups*"]);
2214

2315
await page.locator(".sidebar-nav .nav-link").getByText("Kampagner").click();
2416
await expect(page.locator("h1").getByText("Kampagner")).toBeVisible();
@@ -33,9 +25,7 @@ test.describe("Campaign pages work", () => {
3325

3426
test("It removes slide", async ({ page }) => {
3527
// Intercept slides in dropdown
36-
await page.route("**/slides*", async (route) => {
37-
await route.fulfill({ json: slidesJson1 });
38-
});
28+
await awaitDataRoute(page, "**/slides*", slidesJson1);
3929

4030
// Pick slide
4131
await page

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
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";
43

54
test.describe("Content string", () => {
6-
test.beforeEach(async ({ page }) => {
7-
await abortUnhandledRoutes(page);
8-
});
9-
105
test("It creates a string: 'test and test'", async ({ page }) => {
116
expect(contentString([{ name: "test" }, { name: "test" }], "and")).toBe(
127
"test and test",

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,39 @@ import {
33
errorJson,
44
feedSourcesJson,
55
feedSourcesJson2,
6-
feedSourcesJson3,
6+
feedSourceSingleJson
77
} from "./data-fixtures.js";
8-
import { abortUnhandledRoutes, loginTest } from "./admin-helper.js";
8+
import { awaitDataRoute, awaitEmptyRoutes, beforeEachTest, loginTest } from "./test-helper.js";
99

1010
test.describe("feed sources", () => {
1111
test.beforeEach(async ({ page }) => {
12-
await abortUnhandledRoutes(page);
12+
await beforeEachTest(page);
1313
});
1414

1515
test.beforeEach(async ({ page }) => {
1616
await loginTest({ page });
1717

18-
await page.route("**/feed-sources*", async (route) => {
19-
await route.fulfill({ json: feedSourcesJson });
20-
});
18+
await awaitDataRoute(page, "**/feed-sources*", feedSourcesJson);
19+
20+
await page
21+
.locator(".sidebar-nav .nav-link")
22+
.getByText("Datakilder")
23+
.click();
24+
25+
await awaitEmptyRoutes(page, ["**/slides*"]);
2126

22-
await page.locator(".sidebar-nav .nav-link").getByText("Datakilder").click();
2327
await expect(page.locator("h1").getByText("Datakilder")).toBeVisible();
2428
});
2529

2630
test("It loads create datakilde page", async ({ page }) => {
27-
page.getByText("Opret ny datakilde").click();
31+
await page.getByText("Opret ny datakilde").click();
2832
await expect(page.locator("#save")).toBeVisible();
2933
});
3034

3135
test("It display error toast on save error", async ({ page }) => {
32-
await page.route("**/feed-sources", async (route) => {
33-
await route.fulfill({ status: 500, json: errorJson });
34-
});
35-
page.getByText("Opret ny datakilde").click();
36+
await awaitDataRoute(page, "**/feed-sources*", errorJson, 500);
37+
38+
await page.getByText("Opret ny datakilde").click();
3639

3740
// Displays error toast and stays on page
3841
await expect(
@@ -53,7 +56,8 @@ test.describe("feed sources", () => {
5356
});
5457

5558
test("Cancel create datakilde", async ({ page }) => {
56-
page.getByText("Opret ny datakilde").click();
59+
await page.getByText("Opret ny datakilde").click();
60+
5761
await expect(page.locator("#cancel")).toBeVisible();
5862
await page.locator("#cancel").click();
5963
await expect(page.locator("#cancel")).not.toBeVisible();
@@ -67,13 +71,8 @@ test.describe("feed sources", () => {
6771
test("It goes to edit", async ({ page }) => {
6872
await expect(page.locator("#feed-sourceTitle")).not.toBeVisible();
6973

70-
await page.route("**/feed-sources*", async (route) => {
71-
await route.fulfill({ json: feedSourcesJson2 });
72-
});
73-
74-
await page.route("**/feed-sources/*", async (route) => {
75-
await route.fulfill({ json: feedSourcesJson3 });
76-
});
74+
await awaitDataRoute(page, "**/feed-sources*", feedSourcesJson2);
75+
await awaitDataRoute(page, "**/feed-sources/01JBBP48CS9CV80XRWRP8CAETJ", feedSourceSingleJson);
7776

7877
await page.locator("tbody").locator("tr td a").first().click();
7978
await expect(page.locator("#feed-sourceTitle")).toBeVisible();

assets/tests/admin/admin-helper.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)