import { rankMatch, settingsIndex } from '../settings-index'; describe('settings search', () => { it('matches the start of words, not their middle', () => { expect(rankMatch('og', ['Logo'])).toBe(0); expect(rankMatch('og', ['og:image'])).toBeGreaterThan(0); expect(rankMatch('open hours', ['Opening hours'])).toBeGreaterThan(0); expect(rankMatch('breadcrumb', ['Breadcrumbs'])).toBeGreaterThan(0); }); it('ranks a match in the label above one in the text', () => { expect( rankMatch('noindex', ['Noindex empty archives', '']) ).toBeGreaterThan( rankMatch('noindex', ['Empty archives', 'Mark them noindex']) ); }); it('knows the page and section of every option and section', () => { const index = settingsIndex({ post_types: { post: 'Posts' }, taxonomies: { category: 'Categories' }, }); const find = (label: string, page: string) => index.find(entry => entry.label === label && entry.page === page); expect(find('Opening hours', '/seo/local')?.section).toBe('contact'); expect(find('Separator', '/seo/general')?.section).toBe('breadcrumbs'); expect(find('Home link', '/seo/general')?.section).toBe('breadcrumbs'); expect( index.some( entry => entry.page === '/seo/titles' && entry.section === 'post-type-post' && entry.detail === 'Posts' ) ).toBe(true); expect( index.some( entry => entry.isSection && entry.page === '/seo/sitemap' && entry.section === 'indexnow' ) ).toBe(true); }); });