import { keywordIdeas } from '../keyword-ideas'; describe('keyword ideas', () => { const page = { title: 'How to season a cast iron pan', html: `
Seasoning a cast iron pan takes an hour. A cast iron pan that is seasoned well lasts for generations.
Flaxseed oil and vegetable oil both work. Vegetable oil is cheaper.
Dry the cast iron pan after every wash.
`, }; it('finds the phrases the title and the text share, strongest first', () => { const ideas = keywordIdeas(page); expect(ideas[0]).toBe('cast iron pan'); expect(ideas).toContain('vegetable oil'); }); it('keeps one of overlapping phrases and leaves out what is set already', () => { const ideas = keywordIdeas(page, ['Vegetable oil']); expect(ideas).not.toContain('vegetable oil'); expect(ideas.filter(idea => idea.includes('cast iron'))).toHaveLength(1); }); it('never starts or ends on a word that means nothing', () => { keywordIdeas(page).forEach(idea => { expect(idea).not.toMatch(/^(a|the|to|of|and|how) | (a|the|to|of|and)$/); }); }); it('leaves out the runs that wait for their noun, in English and Romanian', () => { const english = keywordIdeas({ title: 'How to Choose the Right Hoodie Size', html: 'To choose the right hoodie size, measure your chest. The right hoodie size fits over a shirt.
', }); expect(english).toContain('hoodie size'); expect(english).not.toContain('choose the right'); const romanian = keywordIdeas({ title: 'Cum alegi hanoracul potrivit', html: 'Dacă ești între două mărimi, alege hanoracul mai mare. Când te măsori, stai drept.
Te măsori cu un centimetru. Ești între două mărimi? Hanoracul potrivit stă bine.
', }); expect(romanian).toContain('hanoracul potrivit'); romanian.forEach(idea => expect(idea).not.toMatch( /^(ești|te|între|două|îți) | (ești|te|între|două|îți)$/ ) ); }); it('reads Romanian', () => { const ideas = keywordIdeas({ title: 'Cum alegi o tigaie din fontă', html: 'O tigaie din fontă ține o viață. Tigaie din fontă sau tigaie ceramică?
Tigaie ceramică se curăță ușor.
', }); expect(ideas).toContain('tigaie din fontă'); expect(ideas).toContain('tigaie ceramică'); }); });