You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
import assert from 'assert';
|
|
import cheerio from 'cheerio';
|
|
|
|
import HTML from './fixtures/html';
|
|
import {
|
|
getOrInitScore,
|
|
getScore,
|
|
} from './index';
|
|
|
|
describe('getOrInitScore(node, $)', () => {
|
|
describe('when score set', () => {
|
|
it('returns score if node\'s score already set', () => {
|
|
const html = '<p score="40">Foo</p>';
|
|
const $ = cheerio.load(html);
|
|
const node = $('p').first();
|
|
|
|
const score = getOrInitScore(node, $);
|
|
|
|
assert.equal(score, 40);
|
|
});
|
|
});
|
|
|
|
describe('when no score set', () => {
|
|
it('returns 0 if no class/id and text < 25 chars', () => {
|
|
const html = '<p>Foo</p>';
|
|
const $ = cheerio.load(html);
|
|
const node = $('p').first();
|
|
|
|
const score = getOrInitScore(node, $);
|
|
|
|
assert.equal(score, 0);
|
|
});
|
|
|
|
it('returns score if no class/id and has commas/length', () => {
|
|
const $ = cheerio.load(HTML.score19);
|
|
const node = $('p').first();
|
|
|
|
const score = getOrInitScore(node, $);
|
|
|
|
assert.equal(score, 19);
|
|
});
|
|
|
|
it('returns greater score if weighted class/id is set', () => {
|
|
const $ = cheerio.load(HTML.score44);
|
|
const node = $('p').first();
|
|
|
|
const score = getOrInitScore(node, $);
|
|
|
|
assert.equal(score, 44);
|
|
});
|
|
|
|
it('gives 1/4 of its score to its parent', () => {
|
|
const $ = cheerio.load(HTML.score44Parent);
|
|
const node = $('p').first();
|
|
|
|
getOrInitScore(node, $);
|
|
|
|
assert.equal(getScore(node.parent()), 16);
|
|
});
|
|
});
|
|
});
|