-
Notifications
You must be signed in to change notification settings - Fork 6
/
htmlGen.test.js
106 lines (95 loc) · 3.8 KB
/
htmlGen.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
const { htmlGen } = require('./htmlGen');
describe('htmlGen', () => {
//All good values and the typeof html is string
it('Generate a html code with all good values and a html string', () => {
let lang = 'en-CA';
let title = 'OSD600';
let html = '<p>Hello World!</p>';
let footer = 'Seneca College';
let temp =
`<!doctype html>\n` +
`<html lang="${lang}">\n<head>\n<meta charset="UTF-8">\n<title>${title}</title>\n` +
`<link rel="stylesheet" href="../src/css/style.css">\n</head>\n` +
`<body>\n` +
`<div class = "container">\n` +
`<h1>${title} </h1>\n` +
`${html}` +
`</div>\n</body>\n` +
`<footer> \n ${footer}\n</footer>\n</html>`;
expect(htmlGen(lang, title, html, footer)).toEqual(temp);
});
//All good values and the typeof html is object
it('Generate a html code with all good values and a html object', () => {
let lang = 'en-CA';
let title = 'OSD600';
let html = [`<p>Hello World!</p>`, `<p>I'm in OSD600!</p>`];
let footer = 'Seneca College';
let temp =
`<!doctype html>\n` +
`<html lang="${lang}">\n<head>\n<meta charset="UTF-8">\n<title>${title}</title>\n` +
`<link rel="stylesheet" href="../src/css/style.css">\n</head>\n` +
`<body>\n` +
`<div class = "container">\n` +
`${html.join(' ')}` +
`</div>\n</body>\n` +
`<footer> \n ${footer}\n</footer>\n</html>`;
expect(htmlGen(lang, title, html, footer)).toEqual(temp);
});
// Bad value of lang (wrong value type or empty string)
it('Generate a html code with bad lang value type or an empty lang', () => {
let lang = null;
let title = 'OSD600';
let html = '<p>Hello World!</p>';
let footer = 'Seneca College';
let temp = 'Error! Bad value of lang!';
let tempLang = '';
let temp1 = 'Error! Empty value of lang!';
expect(htmlGen(lang, title, html, footer)).toEqual(temp);
expect(htmlGen(tempLang, title, html, footer)).toEqual(temp1);
});
// Bad value of title (wrong value type or empty string)
it('Generate a html code with bad title value type or an empty title', () => {
let lang = 'en-CA';
let title = 600;
let html = [`<p>Hello World!</p>` + `<p>I'm in OSD600!</p>`];
let footer = 'Seneca College';
let temp = 'Error! Bad value of title!';
let tempTitle = '';
let temp1 = 'Error! Empty value of title!';
expect(htmlGen(lang, title, html, footer)).toEqual(temp);
expect(htmlGen(lang, tempTitle, html, footer)).toEqual(temp1);
});
// Bad value of html (wrong value type)
it('Generate a html code with bad html value type', () => {
let lang = 'en-CA';
let title = 'OSD600';
let html = false;
let footer = 'Seneca College';
let temp = 'Error! Bad value of html!';
expect(htmlGen(lang, title, html, footer)).toEqual(temp);
});
// Bad value of html (empty string or empty object)
it('Generate a html code with empty html string or empty html object', () => {
let lang = 'en-CA';
let title = 'OSD600';
let html = '';
let footer = 'Seneca College';
let temp = 'Error! Empty String value of html!';
let tempHtml = [];
let temp1 = 'Error! Empty Object value of html!';
expect(htmlGen(lang, title, html, footer)).toEqual(temp);
expect(htmlGen(lang, title, tempHtml, footer)).toEqual(temp1);
});
// Bad value of footer (wrong value type or empty string)
it('Generate a html code with bad footer value type or an empty footer', () => {
let lang = 'en-CA';
let title = 'OSD600';
let html = '<p>Hello World!</p>';
let footer = undefined;
let temp = 'Error! Bad value of footer!';
let tempFooter = '';
let temp1 = 'Error! Empty value of footer!';
expect(htmlGen(lang, title, html, footer)).toEqual(temp);
expect(htmlGen(lang, title, html, tempFooter)).toEqual(temp1);
});
});