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.
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import assert from 'assert';
|
|
import cheerio from 'cheerio';
|
|
import fs from 'fs';
|
|
|
|
import scoreLinks from './score-links';
|
|
|
|
describe('scoreLinks(links)', () => {
|
|
it('returns an object of scored links', () => {
|
|
const html = fs.readFileSync('./fixtures/ars.html', 'utf8');
|
|
|
|
const $ = cheerio.load(html);
|
|
const links = $('a[href]').toArray();
|
|
const url = 'http://arstechnica.com/gadgets/2016/08/the-connected-renter-how-to-make-your-apartment-smarter/';
|
|
|
|
const scoredPages = scoreLinks({
|
|
links,
|
|
articleUrl: url,
|
|
baseUrl: 'http://arstechnica.com',
|
|
$,
|
|
});
|
|
|
|
assert.equal(typeof scoredPages, 'object');
|
|
});
|
|
|
|
it('returns null if no possible pages', () => {
|
|
const html = '<div><p>Hello wow</p></div>';
|
|
|
|
const $ = cheerio.load(html);
|
|
const links = $('a[href]').toArray();
|
|
const url = 'http://arstechnica.com/gadgets/2016/08/the-connected-renter-how-to-make-your-apartment-smarter/';
|
|
|
|
const scoredPages = scoreLinks({
|
|
links,
|
|
articleUrl: url,
|
|
baseUrl: 'http://arstechnica.com',
|
|
$,
|
|
});
|
|
|
|
assert.equal(scoredPages, null);
|
|
});
|
|
});
|
|
|