/* eslint-env jest */ import type { NavItem } from '../../../lib/navigation/nav-model'; import { buildVisibleNav, seoOnlyHome, type VisibleNavOptions, } from '../nav-config'; const routes = (options: VisibleNavOptions): string[] => { const all: string[] = []; const walk = (items: NavItem[]): void => items.forEach(item => { if (item.to) all.push(item.to); if (item.children) walk(item.children); }); buildVisibleNav(options).sections.forEach(section => walk(section.items)); return all; }; describe('the rows a merchant sees', () => { it('keeps SEO → Analytics out until the site may open it', () => { expect(routes({ canSeeSeoAnalytics: false })).not.toContain( '/seo/analytics' ); expect(routes({ canSeeSeoAnalytics: true })).toContain('/seo/analytics'); }); it('shows the shop rows only with WooCommerce, however deep they sit', () => { const shop = routes({ hasWooCommerce: true }); expect(shop).toContain('/prices'); expect(shop).toContain('/seo/general?section=woocommerce'); const blog = routes({ hasWooCommerce: false }); expect(blog).not.toContain('/prices'); expect(blog).not.toContain('/seo/general?section=woocommerce'); }); it('takes the whole Commerce group away without WooCommerce', () => { const blog = routes({ hasWooCommerce: false, canSeeBulkUpload: true }); for (const page of [ '/catalog-quality', '/content-generator', '/product-improvements', '/agentic-feed', '/import', ]) { expect(blog).not.toContain(page); } expect(blog).toContain('/ai-visibility/contents'); const shop = routes({ hasWooCommerce: true, canSeeBulkUpload: true }); expect(shop).toContain('/catalog-quality'); expect(shop).toContain('/import'); expect(shop).not.toContain('/agentic-feed'); }); it('keeps the content checker, under Content Studio, without a shop', () => { const studio = (hasWooCommerce: boolean): string[] => ( buildVisibleNav({ hasWooCommerce }) .sections.flatMap(section => section.items) .find(item => item.menuKey === 'content-studio')?.children ?? [] ).map(item => item.to ?? ''); expect(studio(false)).toContain('/content-generator/content-checker'); expect(studio(true)).not.toContain('/content-generator/content-checker'); expect(routes({ hasWooCommerce: true })).toContain( '/content-generator/content-checker' ); }); it('drops the setup steps once they are behind the site', () => { expect(routes({ seoSetupDone: false })).toContain('/seo/setup'); expect(routes({ seoSetupDone: true })).not.toContain('/seo/setup'); }); }); describe('a site Recomaze has not opened the SEO module to', () => { it('shows no SEO page, and keeps llms.txt on a page of its own', () => { const without = routes({ seoEnabled: false }); expect(without.filter(to => to.startsWith('/seo'))).toEqual([]); expect(without).toContain('/llm'); expect(without).toContain('/ai-visibility'); const opened = routes({ seoEnabled: true }); expect(opened).toContain('/seo/general?section=llms'); expect(opened).not.toContain('/llm'); }); }); describe('the pages of the SEO modules', () => { it('leave the menu while their module is off', () => { const shown = routes({ seoModules: { redirects: false, monitor_404: true, role_manager: false }, }); expect(shown).not.toContain('/seo/redirects'); expect(shown).not.toContain('/seo/roles'); expect(shown).toContain('/seo/404'); }); it('all stay while the states are not known yet', () => { const shown = routes({}); [ '/seo/redirects', '/seo/404', '/seo/links', '/seo/local', '/seo/roles', ].forEach(route => expect(shown).toContain(route)); }); }); describe('a role given SEO pages alone', () => { const redirects = ['recomaze_seo_redirects', 'recomaze_seo_404']; it('sees the SEO pages it holds and nothing that needs the account', () => { const shown = routes({ seoOnly: true, seoCaps: redirects, canSeeSeoAnalytics: true, hasWooCommerce: true, }); expect(shown).toContain('/seo/redirects'); expect(shown).toContain('/seo/404'); expect(shown).not.toContain('/seo/general'); expect(shown).not.toContain('/seo/analytics'); expect(shown).not.toContain('/hq'); expect(shown).not.toContain('/catalog-quality'); expect(buildVisibleNav({ seoOnly: true }).utilityItems).toEqual([]); }); it('keeps the settings pages but not the role manager or Analytics', () => { const shown = routes({ seoOnly: true, seoCaps: ['recomaze_seo_settings', 'recomaze_seo_analytics'], canSeeSeoAnalytics: true, }); expect(shown).toContain('/seo/general'); expect(shown).toContain('/seo/checkup'); expect(shown).not.toContain('/seo/roles'); expect(shown).not.toContain('/seo/analytics'); }); it('lands on the first page it may open', () => { expect(seoOnlyHome(['recomaze_seo_settings'])).toBe('/seo'); expect(seoOnlyHome(redirects)).toBe('/seo/redirects'); expect(seoOnlyHome(['recomaze_seo_404'])).toBe('/seo/404'); expect(seoOnlyHome(['recomaze_seo_sitemap'])).toBe('/seo/sitemap'); }); });