import fc from 'fast-check'; import { describe, expect, it } from 'vitest'; import sitePages from '../src/sitePages'; import { routePath } from '../src/test/arbitraries'; import { NOT_FOUND_FILE, NOT_FOUND_PATH, pageFile, pagePath, } from './pageFiles'; describe('pageFile', () => { it.each([ ['/', 'index.html'], ['/over-mij', 'over-mij.html'], ['/soorten-fotoshoots', 'soorten-fotoshoots.html'], ['/soorten-fotoshoots/newborn', 'soorten-fotoshoots/newborn.html'], [NOT_FOUND_PATH, NOT_FOUND_FILE], ])('%s staat in %s', (path, file) => { expect(pageFile(path)).toBe(file); }); it('begint nooit met een slash en eindigt op .html (invariant)', () => { fc.assert( fc.property(routePath, (path) => { const file = pageFile(path); expect(file.startsWith('/')).toBe(false); expect(file.endsWith('.html')).toBe(true); }), ); }); }); describe('pagePath', () => { it.each([ ['index.html', '/'], ['over-mij.html', '/over-mij'], ['soorten-fotoshoots/newborn.html', '/soorten-fotoshoots/newborn'], ])('%s hoort bij %s', (file, path) => { expect(pagePath(file)).toBe(path); }); it.each([ ['404.html', 'de 404-pagina is geen pagina uit het register'], ['assets/index-abc.js', 'geen html'], ['sitemap.xml', 'geen html'], ['over-mij.htm', 'andere extensie'], ['over-mij', 'zonder extensie'], ['.html', 'zonder naam'], ['/over-mij.html', 'met voorste slash'], ])('%s is geen paginabestand (%s)', (file) => { expect(pagePath(file)).toBeUndefined(); }); it('geeft index.html voor /index, dus /index is geen eigen pagina', () => { expect(pageFile('/index')).toBe('index.html'); expect(pagePath(pageFile('/index'))).toBe('/'); }); }); describe('pageFile en pagePath samen', () => { it('geven elk pad uit het register terug (round-trip)', () => { for (const path of Object.keys(sitePages)) { expect(pagePath(pageFile(path))).toBe(path); } }); it('geven elk routepad terug (round-trip)', () => { fc.assert( fc.property( // /index valt samen met het bestand van / (zie hierboven) routePath.filter((path) => path !== '/index'), (path) => { expect(pagePath(pageFile(path))).toBe(path); }, ), ); }); it('geven aan de 404-pagina geen pad terug', () => { expect(pageFile(NOT_FOUND_PATH)).toBe(NOT_FOUND_FILE); expect(pagePath(NOT_FOUND_FILE)).toBeUndefined(); }); });