Skip to content

Commit 5e19d05

Browse files
authored
Merge pull request #318 from os2display/feature/5453-tests-of-hook
Tests of hook
2 parents 0e21382 + 8a0850e commit 5e19d05

6 files changed

Lines changed: 215 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file.
2222
- Aligned with v. 2.5.2.
2323
- Removed themes.
2424
- Added command to migrate config.json files.
25-
- Fix data fetching bug.
25+
- Fix data fetching bug + tests
2626
- Refactored screen layout commands.
2727
- Moved list components (search and checkboxes) around.
2828
- Replaced lodash functions with native ones.

assets/admin/components/slide/slide-form.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ function SlideForm({
298298
</ContentBody>
299299
</>
300300
)}
301-
<ContentBody>
301+
<ContentBody id="add-slide-to-playlist-section">
302302
<h2 className="h4">{t("add-slide-to-playlists")}</h2>
303303
<SelectPlaylistsTable
304304
helpText={t("add-playlists-help-text")}

assets/admin/components/util/content-body/content-body.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @param {boolean} props.highlightSection Highlight this section.
66
* @returns {object} The Content header.
77
*/
8-
function ContentBody({ children, id = "", highlightSection = false }) {
8+
function ContentBody({ id = "", highlightSection = false, children }) {
99
const classes = `shadow-sm p-3 mb-3 bg-body rounded ${
1010
highlightSection ? "border border-warning" : ""
1111
}`;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { test, expect } from "@playwright/test";
2+
import {
3+
fulfillDataRoute,
4+
fulfillEmptyRoutes,
5+
beforeEachTest,
6+
loginTest,
7+
} from "./test-helper.js";
8+
import {
9+
imageTextTemplate,
10+
onlyImageTextListJson,
11+
slidesJson1,
12+
slideJson,
13+
slidesPlaylist,
14+
} from "./data-fixtures.js";
15+
16+
test.describe("Test of admin fetch data hook", () => {
17+
test.beforeEach(async ({ page }) => {
18+
await beforeEachTest(page);
19+
});
20+
21+
test.beforeEach(async ({ page }) => {
22+
page.setViewportSize({ width: 600, height: 2600 });
23+
await fulfillDataRoute(
24+
page,
25+
"**/templates?itemsPerPage*",
26+
onlyImageTextListJson,
27+
);
28+
29+
await page.route(
30+
"**/templates/000YR9PMQC0GMC1TP90V9N07WX",
31+
async (route) => {
32+
await route.fulfill(imageTextTemplate);
33+
},
34+
);
35+
36+
await fulfillDataRoute(
37+
page,
38+
"**/templates/01FGC8EXSE1KCC1PTR0NHB0H3R",
39+
imageTextTemplate,
40+
);
41+
42+
await fulfillDataRoute(
43+
page,
44+
"**/templates/002BAP34VD1EHG0E4J0D2Y00JW",
45+
imageTextTemplate,
46+
);
47+
48+
await fulfillDataRoute(
49+
page,
50+
"**/templates/017BG9P0E0103F0TFS17FM016M",
51+
imageTextTemplate,
52+
);
53+
54+
await fulfillDataRoute(
55+
page,
56+
"**/templates/016MHSNKCH1PQW1VY615JC19Y3",
57+
imageTextTemplate,
58+
);
59+
await fulfillDataRoute(
60+
page,
61+
"**/templates/000BGWFMBS15N807E60HP91JCX",
62+
imageTextTemplate,
63+
);
64+
65+
await loginTest(page, slidesJson1);
66+
67+
await fulfillDataRoute(
68+
page,
69+
"**/templates/01FP2SNGFN0BZQH03KCBXHKYHG",
70+
imageTextTemplate,
71+
);
72+
73+
await fulfillDataRoute(
74+
page,
75+
"**/v2/slides/00015Y0ZVC18N407JD07SM0YCF",
76+
slideJson,
77+
);
78+
79+
await fulfillEmptyRoutes(page, ["**/playlists*", "**/themes*"]);
80+
await fulfillDataRoute(
81+
page,
82+
"**/slides/00015Y0ZVC18N407JD07SM0YCF/playlists?*",
83+
slidesPlaylist,
84+
);
85+
86+
await Promise.all([
87+
page.waitForURL("**/slide/edit/*"),
88+
await page.locator("#edit_button").first().click({ force: true }),
89+
]);
90+
91+
const title = page.getByText("Rediger slide:");
92+
await title.waitFor();
93+
94+
await expect(title).toBeVisible();
95+
});
96+
97+
test("Test of admin fetch data hook", async ({ page }) => {
98+
const title = page.locator("#add-slide-to-playlist-section tr");
99+
// The max items per page is 30: https://github.com/os2display/display-api-service/blob/develop/config/packages/api_platform.yaml#L11
100+
// And the header is also a <tr
101+
await expect(title).toHaveCount(32);
102+
});
103+
});

assets/tests/admin/data-fixtures.js

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,80 @@ const clientConfigJson = {
410410
logging: false,
411411
};
412412

413+
const members = [];
414+
Array.from(Array(31).keys()).forEach((i) => {
415+
members.push({
416+
"@id": "/v2/playlist-slides/01JX8KAN3R1D201EJC06AF099N",
417+
"@type": "PlaylistSlide",
418+
slide: {
419+
"@id": "/v2/slides/00015Y0ZVC18N407JD07SM0YCF",
420+
"@type": "Slide",
421+
},
422+
playlist: {
423+
"@id": "/v2/playlists/01JQHJV7101JG70V6G0E9313PV",
424+
"@type": "Playlist",
425+
title: "1",
426+
description:
427+
"Similique voluptas aut temporibus soluta et cupiditate dolore. Ut ut totam fuga. Ullam quis ut nulla et totam neque quia.",
428+
schedules: [],
429+
slides: "/v2/playlists/01JQHJV7101JG70V6G0E9313PV/slides",
430+
campaignScreens: [],
431+
campaignScreenGroups: [],
432+
tenants: [
433+
{
434+
"@type": "Tenant",
435+
"@id": "/v2/tenants/01JDHRTN7R0JWK1KYN12WC16QX",
436+
},
437+
],
438+
isCampaign: false,
439+
published: {
440+
from: "2024-09-27T13:08:20.000Z",
441+
to: "2025-05-26T09:48:41.000Z",
442+
},
443+
relationsChecksum: {
444+
slides: "a392e0ee600c545e5604713161f14bac7460471f",
445+
},
446+
},
447+
weight: { i },
448+
});
449+
});
450+
451+
const slidesPlaylist = {
452+
"@context": "/contexts/PlaylistSlide",
453+
"@id": "/v2/slides/01JVA5509R1V8S16PR15BB1Q4D/playlists",
454+
"hydra:totalItems": 31,
455+
"hydra:member": members,
456+
};
457+
458+
const slideJson = {
459+
"@context": "/contexts/Slide",
460+
"@id": "/v2/slides/00015Y0ZVC18N407JD07SM0YCF",
461+
"@type": "Slide",
462+
title: "",
463+
description: "",
464+
templateInfo: {
465+
"@id": "/v2/templates/01FP2SNGFN0BZQH03KCBXHKYHG",
466+
options: [],
467+
},
468+
onPlaylists: [],
469+
published: {
470+
from: "2025-09-18T09:30:00.000Z",
471+
to: null,
472+
},
473+
media: [],
474+
content: {
475+
title: "Title",
476+
},
477+
modifiedBy: "admin@example.com",
478+
createdBy: "admin@example.com",
479+
id: "01K5E2JGX3G60S73YRGR26W81J",
480+
created: "2025-09-18T11:30:32.000Z",
481+
modified: "2025-09-18T11:33:13.000Z",
482+
relationsChecksum: {
483+
templateInfo: "b2341f464f952dcd78c26990075ab5090af1286c",
484+
},
485+
};
486+
413487
const slidesJson1 = {
414488
"@id": "/v2/slides",
415489
"hydra:member": [
@@ -986,6 +1060,25 @@ const screensListJson = {
9861060
],
9871061
};
9881062

1063+
const onlyImageTextListJson = {
1064+
"@context": "/contexts/Template",
1065+
"@id": "/v2/templates",
1066+
"@type": "hydra:Collection",
1067+
"hydra:totalItems": 1,
1068+
"hydra:member": [
1069+
{
1070+
"@id": "/v2/templates/01FP2SNGFN0BZQH03KCBXHKYHG",
1071+
"@type": "Template",
1072+
title: "Billede og tekst",
1073+
modifiedBy: "",
1074+
createdBy: "",
1075+
id: "01FP2SNGFN0BZQH03KCBXHKYHG",
1076+
created: "2024-08-03T09:38:27.000Z",
1077+
modified: "2025-02-01T06:08:28.000Z",
1078+
},
1079+
],
1080+
};
1081+
9891082
const templatesListJson = {
9901083
"@id": "/v2/templates",
9911084
"hydra:member": [
@@ -1076,6 +1169,15 @@ const templatesListJson = {
10761169
"hydra:totalItems": 12,
10771170
};
10781171

1172+
const imageTextTemplate = {
1173+
title: "Billede og tekst",
1174+
modifiedBy: "",
1175+
createdBy: "",
1176+
id: "01FP2SNGFN0BZQH03KCBXHKYHG",
1177+
created: "2024-08-04T06:32:42.000Z",
1178+
modified: "2025-02-02T03:02:43.000Z",
1179+
};
1180+
10791181
const slidesListJson = {
10801182
"@id": "/v2/slides",
10811183
"hydra:member": [
@@ -1089,7 +1191,7 @@ const slidesListJson = {
10891191
modifiedBy: "",
10901192
createdBy: "",
10911193
templateInfo: {
1092-
"@id": "/v2/templates/00MWCNKC4P0X5C0AT70E741E2V",
1194+
"@id": "/v2/templates/01FP2SNGFN0BZQH03KCBXHKYHG",
10931195
options: [],
10941196
},
10951197
theme: "",
@@ -1645,4 +1747,8 @@ export {
16451747
slidesListJson,
16461748
themesJson,
16471749
themesSingleJson,
1750+
onlyImageTextListJson,
1751+
slideJson,
1752+
imageTextTemplate,
1753+
slidesPlaylist,
16481754
};

assets/tests/admin/test-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ const fulfillDataRoute = async (page, routePattern, data, status) => {
3333
});
3434
};
3535

36-
const loginTest = async (page) => {
36+
const loginTest = async (page, slides = null) => {
3737
await page.goto("/admin/slides/list");
3838

3939
await page.route("**/token", async (route) => {
4040
await route.fulfill({ json: tokenAdminJson });
4141
});
4242

4343
await page.route("**/slides*", async (route) => {
44-
await route.fulfill({ json: emptyJson });
44+
await route.fulfill({ json: slides ?? emptyJson });
4545
});
4646

4747
await expect(page).toHaveTitle(/OS2Display Admin/);

0 commit comments

Comments
 (0)