generated from ProlificLabs/shakesearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
79 lines (60 loc) · 2.67 KB
/
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
const assert = require('chai').assert;
const puppeteer = require('puppeteer-core');
describe('ShakeSearch', () => {
let browser;
let page;
before(async () => {
browser = await puppeteer.launch({
executablePath: '/usr/bin/chromium-browser',
args: ['--no-sandbox'],
});
page = await browser.newPage();
await page.goto('http://localhost:3002');
});
after(async () => {
await browser.close();
});
it('should return no results for "Luke, I am your father"', async () => {
const query = 'Luke, I am your father';
await page.evaluate(() => document.getElementById('query').value = ''); // Reset the input field
await page.type('#query', query);
await page.click('button[type="submit"]');
await page.waitForTimeout(1000);
const results = await page.evaluate(() => {
const rows = document.querySelectorAll('#table-body tr');
return Array.from(rows, row => row.textContent.trim());
});
assert.isEmpty(results, 'Search results should be empty');
});
it('should return search results for "romeo, wherefore art thou"', async () => {
const query = 'romeo, wherefore art thou';
await page.evaluate(() => document.getElementById('query').value = ''); // Reset the input field
await page.type('#query', query);
await page.click('button[type="submit"]');
await page.waitForSelector('#table-body tr');
const results = await page.evaluate(() => {
const rows = document.querySelectorAll('#table-body tr');
return Array.from(rows, row => row.textContent.trim());
});
assert.isNotEmpty(results, 'Search results should not be empty');
assert.include(results.join(' ').toLowerCase(), query.toLowerCase(), 'Search results should contain the query');
});
it('should load more results for "horse" when clicking "Load More"', async () => {
const query = 'horse';
await page.evaluate(() => document.getElementById('query').value = ''); // Reset the input field
await page.type('#query', query);
await page.click('button[type="submit"]');
await page.waitForSelector('#table-body tr');
const initialResults = await page.evaluate(() => {
const rows = document.querySelectorAll('#table-body tr');
return Array.from(rows, row => row.textContent.trim());
});
await page.click('#load-more');
await page.waitForTimeout(1000);
const updatedResults = await page.evaluate(() => {
const rows = document.querySelectorAll('#table-body tr');
return Array.from(rows, row => row.textContent.trim());
});
assert.isAbove(updatedResults.length, initialResults.length, 'More results should be added to the results table');
});
});