import { leadKeyword, parseKeywords, promoteKeyword } from '../keywords'; describe('parseKeywords', () => { it('splits on commas and drops the blanks', () => { expect(parseKeywords(' cast iron kettle, teapot ,, ')).toEqual([ 'cast iron kettle', 'teapot', ]); expect(parseKeywords('')).toEqual([]); }); }); describe('leadKeyword', () => { it('puts the new keyword first and drops the old first one', () => { expect(leadKeyword('kettle, teapot, cups', 'cast iron kettle')).toBe( 'cast iron kettle, teapot, cups' ); }); it('keeps a secondary keyword from appearing twice', () => { expect(leadKeyword('kettle, Teapot, cups', 'teapot')).toBe('teapot, cups'); }); it('starts the list when there was none', () => { expect(leadKeyword('', 'cast iron kettle')).toBe('cast iron kettle'); }); it('keeps to five keywords', () => { expect(leadKeyword('a, b, c, d, e', 'f')).toBe('f, b, c, d, e'); }); it('leaves the list alone without a keyword', () => { expect(leadKeyword('a, b', ' ')).toBe('a, b'); }); it('moves a secondary keyword to the front and keeps the rest in order', () => { expect(promoteKeyword('cast iron, seasoning, oil', 2)).toBe( 'oil, cast iron, seasoning' ); expect(promoteKeyword('cast iron, seasoning', 0)).toBe( 'cast iron, seasoning' ); expect(promoteKeyword('cast iron', 3)).toBe('cast iron'); }); });