forked from etolstoy/mobileunderhood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
64 lines (57 loc) · 2 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
/* eslint-env mocha */
import assert from 'assert';
import { readFileSync } from 'fs-extra';
import cheerio from 'cheerio';
import typeNumbers from 'typographic-numbers';
import authors from './dump';
import authorId from './helpers/author-id';
import underhood from './.underhoodrc.json';
import getAuthorArea from './helpers/get-author-area';
const underhoodInfo = getAuthorArea(underhood.underhood, 'info') || {};
const numbers = input => typeNumbers(input, { locale: 'ru' });
const make$ = file => cheerio.load(readFileSync(file, { encoding: 'utf8' }));
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(underhoodInfo.followers_count));
assert($('.page-header p i').text().indexOf(followers) > 0);
});
});
describe('about page', () => {
it('text', () => {
const $ = make$('dist/about/index.html');
assert($('article').text().length > 0);
});
});
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);
});
});
});