60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import { test } from '@japa/runner'
|
|
import {
|
|
ancestorPaths,
|
|
ancestorsAlreadyLoaded,
|
|
BREADCRUMB_PARENT_GROUP_KEYS,
|
|
} from '#base_modules/WebManager/services/breadcrumb_paths'
|
|
import { BREADCRUMB_PAGE_TYPE_PARENTS } from '#base_modules/WebManager/config/general'
|
|
|
|
/**
|
|
* These decide which rows the breadcrumb query asks for. Miss a path here and the trail
|
|
* silently loses a level, because the walk can only choose from what was loaded.
|
|
*/
|
|
test.group('Web Manager breadcrumb candidate paths', () => {
|
|
test('climbs every shorter prefix, longest first, then home', ({ assert }) => {
|
|
assert.deepEqual(ancestorPaths('blog/post/hello'), ['blog/post', 'blog', ''])
|
|
})
|
|
|
|
test('never offers the page itself as its own parent', ({ assert }) => {
|
|
assert.notInclude(ancestorPaths('about'), 'about')
|
|
assert.notInclude(ancestorPaths('blog/post'), 'blog/post')
|
|
})
|
|
|
|
test('a top-level page and the home page both fall back to home', ({ assert }) => {
|
|
assert.deepEqual(ancestorPaths('about'), [''])
|
|
assert.deepEqual(ancestorPaths(''), [''])
|
|
})
|
|
|
|
test('tolerates stray slashes in a stored path', ({ assert }) => {
|
|
assert.deepEqual(ancestorPaths('/blog/post/'), ancestorPaths('blog/post'))
|
|
assert.deepEqual(ancestorPaths('/blog/post/'), ['blog', ''])
|
|
})
|
|
|
|
test('covers the group keys a page type can be re-parented onto', ({ assert }) => {
|
|
assert.includeMembers(BREADCRUMB_PARENT_GROUP_KEYS, Object.values(BREADCRUMB_PAGE_TYPE_PARENTS))
|
|
assert.equal(
|
|
BREADCRUMB_PARENT_GROUP_KEYS.length,
|
|
new Set(BREADCRUMB_PARENT_GROUP_KEYS).size,
|
|
'duplicate group keys would widen the query for nothing'
|
|
)
|
|
})
|
|
})
|
|
|
|
test.group('Web Manager breadcrumb candidate reuse', () => {
|
|
test('walking up a prefix reuses the rows already loaded', ({ assert }) => {
|
|
assert.isTrue(ancestorsAlreadyLoaded('blog/post', ['blog/post/hello']))
|
|
assert.isTrue(ancestorsAlreadyLoaded('blog', ['blog/post/hello']))
|
|
assert.isTrue(ancestorsAlreadyLoaded('', ['blog/post/hello']))
|
|
assert.isTrue(ancestorsAlreadyLoaded('blog/post/hello', ['blog/post/hello']))
|
|
})
|
|
|
|
test('a jump to an unrelated branch needs its own query', ({ assert }) => {
|
|
assert.isFalse(ancestorsAlreadyLoaded('company/blog', ['news/hello']))
|
|
assert.isFalse(ancestorsAlreadyLoaded('blog', []))
|
|
})
|
|
|
|
test('does not mistake a shared name prefix for an ancestor', ({ assert }) => {
|
|
assert.isFalse(ancestorsAlreadyLoaded('blogging', ['blog/post']))
|
|
})
|
|
})
|