-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
111 lines (93 loc) · 4.42 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { JSDOM } from "jsdom";
import { setTimeout } from "timers/promises";
import { test } from "uvu";
import * as assert from "uvu/assert";
let filePath = "./src/index.html";
// Helpers
const hasAllClasses = (dom, id, classes) =>
classes.every((val) => dom.window.document.getElementById(id).getAttribute("class").split(" ").includes(val));
// Tests
test("Nav Buttons Don't Work (Desktop & Mobile)", async () => {
const dom = await JSDOM.fromFile(filePath, {
runScripts: "dangerously",
resources: "usable",
});
await setTimeout(10);
assert.is(dom.window.document.getElementById("nav-logo").getAttribute("href"), "#header");
assert.is(dom.window.document.getElementById("nav-challenges").getAttribute("href"), "#challenges");
assert.is(dom.window.document.getElementById("nav-signup").getAttribute("href"), "#signup");
assert.is(dom.window.document.getElementById("mobile-nav-challenges").getAttribute("href"), "#challenges");
assert.is(dom.window.document.getElementById("mobile-nav-signup").getAttribute("href"), "#signup");
});
test("Desktop Nav Is Visible on Mobile", async () => {
const dom = await JSDOM.fromFile(filePath, {
runScripts: "dangerously",
resources: "usable",
});
await setTimeout(10);
assert.ok(hasAllClasses(dom, "nav-challenges", ["hide-small"]));
assert.ok(hasAllClasses(dom, "nav-signup", ["hide-small"]));
});
test("Invert Banner Image Colors", async () => {
const dom = await JSDOM.fromFile(filePath, {
runScripts: "dangerously",
resources: "usable",
});
await setTimeout(150);
let banner = dom.window.document.getElementById("jumbo-image");
assert.ok(["invert(1)", "invert(100%)"].includes(dom.window.getComputedStyle(banner)._values["filter"]));
});
test("Tiles Need to be 2x2 Grid", async () => {
const dom = await JSDOM.fromFile(filePath, {
runScripts: "dangerously",
resources: "usable",
});
await setTimeout(10);
let grid = dom.window.document.getElementById("challenge-grid");
assert.ok(
["repeat(2,1fr)", "1fr1fr", "50%50%", "autoauto"].includes(
dom.window.getComputedStyle(grid)._values["grid-template-columns"].replace(/\s/g, "")
)
);
});
test("Improve Errors on Signup Form Validation (Empty Email)", async () => {
const dom = await JSDOM.fromFile(filePath, {
runScripts: "dangerously",
resources: "usable",
});
await setTimeout(150); // Need to wait for script to load
// simulate empty email signup
dom.window.document.querySelector("button").dispatchEvent(new dom.window.MouseEvent("click"));
assert.is(dom.window.document.getElementById("success-message").hidden, true);
assert.is(dom.window.document.getElementById("empty-error-message").hidden, false);
assert.is(dom.window.document.getElementById("taken-error-message").hidden, true);
});
test("Improve Errors on Signup Form Validation (Taken Email)", async () => {
const dom = await JSDOM.fromFile(filePath, {
runScripts: "dangerously",
resources: "usable",
});
await setTimeout(150); // Need to wait for script to load
dom.window.document.getElementById("email").value = "hello@world.com";
dom.window.document.querySelector("button").dispatchEvent(new dom.window.MouseEvent("click"));
assert.is(dom.window.document.getElementById("success-message").hidden, true);
assert.is(dom.window.document.getElementById("empty-error-message").hidden, true);
assert.is(dom.window.document.getElementById("taken-error-message").hidden, false);
});
test("Improve Errors on Signup Form Validation (Repeat Email)", async () => {
const dom = await JSDOM.fromFile(filePath, {
runScripts: "dangerously",
resources: "usable",
});
await setTimeout(150); // Need to wait for script to load
dom.window.document.getElementById("email").value = "test@new.com";
dom.window.document.querySelector("button").dispatchEvent(new dom.window.MouseEvent("click"));
assert.is(dom.window.document.getElementById("success-message").hidden, false);
assert.is(dom.window.document.getElementById("empty-error-message").hidden, true);
assert.is(dom.window.document.getElementById("taken-error-message").hidden, true);
dom.window.document.querySelector("button").dispatchEvent(new dom.window.MouseEvent("click"));
assert.is(dom.window.document.getElementById("success-message").hidden, true);
assert.is(dom.window.document.getElementById("empty-error-message").hidden, true);
assert.is(dom.window.document.getElementById("taken-error-message").hidden, false);
});
test.run();