|
1 | 1 | import { test, expect } from "@playwright/test"; |
2 | 2 |
|
3 | | -test("News Feed 0", async ({ page }) => { |
4 | | - await page.goto("/template/news-feed-0"); |
| 3 | +test.describe("news-feed-0: ui tests", async () => { |
| 4 | + test.beforeEach(async ({ page }) => { |
| 5 | + await page.goto("/template/news-feed-0"); |
| 6 | + }); |
5 | 7 |
|
6 | | - // TODO |
| 8 | + test("Should render template with media", async ({ page }) => { |
| 9 | + const slide = page.locator(".slide"); |
| 10 | + await expect(slide).toBeVisible(); |
| 11 | + |
| 12 | + const backgroundImage = slide.locator(".media-section"); |
| 13 | + await expect(backgroundImage).toHaveCSS( |
| 14 | + "background-image", |
| 15 | + new RegExp("/fixtures/template/images/sunset-full-hd.jpg"), |
| 16 | + ); |
| 17 | + }); |
| 18 | + |
| 19 | + test("Should render template with title", async ({ page }) => { |
| 20 | + const slide = page.locator(".slide"); |
| 21 | + |
| 22 | + const title = slide.locator(".title"); |
| 23 | + await expect(title).toHaveText( |
| 24 | + "Aenean scelerisque ligula ante, sed tristique tellus?", |
| 25 | + ); |
| 26 | + }); |
| 27 | + |
| 28 | + test("Should render template with author", async ({ page }) => { |
| 29 | + const slide = page.locator(".slide"); |
| 30 | + |
| 31 | + const authorAndDate = slide.locator(".author"); |
| 32 | + await expect(authorAndDate).toHaveText("18. nov. 2024 ▪ Test Testesen"); |
| 33 | + }); |
| 34 | + |
| 35 | + test("Should render template with description", async ({ page }) => { |
| 36 | + const slide = page.locator(".slide"); |
| 37 | + const description = slide.locator(".description"); |
| 38 | + await expect(description).toContainText("Duis volutpat orci lectus"); |
| 39 | + }); |
| 40 | + |
| 41 | + test("Should render template with qr code", async ({ page }) => { |
| 42 | + const slide = page.locator(".slide"); |
| 43 | + |
| 44 | + const qrCode = slide.locator("img.qr"); |
| 45 | + await expect(qrCode).toBeVisible(); |
| 46 | + await expect(qrCode).toHaveAttribute("src", /data:image\/png;base64/); |
| 47 | + }); |
| 48 | + |
| 49 | + test("Should render template with read more link", async ({ page }) => { |
| 50 | + const slide = page.locator(".slide"); |
| 51 | + |
| 52 | + const readMore = slide.locator(".read-more"); |
| 53 | + await expect(readMore).toHaveText("Læs hele nyheden"); |
| 54 | + |
| 55 | + const link = slide.locator(".link"); |
| 56 | + await expect(link).toHaveText("https://example.com/news/1"); |
| 57 | + }); |
| 58 | + |
| 59 | + test("Should set media contain", async ({ page }) => { |
| 60 | + const mediaContain = page.locator(".media-contain"); |
| 61 | + await expect(mediaContain).toHaveCount(1); |
| 62 | + }); |
| 63 | + test("Should render template with media (after 2100 seconds", async ({ |
| 64 | + page, |
| 65 | + }) => { |
| 66 | + await page.waitForTimeout(2100); |
| 67 | + const slide = page.locator(".slide"); |
| 68 | + await expect(slide).toBeVisible(); |
| 69 | + |
| 70 | + const backgroundImage = slide.locator(".media-section"); |
| 71 | + await expect(backgroundImage).toHaveCSS( |
| 72 | + "background-image", |
| 73 | + new RegExp("/fixtures/template/images/mountain4.jpeg"), |
| 74 | + ); |
| 75 | + }); |
| 76 | + |
| 77 | + test("Should render template with title (after 2100 seconds", async ({ |
| 78 | + page, |
| 79 | + }) => { |
| 80 | + await page.waitForTimeout(2100); |
| 81 | + const slide = page.locator(".slide"); |
| 82 | + |
| 83 | + const title = slide.locator(".title"); |
| 84 | + await expect(title).toHaveText("Duis volutpat orci lectus."); |
| 85 | + }); |
| 86 | + |
| 87 | + test("Should render template with author (after 2100 seconds", async ({ |
| 88 | + page, |
| 89 | + }) => { |
| 90 | + await page.waitForTimeout(2100); |
| 91 | + const slide = page.locator(".slide"); |
| 92 | + |
| 93 | + const authorAndDate = slide.locator(".author"); |
| 94 | + await expect(authorAndDate).toHaveText( |
| 95 | + "18. nov. 2024 ▪ Aenean Scelerisque", |
| 96 | + ); |
| 97 | + }); |
| 98 | + |
| 99 | + test("Should render template with description (after 2100 seconds", async ({ |
| 100 | + page, |
| 101 | + }) => { |
| 102 | + await page.waitForTimeout(2100); |
| 103 | + const slide = page.locator(".slide"); |
| 104 | + const description = slide.locator(".description"); |
| 105 | + await expect(description).toContainText("Summary2"); |
| 106 | + }); |
| 107 | + |
| 108 | + test("Should render template with qr code (after 2100 seconds", async ({ |
| 109 | + page, |
| 110 | + }) => { |
| 111 | + await page.waitForTimeout(2100); |
| 112 | + const slide = page.locator(".slide"); |
| 113 | + |
| 114 | + const qrCode = slide.locator("img.qr"); |
| 115 | + await expect(qrCode).toBeVisible(); |
| 116 | + await expect(qrCode).toHaveAttribute("src", /data:image\/png;base64/); |
| 117 | + }); |
| 118 | + |
| 119 | + test("Should render template with read more link (after 2100 seconds", async ({ |
| 120 | + page, |
| 121 | + }) => { |
| 122 | + await page.waitForTimeout(2100); |
| 123 | + const slide = page.locator(".slide"); |
| 124 | + |
| 125 | + const readMore = slide.locator(".read-more"); |
| 126 | + await expect(readMore).toHaveText("Læs hele nyheden"); |
| 127 | + |
| 128 | + const link = slide.locator(".link"); |
| 129 | + await expect(link).toHaveText("https://example.com/news/2"); |
| 130 | + }); |
| 131 | + |
| 132 | + test("Should set media contain (after 2100 seconds", async ({ page }) => { |
| 133 | + await page.waitForTimeout(2100); |
| 134 | + const mediaContain = page.locator(".media-contain"); |
| 135 | + await expect(mediaContain).toHaveCount(1); |
| 136 | + }); |
| 137 | + |
| 138 | + test("Should use fallbackImage (after 4100 seconds", async ({ page }) => { |
| 139 | + await page.waitForTimeout(4100); |
| 140 | + const slide = page.locator(".slide"); |
| 141 | + await expect(slide).toBeVisible(); |
| 142 | + |
| 143 | + const backgroundImage = slide.locator(".media-section"); |
| 144 | + await expect(backgroundImage).toHaveCSS( |
| 145 | + "background-image", |
| 146 | + new RegExp("/fixtures/template/images/mountain1.jpeg"), |
| 147 | + ); |
| 148 | + }); |
| 149 | +}); |
| 150 | + |
| 151 | +test.describe("news-feed-no-media-contain: ui tests", async () => { |
| 152 | + test.beforeEach(async ({ page }) => { |
| 153 | + await page.goto("/template/news-feed-no-media-contain"); |
| 154 | + }); |
| 155 | + |
| 156 | + test("Should not set media contain", async ({ page }) => { |
| 157 | + const mediaContain = page.locator(".media-contain"); |
| 158 | + await expect(mediaContain).toHaveCount(0); |
| 159 | + }); |
| 160 | + |
| 161 | + test("Should render template with alternative read more link (after 2100 seconds", async ({ |
| 162 | + page, |
| 163 | + }) => { |
| 164 | + await page.waitForTimeout(2100); |
| 165 | + const slide = page.locator(".slide"); |
| 166 | + |
| 167 | + const readMore = slide.locator(".read-more"); |
| 168 | + await expect(readMore).toHaveText("Read more text"); |
| 169 | + |
| 170 | + const link = slide.locator(".link"); |
| 171 | + await expect(link).toHaveText("https://example.com/news/3"); |
| 172 | + }); |
7 | 173 | }); |
0 commit comments