|
| 1 | +<<<<<<< Updated upstream |
1 | 2 | import { setTimeout } from "timers/promises";
|
2 | 3 | import { test } from "uvu";
|
3 | 4 | import * as assert from "uvu/assert";
|
@@ -102,6 +103,116 @@ test("Solved Issue #4: make table look prettier", async (context) => {
|
102 | 103 | return window.getComputedStyle(table).getPropertyValue("border-color");
|
103 | 104 | });
|
104 | 105 | assert.is(tableBorderColor, "rgb(173, 216, 230)");
|
| 106 | +======= |
| 107 | +import { JSDOM } from "jsdom"; |
| 108 | +import { setTimeout } from "timers/promises"; |
| 109 | +import { test } from "uvu"; |
| 110 | +import * as assert from "uvu/assert"; |
| 111 | +let filePath = "./src/index.html"; |
| 112 | + |
| 113 | +// Helpers |
| 114 | + |
| 115 | +const hasAllClasses = (dom, id, classes) => |
| 116 | + classes.every((val) => dom.window.document.getElementById(id).getAttribute("class").split(" ").includes(val)); |
| 117 | + |
| 118 | +// Tests |
| 119 | + |
| 120 | +test("Nav Buttons Don't Work (Desktop & Mobile)", async () => { |
| 121 | + const dom = await JSDOM.fromFile(filePath, { |
| 122 | + runScripts: "dangerously", |
| 123 | + resources: "usable", |
| 124 | + }); |
| 125 | + await setTimeout(10); |
| 126 | + assert.is(dom.window.document.getElementById("nav-logo").getAttribute("href"), "#header"); |
| 127 | + assert.is(dom.window.document.getElementById("nav-challenges").getAttribute("href"), "#challenges"); |
| 128 | + assert.is(dom.window.document.getElementById("nav-signup").getAttribute("href"), "#signup"); |
| 129 | + assert.is(dom.window.document.getElementById("mobile-nav-challenges").getAttribute("href"), "#challenges"); |
| 130 | + assert.is(dom.window.document.getElementById("mobile-nav-signup").getAttribute("href"), "#signup"); |
| 131 | +}); |
| 132 | + |
| 133 | +test("Desktop Nav Is Visible on Mobile", async () => { |
| 134 | + const dom = await JSDOM.fromFile(filePath, { |
| 135 | + runScripts: "dangerously", |
| 136 | + resources: "usable", |
| 137 | + }); |
| 138 | + await setTimeout(10); |
| 139 | + assert.ok(hasAllClasses(dom, "nav-challenges", ["hide-small"])); |
| 140 | + assert.ok(hasAllClasses(dom, "nav-signup", ["hide-small"])); |
| 141 | +}); |
| 142 | + |
| 143 | +test("Invert Banner Image Colors", async () => { |
| 144 | + const dom = await JSDOM.fromFile(filePath, { |
| 145 | + runScripts: "dangerously", |
| 146 | + resources: "usable", |
| 147 | + }); |
| 148 | + await setTimeout(150); |
| 149 | + let banner = dom.window.document.getElementById("jumbo-image"); |
| 150 | + assert.ok(["invert(1)", "invert(100%)"].includes(dom.window.getComputedStyle(banner)._values["filter"])); |
| 151 | +}); |
| 152 | + |
| 153 | +test("Tiles Need to be 2x2 Grid", async () => { |
| 154 | + const dom = await JSDOM.fromFile(filePath, { |
| 155 | + runScripts: "dangerously", |
| 156 | + resources: "usable", |
| 157 | + }); |
| 158 | + await setTimeout(10); |
| 159 | + let grid = dom.window.document.getElementById("challenge-grid"); |
| 160 | + assert.ok( |
| 161 | + ["repeat(2,1fr)", "1fr1fr", "50%50%"].includes( |
| 162 | + dom.window.getComputedStyle(grid)._values["grid-template-columns"].replace(/\s/g, "") |
| 163 | + ) |
| 164 | + ); |
| 165 | +}); |
| 166 | + |
| 167 | +test("Improve Errors on Signup Form Validation (Empty Email)", async () => { |
| 168 | + const dom = await JSDOM.fromFile(filePath, { |
| 169 | + runScripts: "dangerously", |
| 170 | + resources: "usable", |
| 171 | + }); |
| 172 | + await setTimeout(150); // Need to wait for script to load |
| 173 | + |
| 174 | + // simulate empty email signup |
| 175 | + dom.window.document.querySelector("button").dispatchEvent(new dom.window.MouseEvent("click")); |
| 176 | + |
| 177 | + assert.is(dom.window.document.getElementById("success-message").hidden, true); |
| 178 | + assert.is(dom.window.document.getElementById("empty-error-message").hidden, false); |
| 179 | + assert.is(dom.window.document.getElementById("taken-error-message").hidden, true); |
| 180 | +}); |
| 181 | + |
| 182 | +test("Improve Errors on Signup Form Validation (Taken Email)", async () => { |
| 183 | + const dom = await JSDOM.fromFile(filePath, { |
| 184 | + runScripts: "dangerously", |
| 185 | + resources: "usable", |
| 186 | + }); |
| 187 | + await setTimeout(150); // Need to wait for script to load |
| 188 | + |
| 189 | + dom.window.document.getElementById("email").value = "[email protected]"; |
| 190 | + dom.window.document.querySelector("button").dispatchEvent(new dom.window.MouseEvent("click")); |
| 191 | + |
| 192 | + assert.is(dom.window.document.getElementById("success-message").hidden, true); |
| 193 | + assert.is(dom.window.document.getElementById("empty-error-message").hidden, true); |
| 194 | + assert.is(dom.window.document.getElementById("taken-error-message").hidden, false); |
| 195 | +}); |
| 196 | + |
| 197 | +test("Improve Errors on Signup Form Validation (Repeat Email)", async () => { |
| 198 | + const dom = await JSDOM.fromFile(filePath, { |
| 199 | + runScripts: "dangerously", |
| 200 | + resources: "usable", |
| 201 | + }); |
| 202 | + await setTimeout(150); // Need to wait for script to load |
| 203 | + |
| 204 | + dom.window.document.getElementById("email").value = "[email protected]"; |
| 205 | + dom.window.document.querySelector("button").dispatchEvent(new dom.window.MouseEvent("click")); |
| 206 | + |
| 207 | + assert.is(dom.window.document.getElementById("success-message").hidden, false); |
| 208 | + assert.is(dom.window.document.getElementById("empty-error-message").hidden, true); |
| 209 | + assert.is(dom.window.document.getElementById("taken-error-message").hidden, true); |
| 210 | + |
| 211 | + dom.window.document.querySelector("button").dispatchEvent(new dom.window.MouseEvent("click")); |
| 212 | + assert.is(dom.window.document.getElementById("success-message").hidden, true); |
| 213 | + assert.is(dom.window.document.getElementById("empty-error-message").hidden, true); |
| 214 | + assert.is(dom.window.document.getElementById("taken-error-message").hidden, false); |
| 215 | +>>>>>>> Stashed changes |
105 | 216 | });
|
106 | 217 |
|
107 | 218 | test.run();
|
0 commit comments