-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
codegrade_mvp.test.js
192 lines (190 loc) · 5.9 KB
/
codegrade_mvp.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
const { server } = require('./mocks/server')
const { screen } = require('@testing-library/dom')
require('@testing-library/jest-dom/extend-expect')
beforeAll(() => {
server.listen()
document.body.innerHTML = `
<div class="container">
<header>
<nav>
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
<a href="#"></a>
</nav>
<img id="logo-img" class="logo" alt="Great Idea! Company logo">
</header>
<section class="cta">
<div class="cta-text">
<h1></h1>
<button></button>
</div>
<img id="cta-img" alt="Image of a code snippet">
</section>
<section class="main-content">
<div class="top-content">
<div class="text-content">
<h4></h4>
<p></p>
</div>
<div class="text-content">
<h4></h4>
<p></p>
</div>
</div>
<img class="middle-img" id="middle-img" alt="Image of code snippets across the screen">
<div class="bottom-content">
<div class="text-content">
<h4></h4>
<p></p>
</div>
<div class="text-content">
<h4></h4>
<p></p>
</div>
<div class="text-content">
<h4></h4>
<p></p>
</div>
</div>
</section>
<section class="contact">
<h4></h4>
<p></p>
<p></p>
<p></p>
</section>
<footer>
<a href="#"></a>
</footer>
</div>
`
require('./src/index.js')
})
afterAll(() => {
server.close()
})
afterEach(() => {
server.resetHandlers()
})
describe('text contents', () => {
test('[1] header nav links contain the correct text', () => {
expect(screen.getByText('Services', { selector: 'nav a' }))
expect(screen.getByText('Product', { selector: 'nav a' }))
expect(screen.getByText('Vision', { selector: 'nav a' }))
expect(screen.getByText('Features', { selector: 'nav a' }))
expect(screen.getByText('About', { selector: 'nav a' }))
expect(screen.getByText('Contact', { selector: 'nav a' }))
})
test('[2] call to action elements contain the correct text', () => {
expect(screen.getByText('DOM Is Awesome'))
expect(screen.getByText('Get Started'))
})
test('[3] main content headings contain the correct text', () => {
expect(screen.getByText(
'Features',
{ selector: '.top-content .text-content:nth-of-type(1) h4' }
))
expect(screen.getByText(
'About',
{ selector: '.top-content .text-content:nth-of-type(2) h4' }
))
})
test('[4] main content paragraphs contain the correct text', () => {
expect(screen.getByText(
/Features content elementum magna eros/,
{ selector: '.top-content .text-content p' }
))
expect(screen.getByText(
/About content elementum magna eros/,
{ selector: '.top-content .text-content p' }
))
})
test('[5] bottom content headings contain the correct text', () => {
expect(screen.getByText(
'Services',
{ selector: '.bottom-content .text-content h4' }
))
expect(screen.getByText(
'Product',
{ selector: '.bottom-content .text-content h4' }
))
expect(screen.getByText(
'Vision',
{ selector: '.bottom-content .text-content h4' }
))
})
test('[6] bottom content headings contain the correct text', () => {
expect(screen.getByText(
/Services content elementum magna eros/,
{ selector: '.bottom-content .text-content p' }
))
expect(screen.getByText(
/Product content elementum magna eros/,
{ selector: '.bottom-content .text-content p' }
))
expect(screen.getByText(
/Vision content elementum magna eros/,
{ selector: '.bottom-content .text-content p' }
))
})
test('[7] contact information elements contain the correct text', () => {
expect(screen.getByText(
'Contact',
{ selector: 'section.contact h4' }
))
expect(screen.getByText(
'123 Way 456 Street Somewhere, USA',
{ selector: 'section.contact p' }
))
expect(screen.getByText('1 (888) 888-8888',
{ selector: 'section.contact p' }
))
expect(screen.getByText(
'sales@greatidea.io',
{ selector: 'section.contact p' }
))
})
test('[8] copyright information link contains the correct text', () => {
expect(screen.getByText(
/Copyright Great Idea/,
{ selector: 'footer a' }
))
})
})
describe('img sources', () => {
test('[9] header logo img has the correct src', () => {
expect(screen.getByAltText(/Company logo/))
.toHaveAttribute('src', 'http://localhost:9000/img/logo.png')
})
test('[10] call to action img has the correct src', () => {
expect(screen.getByAltText('Image of a code snippet'))
.toHaveAttribute('src', 'http://localhost:9000/img/cta.png')
})
test('[11] middle img has the correct src', () => {
expect(screen.getByAltText(/Image of code snippets/))
.toHaveAttribute('src', 'http://localhost:9000/img/accent.png')
})
})
describe('class names', () => {
test('[12] nav links have a class name of italic', () => {
// screen.getAllByText(/[\s\S]*/, { selector: 'nav a' }) // TODO: research which
for (let link of document.querySelectorAll('nav a')) {
expect(link).toHaveAttribute('class', 'italic')
}
})
test('[13] no other links have a class name of italic', () => {
expect(document.querySelector('footer a')).not.toHaveAttribute('class', 'italic')
})
test('[14] the footer link has a class name of bold', () => {
const link = document.querySelector('footer a')
expect(link).toHaveAttribute('class', 'bold')
})
test('[15] no other links have a class name of bold', () => {
for (let link of document.querySelectorAll('nav a')) {
expect(link).not.toHaveAttribute('class', 'bold')
}
})
})