|
1 | 1 | import { test, expect } from "@playwright/test"; |
2 | 2 |
|
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"); |
5 | 5 |
|
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 | + }); |
7 | 148 | }); |
0 commit comments