|
| 1 | +import { chromium } from "playwright"; |
| 2 | +import { setTimeout } from "timers/promises"; |
| 3 | +import { test } from "uvu"; |
| 4 | +import * as assert from "uvu/assert"; |
| 5 | + |
| 6 | +let browser; |
| 7 | +let context; |
| 8 | +let page; |
| 9 | + |
| 10 | +test.before(async () => { |
| 11 | + browser = await chromium.launch({ |
| 12 | + use: { timezoneId: "Etc/UTC" }, |
| 13 | + }); |
| 14 | + context = await browser.newContext(); |
| 15 | +}); |
| 16 | + |
| 17 | +test.before.each(async () => { |
| 18 | + page = await context.newPage(); |
| 19 | +}); |
| 20 | + |
| 21 | +test.after.each(async () => { |
| 22 | + await page.close(); |
| 23 | +}); |
| 24 | + |
| 25 | +test.after(async () => { |
| 26 | + await browser.close(); |
| 27 | + await context.close(); |
| 28 | +}); |
| 29 | + |
| 30 | +test("Solved Issue #1: Company Names are Present", async () => { |
| 31 | + await page.goto("http://localhost:8080"); |
| 32 | + await setTimeout(250); |
| 33 | + |
| 34 | + var text = await page.$eval("body > table > tbody > tr:nth-child(2) > td:nth-child(1)", (el) => el.textContent); |
| 35 | + assert.type(text, "string"); |
| 36 | + assert.is(text, "Fusion LLC"); |
| 37 | + |
| 38 | + var text = await page.$eval("body > table > tbody > tr:nth-child(3) > td:nth-child(1)", (el) => el.textContent); |
| 39 | + assert.type(text, "string"); |
| 40 | + assert.is(text, "Techopolis Ltd."); |
| 41 | + |
| 42 | + var text = await page.$eval("body > table > tbody > tr:nth-child(4) > td:nth-child(1)", (el) => el.textContent); |
| 43 | + assert.type(text, "string"); |
| 44 | + assert.is(text, "Code learning LLC"); |
| 45 | +}); |
| 46 | + |
| 47 | +test("Solved Issue #2: display dates in 24-hour time format", async () => { |
| 48 | + await page.goto("http://localhost:8080"); |
| 49 | + await setTimeout(250); |
| 50 | + |
| 51 | + var text = await page.$eval("body > table > tbody > tr:nth-child(2) > td:nth-child(3)", (el) => el.textContent); |
| 52 | + assert.type(text, "string"); |
| 53 | + assert.is(text, "03:41"); |
| 54 | + |
| 55 | + var text = await page.$eval("body > table > tbody > tr:nth-child(3) > td:nth-child(3)", (el) => el.textContent); |
| 56 | + assert.type(text, "string"); |
| 57 | + assert.is(text, "08:45"); |
| 58 | + |
| 59 | + var text = await page.$eval("body > table > tbody > tr:nth-child(4) > td:nth-child(3)", (el) => el.textContent); |
| 60 | + assert.type(text, "string"); |
| 61 | + assert.is(text, "12:45"); |
| 62 | +}); |
| 63 | + |
| 64 | +test("Solved Issue #3: display revenue numbers in a human readable format", async () => { |
| 65 | + await page.goto("http://localhost:8080"); |
| 66 | + await setTimeout(250); |
| 67 | + |
| 68 | + var text = await page.$eval("body > table > tbody > tr:nth-child(2) > td:nth-child(4)", (el) => el.textContent); |
| 69 | + assert.type(text, "string"); |
| 70 | + assert.is(text, "17 000 000"); |
| 71 | + |
| 72 | + var text = await page.$eval("body > table > tbody > tr:nth-child(3) > td:nth-child(4)", (el) => el.textContent); |
| 73 | + assert.type(text, "string"); |
| 74 | + assert.is(text, "7 375 294"); |
| 75 | + |
| 76 | + var text = await page.$eval("body > table > tbody > tr:nth-child(4) > td:nth-child(4)", (el) => el.textContent); |
| 77 | + assert.type(text, "string"); |
| 78 | + assert.is(text, "100 000"); |
| 79 | +}); |
| 80 | + |
| 81 | +test("Solved Issue #4: make table look prettier", async () => { |
| 82 | + await page.goto("http://localhost:8080"); |
| 83 | + await setTimeout(250); |
| 84 | + |
| 85 | + var headerColor = await page.$eval("tr:first-of-type", (el) => |
| 86 | + getComputedStyle(el).getPropertyValue("background-color") |
| 87 | + ); |
| 88 | + assert.is(headerColor, "rgb(173, 216, 230)"); |
| 89 | + |
| 90 | + var tableBorderColor = await page.$eval("body > table", (el) => |
| 91 | + getComputedStyle(el).getPropertyValue("border-color") |
| 92 | + ); |
| 93 | + assert.is(tableBorderColor, "rgb(173, 216, 230)"); |
| 94 | +}); |
| 95 | + |
| 96 | +test.run(); |
0 commit comments