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.
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
8 years ago
|
import assert from 'assert'
|
||
|
import cheerio from 'cheerio'
|
||
|
|
||
|
import HTML from './fixtures/html'
|
||
|
|
||
|
import GenericLeadImageUrlExtractor from './extractor'
|
||
|
|
||
|
describe('GenericLeadImageUrlExtractor', () => {
|
||
8 years ago
|
describe('extract({ $, content, metaCache })', () => {
|
||
8 years ago
|
it('returns og:image first', () => {
|
||
|
const $ = cheerio.load(HTML.og.test)
|
||
|
const content = $('*').first()
|
||
8 years ago
|
const metaCache = ['og:image']
|
||
8 years ago
|
|
||
|
const result =
|
||
8 years ago
|
GenericLeadImageUrlExtractor.extract(
|
||
|
{ $, content, metaCache }
|
||
|
)
|
||
8 years ago
|
|
||
|
assert.equal(result, HTML.og.result)
|
||
|
})
|
||
|
|
||
|
it('returns twitter:image', () => {
|
||
|
const $ = cheerio.load(HTML.twitter.test)
|
||
|
const content = $('*').first()
|
||
8 years ago
|
const metaCache = ['twitter:image']
|
||
8 years ago
|
|
||
|
const result =
|
||
8 years ago
|
GenericLeadImageUrlExtractor.extract(
|
||
|
{ $, content, metaCache }
|
||
|
)
|
||
8 years ago
|
|
||
|
assert.equal(result, HTML.twitter.result)
|
||
|
})
|
||
|
|
||
|
it('finds images based on scoring', () => {
|
||
|
const $ = cheerio.load(HTML.scoring.test)
|
||
|
const content = $('*').first()
|
||
8 years ago
|
const metaCache = []
|
||
8 years ago
|
|
||
|
const result =
|
||
8 years ago
|
GenericLeadImageUrlExtractor.extract(
|
||
|
{ $, content, metaCache }
|
||
|
)
|
||
8 years ago
|
|
||
|
assert.equal(result, HTML.scoring.result)
|
||
|
})
|
||
|
|
||
|
it('returns image based on selectors', () => {
|
||
|
const $ = cheerio.load(HTML.selectors.test)
|
||
|
const content = $('*').first()
|
||
8 years ago
|
const metaCache = []
|
||
8 years ago
|
|
||
|
const result =
|
||
8 years ago
|
GenericLeadImageUrlExtractor.extract(
|
||
|
{ $, content, metaCache }
|
||
|
)
|
||
8 years ago
|
|
||
|
assert.equal(result, HTML.selectors.result)
|
||
|
})
|
||
|
})
|
||
|
})
|