Skip to content

Commit ee4e850

Browse files
authored
Merge pull request #295 from os2display/feature/5317-contacts-tests
Add contacts test
2 parents 0061bed + 6d407e2 commit ee4e850

File tree

2 files changed

+199
-29
lines changed

2 files changed

+199
-29
lines changed

assets/template/fixtures/slide-fixtures.js

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ const slideFixtures = [
664664
},
665665
},
666666
{
667-
id: "contacts-0",
667+
id: "contacts-underlined",
668668
templateData: {
669669
id: "01FPZ19YEHX7MQ5Q6ZS0WK0VEA",
670670
},
@@ -677,12 +677,12 @@ const slideFixtures = [
677677
},
678678
"/v1/media/00000000000000000000000002": {
679679
assets: {
680-
uri: "/fixtures/template/images/author.jpg",
680+
uri: "/fixtures/template/images/logo.png",
681681
},
682682
},
683683
"/v1/media/00000000000000000000000003": {
684684
assets: {
685-
uri: "/fixtures/template/images/author.jpg",
685+
uri: "/fixtures/template/images/mountain1.jpeg",
686686
},
687687
},
688688
},
@@ -691,51 +691,80 @@ const slideFixtures = [
691691
duration: 5000,
692692
contacts: [
693693
{
694-
title: "Pedel",
695-
name: "John Michael Dorian",
696-
phone: "12341234",
697-
694+
title: "Chief of Medicine",
695+
name: "Bob Kelso",
696+
phone: "55510001",
697+
email: "kelso@@hospital.com",
698698
id: "uniqueContact1",
699699
image: ["/v1/media/00000000000000000000000001"],
700700
},
701701
{
702-
title: "Forstander",
703-
name: "Janitor",
704-
image: ["/v1/media/00000000000000000000000002"],
705-
phone: "12341234",
706-
702+
title: "Custodial Engineer",
703+
name: "The Janitor",
704+
phone: "55510002",
705+
email: "janitor@@hospital.com",
707706
id: "uniqueContact2",
707+
image: ["/v1/media/00000000000000000000000002"],
708708
},
709709
{
710-
title: "Lady",
711-
name: "Dr. Cox",
712-
phone: "12341234",
713-
image: ["/v1/media/00000000000000000000000003"],
714-
710+
title: "Resident Doctor",
711+
name: "Elliot Reid",
712+
phone: "55510003",
713+
email: "ereid@@hospital.com",
715714
id: "uniqueContact3",
715+
image: ["/v1/media/00000000000000000000000003"],
716716
},
717717
{
718-
name: "Dr. Cox",
719-
phone: "12341234",
720-
718+
name: "Christopher Turk",
719+
phone: "55510004",
720+
721721
id: "uniqueContact4",
722722
},
723723
{
724-
name: "Dr. Cox",
725-
phone: "12341234",
726-
724+
name: "Carla Espinosa",
725+
phone: "55510005",
726+
727727
id: "uniqueContact5",
728728
},
729729
{
730-
name: "Dr. Cox",
731-
phone: "12341234",
732-
730+
name: "Ted Buckland",
731+
phone: "55510006",
732+
email: "ted@@hospital.com",
733733
id: "uniqueContact6",
734734
},
735735
],
736736
separator: true,
737737
},
738738
},
739+
{
740+
id: "contacts-not-underlined",
741+
templateData: {
742+
id: "01FPZ19YEHX7MQ5Q6ZS0WK0VEA",
743+
},
744+
themeFile: null,
745+
mediaData: {
746+
"/v1/media/00000000000000000000000001": {
747+
assets: {
748+
uri: "/fixtures/template/images/author.jpg",
749+
},
750+
},
751+
"/v1/media/00000000000000000000000002": {
752+
assets: {
753+
uri: "/fixtures/template/images/author.jpg",
754+
},
755+
},
756+
"/v1/media/00000000000000000000000003": {
757+
assets: {
758+
uri: "/fixtures/template/images/author.jpg",
759+
},
760+
},
761+
},
762+
content: {
763+
mediaContain: false,
764+
duration: 5000,
765+
separator: false,
766+
},
767+
},
739768
{
740769
id: "iframe-0",
741770
templateData: {
Lines changed: 144 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,148 @@
11
import { test, expect } from "@playwright/test";
22

3-
test("Contacts 0", async ({ page }) => {
4-
await page.goto("/template/contacts-0");
3+
test("contacts-not-underlined - ui test", async ({ page }) => {
4+
await page.goto("/template/contacts-not-underlined");
55

6-
// TODO
6+
const header = page.locator("h1");
7+
await expect(header).toHaveText("Kontakter");
8+
9+
const separator = page.locator(".separator");
10+
await expect(separator).not.toBeVisible();
11+
});
12+
13+
test.describe("contacts-underlined - ui test", async () => {
14+
test.beforeEach(async ({ page }) => {
15+
await page.goto("/template/contacts-underlined");
16+
});
17+
18+
test("Should display separator", async ({ page }) => {
19+
const separator = page.locator(".separator");
20+
await expect(separator).toBeVisible();
21+
});
22+
23+
test("Should display the correct header", async ({ page }) => {
24+
const header = await page.locator("header h1");
25+
await expect(header).toHaveText(/Kontakter/);
26+
});
27+
28+
test("Should render exactly 6 contacts", async ({ page }) => {
29+
const contacts = await page.locator(".contact");
30+
await expect(contacts).toHaveCount(6);
31+
});
32+
33+
test("Should render the first contact with correct name and title", async ({
34+
page,
35+
}) => {
36+
const firstContact = page.locator(".contact").nth(0);
37+
await expect(firstContact.locator(".contact-text div").nth(0)).toHaveText(
38+
"Chief of Medicine",
39+
);
40+
await expect(firstContact.locator(".contact-text div").nth(1)).toHaveText(
41+
"Bob Kelso",
42+
);
43+
await expect(firstContact.locator(".contact-text div").nth(2)).toHaveText(
44+
"kelso@@hospital.com",
45+
);
46+
await expect(firstContact.locator(".contact-text div").nth(3)).toHaveText(
47+
"55510001",
48+
);
49+
await expect(firstContact.locator(".contact-image")).toHaveCSS(
50+
"background-image",
51+
new RegExp("/fixtures/template/images/author.jpg"),
52+
);
53+
});
54+
55+
test("Should render the second contact with correct name and title", async ({
56+
page,
57+
}) => {
58+
const secondContact = page.locator(".contact").nth(1);
59+
await expect(secondContact.locator(".contact-text div").nth(0)).toHaveText(
60+
"Custodial Engineer",
61+
);
62+
await expect(secondContact.locator(".contact-text div").nth(1)).toHaveText(
63+
"The Janitor",
64+
);
65+
await expect(secondContact.locator(".contact-text div").nth(2)).toHaveText(
66+
"janitor@@hospital.com",
67+
);
68+
await expect(secondContact.locator(".contact-text div").nth(3)).toHaveText(
69+
"55510002",
70+
);
71+
await expect(secondContact.locator(".contact-image")).toHaveCSS(
72+
"background-image",
73+
new RegExp("/fixtures/template/images/logo.png"),
74+
);
75+
});
76+
77+
test("Should render the third contact with correct name and title", async ({
78+
page,
79+
}) => {
80+
const thirdContact = page.locator(".contact").nth(2);
81+
await expect(thirdContact.locator(".contact-text div").nth(0)).toHaveText(
82+
"Resident Doctor",
83+
);
84+
await expect(thirdContact.locator(".contact-text div").nth(1)).toHaveText(
85+
"Elliot Reid",
86+
);
87+
await expect(thirdContact.locator(".contact-text div").nth(2)).toHaveText(
88+
"ereid@@hospital.com",
89+
);
90+
await expect(thirdContact.locator(".contact-text div").nth(3)).toHaveText(
91+
"55510003",
92+
);
93+
await expect(thirdContact.locator(".contact-image")).toHaveCSS(
94+
"background-image",
95+
new RegExp("/fixtures/template/images/mountain1.jpeg"),
96+
);
97+
});
98+
99+
test("Should render the fourth contact with correct name and title", async ({
100+
page,
101+
}) => {
102+
const fourthContact = page.locator(".contact").nth(3);
103+
await expect(fourthContact.locator(".contact-text div").nth(0)).toHaveText(
104+
"",
105+
);
106+
await expect(fourthContact.locator(".contact-text div").nth(1)).toHaveText(
107+
"Christopher Turk",
108+
);
109+
await expect(fourthContact.locator(".contact-text div").nth(2)).toHaveText(
110+
111+
);
112+
await expect(fourthContact.locator(".contact-text div").nth(3)).toHaveText(
113+
"55510004",
114+
);
115+
await expect(fourthContact.locator(".contact-image")).toHaveCSS(
116+
"background-image",
117+
"none",
118+
);
119+
});
120+
121+
test("Should render image as background image for first three contacts", async ({
122+
page,
123+
}) => {
124+
for (let i = 0; i < 3; i++) {
125+
const imageDiv = page
126+
.locator(".contact")
127+
.nth(i)
128+
.locator(".contact-image");
129+
const bgImage = await imageDiv.evaluate(
130+
(el) => getComputedStyle(el).backgroundImage,
131+
);
132+
expect(bgImage).toContain("/fixtures/template/images/");
133+
}
134+
});
135+
136+
test("Should set media-contain class", async ({ page }) => {
137+
expect(page.locator(".media-contain")).toHaveCount(3);
138+
});
139+
140+
test("Should render last 3 contacts with SVG instead of background image", async ({
141+
page,
142+
}) => {
143+
for (let i = 3; i < 6; i++) {
144+
const svg = page.locator(".contact").nth(i).locator("svg");
145+
await expect(svg).toBeVisible();
146+
}
147+
});
7148
});

0 commit comments

Comments
 (0)