|
1 | 1 | import assert from 'assert';
|
2 | 2 | import cheerio from 'cheerio';
|
3 | 3 |
|
4 |
| -import HTML from './fixtures/html'; |
5 |
| - |
6 | 4 | import { getScore, findTopCandidate, scoreContent } from './index';
|
7 | 5 |
|
8 | 6 | const fs = require('fs');
|
9 | 7 |
|
10 | 8 | describe('findTopCandidate($)', () => {
|
11 | 9 | it('finds the top candidate from simple case', () => {
|
12 |
| - const $ = cheerio.load(HTML.findDom1); |
| 10 | + const $ = cheerio.load(` |
| 11 | + <div score="100"> |
| 12 | + <p score="1">Lorem ipsum etc</p> |
| 13 | + </div> |
| 14 | + `); |
13 | 15 |
|
14 | 16 | const $$topCandidate = findTopCandidate($);
|
15 | 17 |
|
16 | 18 | assert.equal(getScore($$topCandidate), 100);
|
17 | 19 | });
|
18 | 20 |
|
19 | 21 | it('finds the top candidate from a nested case', () => {
|
20 |
| - const $ = cheerio.load(HTML.findDom2); |
| 22 | + const $ = cheerio.load(` |
| 23 | + <div score="10"> |
| 24 | + <article score="50"> |
| 25 | + <p score="1">Lorem ipsum etc</p> |
| 26 | + </article> |
| 27 | + </div> |
| 28 | + `); |
21 | 29 |
|
22 | 30 | const $$topCandidate = findTopCandidate($);
|
23 | 31 |
|
24 |
| - // this is wrapped in a div so checking |
25 |
| - // the score of the first child |
| 32 | + // this is wrapped in a div so checking the score of the first child |
26 | 33 | assert.equal(getScore($$topCandidate.first()), 50);
|
27 | 34 | });
|
28 | 35 |
|
29 | 36 | it('ignores tags like BR', () => {
|
30 |
| - const $ = cheerio.load(HTML.findDom3); |
| 37 | + const $ = cheerio.load(` |
| 38 | + <article score="50"> |
| 39 | + <p score="1">Lorem ipsum br</p> |
| 40 | + <br score="1000" /> |
| 41 | + </article> |
| 42 | + `); |
31 | 43 |
|
32 | 44 | const $topCandidate = findTopCandidate($);
|
33 | 45 |
|
34 | 46 | assert.equal(getScore($topCandidate), 50);
|
35 | 47 | });
|
36 | 48 |
|
37 | 49 | it('returns BODY if no candidates found', () => {
|
38 |
| - const $ = cheerio.load(HTML.topBody); |
| 50 | + const $ = cheerio.load(` |
| 51 | + <body> |
| 52 | + <article> |
| 53 | + <p>Lorem ipsum etc</p> |
| 54 | + <br /> |
| 55 | + </article> |
| 56 | + <body> |
| 57 | + `); |
39 | 58 |
|
40 | 59 | const $topCandidate = findTopCandidate($);
|
41 | 60 |
|
42 |
| - // browser won't allow body tag to be placed |
43 |
| - // arbitrarily/loaded on the page, so we tranform |
44 |
| - // it in cheerio-query, so this test would fail. |
| 61 | + // browser won't allow body tag to be placed arbitrarily/loaded on the page, |
| 62 | + // so we tranform it in cheerio-query, so this test would fail. |
45 | 63 | if (!$.browser) {
|
46 | 64 | assert.equal($topCandidate.get(0).tagName, 'body');
|
47 | 65 | }
|
|
0 commit comments