Compare commits

..

1 Commits

Author SHA1 Message Date
Kayssar Daher 2dca38796d Add test to cover longest URL match for nested site spaces 2026-11-02 15:59:01 +01:00
2 changed files with 26 additions and 1 deletions
+1 -1
View File
@@ -161,4 +161,4 @@ GitBook wouldn't be possible without these projects:
## Legacy GitBook (Deprecated)
Our previous version of GitBook and it's CLI tool are now deprecated. You can still view the old repository and it's commits on this [branch](https://github.com/GitbookIO/gitbook/tree/legacy).
Our previous version of GitBook and it's CLI tool are now deprecated. You can still view the old repository and it's commits on this [branch](https://github.com/GitbookIO/gitbook/tree/legacy).
+25
View File
@@ -14,6 +14,7 @@ import { createLinker } from './links';
import {
filterSiteSpacesByLocale,
findSiteSpaceBy,
findSiteSpaceByUrl,
getFallbackSiteSpacePath,
getLinkerForSiteSpace,
getSiteStructureSections,
@@ -114,6 +115,30 @@ describe('site structure traversal', () => {
});
});
describe('findSiteSpaceByUrl', () => {
const docsSpace = {
id: 'docs',
urls: { published: 'https://example.com/docs' },
} as SiteSpace;
const v2Space = {
id: 'v2',
urls: { published: 'https://example.com/docs/v2' },
} as SiteSpace;
it.each([
{ order: 'broader space first', spaces: [docsSpace, v2Space] },
{ order: 'nested space first', spaces: [v2Space, docsSpace] },
])('chooses the longest matching published URL with $order', ({ spaces }) => {
const match = findSiteSpaceByUrl(
{ type: 'siteSpaces', structure: spaces },
'https://example.com/docs/v2/install'
);
expect(match?.siteSpace).toBe(v2Space);
expect(match?.pagePath).toBe('install');
});
});
describe('filterSiteSpacesByLocale', () => {
it('returns all spaces on a single-language site', () => {
const spaces = [makeSiteSpace(undefined), makeSiteSpace(undefined)];