11import { describe , it , expect } from 'vitest'
2- import { findPageBreadcrumb , findPageChildren , findPageSiblings } from '@nuxt/content/utils'
2+ import { findPageBreadcrumb , findPageChildren , findPageSiblings , findPageHeadline } from '@nuxt/content/utils'
33
44describe ( 'utils' , ( ) => {
55 const navigation = [
@@ -32,6 +32,48 @@ describe('utils', () => {
3232 } ,
3333 ]
3434
35+ const navigation2 = [
36+ {
37+ title : 'Guide Dir' ,
38+ path : '/guide' ,
39+ stem : 'guide' ,
40+ children : [
41+ {
42+ title : 'Guide Index' ,
43+ path : '/guide' ,
44+ stem : 'guide/index' ,
45+ } ,
46+ {
47+ title : 'Getting Started Dir' ,
48+ path : '/guide/getting-started' ,
49+ stem : 'guide/getting-started' ,
50+ children : [
51+ {
52+ title : 'Getting Started Index' ,
53+ path : '/guide/getting-started' ,
54+ stem : 'guide/getting-started/index' ,
55+ } ,
56+ {
57+ title : 'Getting Started 1' ,
58+ path : '/guide/getting-started/1' ,
59+ stem : 'guide/getting-started/1' ,
60+ } ,
61+ {
62+ title : 'Getting Started 2' ,
63+ path : '/guide/getting-started/2' ,
64+ stem : 'guide/getting-started/2' ,
65+ } ,
66+ ] ,
67+ } ,
68+ {
69+ title : 'Introduction' ,
70+ path : '/guide/introduction' ,
71+ stem : 'guide/introduction' ,
72+ } ,
73+ ] ,
74+ } ,
75+ ]
76+
3577 function removeChildren ( array ) {
3678 return array . map ( ( obj ) => {
3779 const { children, ...rest } = obj
@@ -116,9 +158,9 @@ describe('utils', () => {
116158 } )
117159
118160 it ( 'findPageChildren' , async ( ) => {
119- const breadcrumb = removeChildren ( findPageChildren ( navigation , '/guide' ) )
161+ const pages = removeChildren ( findPageChildren ( navigation , '/guide' ) )
120162
121- expect ( breadcrumb ) . toEqual ( [
163+ expect ( pages ) . toEqual ( [
122164 {
123165 title : 'Getting Started' ,
124166 path : '/guide/getting-started' ,
@@ -133,9 +175,9 @@ describe('utils', () => {
133175 } )
134176
135177 it ( 'findPageChildren with indexAsChild option' , async ( ) => {
136- const breadcrumb = removeChildren ( findPageChildren ( navigation , '/guide' , { indexAsChild : true } ) )
178+ const pages = removeChildren ( findPageChildren ( navigation , '/guide' , { indexAsChild : true } ) )
137179
138- expect ( breadcrumb ) . toEqual ( [
180+ expect ( pages ) . toEqual ( [
139181 {
140182 title : 'Guide Index' ,
141183 path : '/guide' ,
@@ -155,9 +197,9 @@ describe('utils', () => {
155197 } )
156198
157199 it ( 'findPageSiblings' , async ( ) => {
158- const breadcrumb = removeChildren ( findPageSiblings ( navigation , '/guide/getting-started' ) )
200+ const pages = removeChildren ( findPageSiblings ( navigation , '/guide/getting-started' ) )
159201
160- expect ( breadcrumb ) . toEqual ( [
202+ expect ( pages ) . toEqual ( [
161203 {
162204 title : 'Introduction' ,
163205 path : '/guide/introduction' ,
@@ -167,9 +209,9 @@ describe('utils', () => {
167209 } )
168210
169211 it ( 'findPageSiblings with indexAsChild option' , async ( ) => {
170- const breadcrumb = removeChildren ( findPageSiblings ( navigation , '/guide/getting-started' , { indexAsChild : true } ) )
212+ const pages = removeChildren ( findPageSiblings ( navigation , '/guide/getting-started' , { indexAsChild : true } ) )
171213
172- expect ( breadcrumb ) . toEqual ( [
214+ expect ( pages ) . toEqual ( [
173215 {
174216 title : 'Guide Index' ,
175217 path : '/guide' ,
@@ -182,4 +224,30 @@ describe('utils', () => {
182224 } ,
183225 ] )
184226 } )
227+
228+ it ( 'findPageHeadline' , async ( ) => {
229+ const headline = findPageHeadline ( navigation2 , '/guide/getting-started' )
230+
231+ expect ( headline ) . toEqual ( 'Guide Dir' )
232+ } )
233+
234+ it ( 'findPageHeadline for index with indexAsChild' , async ( ) => {
235+ const headline = findPageHeadline ( navigation2 , '/guide' , { indexAsChild : true } )
236+
237+ expect ( headline ) . toEqual ( 'Guide Dir' )
238+
239+ const headline2 = findPageHeadline ( navigation2 , '/guide/getting-started' , { indexAsChild : true } )
240+
241+ expect ( headline2 ) . toEqual ( 'Getting Started Dir' )
242+ } )
243+
244+ it ( 'findPageHeadline for index without indexAsChild' , async ( ) => {
245+ const headline = findPageHeadline ( navigation2 , '/guide' )
246+
247+ expect ( headline ) . toEqual ( undefined )
248+
249+ const headline2 = findPageHeadline ( navigation2 , '/guide/getting-started' )
250+
251+ expect ( headline2 ) . toEqual ( 'Guide Dir' )
252+ } )
185253} )
0 commit comments