-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
49 lines (39 loc) · 1.5 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
import injectMidContentAds from './inject-mid-content-ads';
import articles from './data/articles';
const simpleArticle = articles[0];
const articleWithImages = articles[1];
const articleWithBlacklist = articles[2];
describe('injectMidContentAds()', () => {
describe('Simple Article', () => {
document.body.innerHTML = injectMidContentAds(simpleArticle);
const ads = document.querySelectorAll('.ad');
const elements = document.querySelectorAll('article > *');
test('1 ad gets added', () => {
expect(ads.length).toBe(1);
});
test('the ad is placed after the 4th paragraph', () => {
expect(elements[4].className).toBe('ad');
});
});
describe('Article with Images', () => {
document.body.innerHTML = injectMidContentAds(articleWithImages);
const ads = document.querySelectorAll('.ad');
const elements = document.querySelectorAll('article > *');
test('3 ads gets added', () => {
expect(ads.length).toBe(3);
});
test('the first ad is placed after the 3rd paragraph (because there\'s an image after the 4th)', () => {
expect(elements[3].className).toBe('ad');
});
test('the rest of the ads get placed normally', () => {
expect(elements[10].className).toBe('ad');
expect(elements[16].className).toBe('ad');
});
});
describe('Article with Blacklist', () => {
const html = injectMidContentAds(articleWithBlacklist);
test('0 ads gets added', () => {
expect(html).toBe(articleWithBlacklist.html);
});
});
});