forked from 18F/cv_faq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html.test.js
85 lines (68 loc) · 2.76 KB
/
index.html.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
beforeAll(async () => {
await page.goto('http://localhost:4444/');
});
test('all six top questions have an icon and text', async () => {
const questions = await page.$$eval('.top-questions .question', elements => {
return elements.map(q => { return {
text: q.innerText.trim(),
src: q.querySelector('img').src
}});
});
expect(questions).toHaveLength(6);
questions.forEach(({text, src}) => {
expect(text).not.toEqual('');
// Asserts a fingerprint has been calculated for this asset, therefore it
// has been found in the build process.
expect(src).toMatch(/\/assets\/.+-.{64}\.svg/);
});
});
test('both question boxes have three content links and a view all link', async () => {
const boxes = await page.$$eval('.question-box', elements => {
return elements.map(b => {
const getText = (el) => el ? el.innerText.trim().replace(/\n/g, '') : null;
return {
title: getText(b.querySelector('h2')),
questions: [...b.querySelectorAll('li')].map(getText),
viewAllText: getText(b.querySelector('.view-all'))
};
});
});
expect(boxes).toHaveLength(2);
boxes.forEach(({title, questions, viewAllText}) => {
expect(title).not.toEqual('');
expect(questions).toHaveLength(3);
// Assert that the view all text (including the screen reader text) is present.
expect(viewAllText).toContain(`View all questions about ${title}`);
});
});
test('the six displayed categories have three content links and a view all link', async () => {
const categories = await page.$$eval('.top-categories .usa-media-block', elements => {
return elements.map(b => {
const getText = (el) => el ? el.innerText.trim().replace(/\n/g, '') : null;
return {
title: getText(b.querySelector('h3')),
questions: [...b.querySelectorAll('li')].map(getText),
viewAllText: getText(b.querySelector('.view-all'))
};
});
});
expect(categories).toHaveLength(6);
categories.forEach(({title, questions, viewAllText}) => {
expect(title).not.toEqual('');
expect(questions).toHaveLength(3);
// Assert that the view all text (including the screen reader text) is present.
expect(viewAllText).toContain(`View all questions about ${title}`);
});
});
test('the load more button displays additional categories', async () => {
const getVisibleCategories = () => page.$$eval('.usa-media-block', elements => {
return elements.map(category => { return {
title: category.querySelector('h3').innerText,
visible: category.offsetHeight !== 0
}}).filter(c => c.visible);
});
const before = await getVisibleCategories();
await page.click('#more-questions-button');
const after = await getVisibleCategories();
expect(before.length).toBeLessThan(after.length);
});