File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -270,7 +270,7 @@ describe('docTree', () => {
270270 expect ( getPreviousNode ( xA ) ) . toBe ( xB ) ;
271271 } ) ;
272272
273- test ( 'should not return siblings for root platform or guide paths' , ( ) => {
273+ test ( 'should return root as previous page for root platform or guide paths' , ( ) => {
274274 const platforms = createNode ( 'platforms' , 'Platforms' ) ;
275275 const js = createNode ( 'platforms/javascript' , 'JavaScript' ) ;
276276 const python = createNode ( 'platforms/python' , 'Python' ) ;
@@ -286,10 +286,10 @@ describe('docTree', () => {
286286 child . parent = js ;
287287 } ) ;
288288
289- expect ( getPreviousNode ( js ) ) . toBe ( undefined ) ;
290- expect ( getPreviousNode ( python ) ) . toBe ( undefined ) ;
291- expect ( getPreviousNode ( nextjs ) ) . toBe ( undefined ) ;
292- expect ( getPreviousNode ( angular ) ) . toBe ( undefined ) ;
289+ expect ( getPreviousNode ( js ) ) . toBe ( 'root' ) ;
290+ expect ( getPreviousNode ( python ) ) . toBe ( 'root' ) ;
291+ expect ( getPreviousNode ( nextjs ) ) . toBe ( 'root' ) ;
292+ expect ( getPreviousNode ( angular ) ) . toBe ( 'root' ) ;
293293 } ) ;
294294
295295 test ( 'should not return /platforms as previous page' , ( ) => {
Original file line number Diff line number Diff line change @@ -185,9 +185,10 @@ export const getNextNode = (node: DocNode): DocNode | undefined => {
185185 * Returns the previous node in the tree, which is either the last child of the parent,
186186 * the previous sibling, or the previous sibling of a parent node.
187187 */
188- export const getPreviousNode = ( node : DocNode ) : DocNode | undefined => {
188+ export const getPreviousNode = ( node : DocNode ) : DocNode | undefined | 'root' => {
189+ // in this special case, calculating the root node is unnecessary so we return a string instead
189190 if ( isRootPlatformPath ( node . path ) || isRootGuidePath ( node . path ) ) {
190- return undefined ;
191+ return 'root' ;
191192 }
192193
193194 const previousSibling = getPreviousSiblingNode ( node ) ;
You can’t perform that action at this time.
0 commit comments