forked from iamstarkov/jsunderhood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
104 lines (92 loc) · 3.29 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
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
/* eslint-env mocha */
const assert = require('assert');
const { readFileSync } = require('fs-extra');
const cheerio = require('cheerio');
const typeNumbers = require('typographic-numbers');
const { head } = require('ramda');
const authors = require('./dump');
const authorId = require('./helpers/author-id');
const getGainedFollowers = require('./helpers/get-gained-followers');
const getDiffFollowers = require('./helpers/get-diff-followers');
const latestInfo = head(authors).info;
const numbers = (input) => typeNumbers(input, { locale: 'ru' });
const make$ = (file) => cheerio.load(readFileSync(file, { encoding: 'utf8' }));
describe('js', () => {
it('getGainedFollowers ordinary', () => {
assert.equal(getGainedFollowers('rstacruz'), 17);
});
it('getGainedFollowers first one', () => {
assert.equal(getGainedFollowers('shuvalov_anton'), 115);
});
it('getDiffFollowers normal', () => {
assert.deepEqual(getDiffFollowers('rstacruz'), { gain: 29, loss: 12 });
assert.deepEqual(getDiffFollowers('touzoku'), { gain: 88, loss: 15 });
assert.deepEqual(getDiffFollowers('milk_is_my_life'), { gain: 60, loss: 28 });
});
it('getDiffFollowers obsolete', () => {
assert.equal(getDiffFollowers('ihorzenich'), null);
assert.equal(getDiffFollowers('oleg008'), null);
});
});
describe('html', () => {
describe('index page', () => {
it('short authors info', () => {
const $ = make$('dist/index.html');
const pageAuthors = $('article .list__item-desc');
const realAuthors = authors.filter((a) => a.post !== false);
assert(pageAuthors.length === realAuthors.length);
});
it('don’t have subheading', () => {
const $ = make$('dist/index.html');
assert($('.page-header h1 small').length === 0);
});
it('followers count exists', () => {
const $ = make$('dist/index.html');
const followers = numbers(String(latestInfo.followers_count));
assert($('.page-header p i').text().indexOf(followers) > 0);
});
});
describe('stats page', () => {
it('stats rows', () => {
const $ = make$('dist/stats/index.html');
const rows = $('.host-stats__row:not(.host-stats__row_head)');
assert(rows.length === authors.length);
});
});
describe('about page', () => {
it('text', () => {
const $ = make$('dist/about/index.html');
assert($('article').text().length > 0);
});
});
describe('archive pages', () => {
it('tweets list', () => {
authors.forEach((author) => {
if (author.post === false) return;
const $ = make$(`dist/${author.username}/index.html`);
assert($('article p').length > 1);
// assert($('article h2 small').length > 1);
});
});
});
describe('authorId', () => {
const input = [
{ username: 'first' },
{ username: 'yolo' },
{ username: 'first' },
{ username: 'yolo' },
{ username: 'first' },
];
it('should work', () => {
const actual = authorId(input);
const expected = [
{ username: 'first', authorId: 'first-3' },
{ username: 'yolo', authorId: 'yolo-2' },
{ username: 'first', authorId: 'first-2' },
{ username: 'yolo', authorId: 'yolo' },
{ username: 'first', authorId: 'first' },
];
assert.deepEqual(actual, expected);
});
});
});