-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
93 lines (79 loc) · 2.86 KB
/
script.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
/* =================
TESTS, LOOK AT THESE
Reading tests will always help you discover your requirements.
You can make this window bigger.
===================
*/
const {
core: { test, expect, run },
prettify
} = window.jestLite;
/* =================
FIND ELEMENTS
These are all the elements we will look for.
===================
*/
const getHeader = document.querySelectorAll("header"),
getH1 = document.querySelectorAll("h1"),
getSiteHeader = document.querySelectorAll(".c-site-header"),
getAria = document.querySelectorAll('nav[aria-label="Main Site Links."]'),
getMain = document.querySelectorAll("main"),
getFooter = document.querySelectorAll("footer"),
getSiteFooter = document.querySelectorAll(".c-site-footer"),
getIFrame = document.querySelectorAll("iframe"),
getImage = document.querySelectorAll("img"),
getWords = document.body.innerText;
/* =================
ASSERTIONS
These are the things we check are true about your page.
Read and update your HTML to discover the requirements.
The tests will run every time you update your code.
===================
*/
test("There is at least one header element", () => {
expect(getHeader.length).toBeGreaterThanOrEqual(1);
});
test("There is at least one h1", () => {
expect(getH1.length).toBeGreaterThanOrEqual(1);
});
test("There is only one header element with the class c-site-header", () => {
expect(getSiteHeader.length).toBe(1);
});
test("There is a nav element with an aria-label of Main Site Links.", () => {
expect(getAria.length).toBeGreaterThanOrEqual(1);
});
test("There is only one main element", () => {
expect(getMain.length).toBe(1);
});
test("There is at least one footer element", () => {
expect(getFooter.length).toBeGreaterThanOrEqual(1);
});
test("There is only one footer element with the class c-site-footer", () => {
expect(getSiteFooter.length).toBe(1);
});
test("There is embedded video", () => {
expect(getIFrame.length).toBeGreaterThanOrEqual(1);
});
test("There is at least one image", () => {
expect(getImage.length).toBeGreaterThanOrEqual(1);
});
test("There are at least 500 words on the page", () => {
expect(getWords.length).toBeGreaterThanOrEqual(500);
});
function getNumberOrString(value) {
// Convert a string value to a number if possible
let number_value = Number(value);
if (Number.isNaN(number_value)) {
return value
} else {
return number_value
}
}
document.getElementById('send').addEventListener('click', (event) => {
let element_outputName = document.getElementById('NameReturn');
element_outputName.innerText = getNumberOrString(document.getElementById('c_name').value);
let element_outputText = document.getElementById('TextReturn');
element_outputText.innerText = getNumberOrString(document.getElementById('c_comment').value);
});
const console = document.getElementById("tests");
prettify.toHTML(run(), console);