@@ -3,6 +3,8 @@ import { test, expect } from '@playwright/test';
33import { waitForIsland } from './helpers.mjs' ;
44
55const ARTICLE = '/learn/getting-started/introduction-to-nodejs' ;
6+ const EVENT_LOOP_ARTICLE =
7+ '/learn/asynchronous-work/event-loop-timers-and-nexttick' ;
68
79/**
810 * The theme is applied in an effect after the menu item is clicked, so use a
@@ -54,6 +56,63 @@ test.describe('Navigation', () => {
5456 await expect ( page . getByRole ( 'heading' , { level : 1 } ) ) . toBeVisible ( ) ;
5557 } ) ;
5658
59+ test ( 'renders previous and next article links in sidebar order' , async ( {
60+ page,
61+ } ) => {
62+ await page . goto ( EVENT_LOOP_ARTICLE ) ;
63+
64+ const navigation = page . getByRole ( 'navigation' , {
65+ name : 'Article navigation' ,
66+ } ) ;
67+ const previous = navigation . getByRole ( 'link' , { name : / P r e v i o u s / } ) ;
68+ const next = navigation . getByRole ( 'link' , { name : / N e x t / } ) ;
69+
70+ await expect ( previous ) . toContainText (
71+ 'Overview of Blocking vs Non-Blocking'
72+ ) ;
73+ await expect ( previous ) . toHaveAttribute (
74+ 'href' ,
75+ '/learn/asynchronous-work/overview-of-blocking-vs-non-blocking'
76+ ) ;
77+ await expect ( next ) . toContainText ( 'The Node.js Event Emitter' ) ;
78+ await expect ( next ) . toHaveAttribute (
79+ 'href' ,
80+ '/learn/asynchronous-work/the-nodejs-event-emitter'
81+ ) ;
82+ } ) ;
83+
84+ test ( 'continues article navigation across sidebar groups' , async ( {
85+ page,
86+ } ) => {
87+ await page . goto ( '/learn/asynchronous-work/dont-block-the-event-loop' ) ;
88+
89+ const navigation = page . getByRole ( 'navigation' , {
90+ name : 'Article navigation' ,
91+ } ) ;
92+ const next = navigation . getByRole ( 'link' , { name : / N e x t / } ) ;
93+
94+ await expect ( next ) . toContainText ( 'Comparing Node.js concurrency models' ) ;
95+ await expect ( next ) . toHaveAttribute (
96+ 'href' ,
97+ '/learn/concurrency/comparing-nodejs-concurrency-models'
98+ ) ;
99+ } ) ;
100+
101+ test ( 'uses leaf article order for nested sidebar sections' , async ( {
102+ page,
103+ } ) => {
104+ await page . goto ( '/learn/diagnostics/memory' ) ;
105+
106+ const navigation = page . getByRole ( 'navigation' , {
107+ name : 'Article navigation' ,
108+ } ) ;
109+ const previous = navigation . getByRole ( 'link' , { name : / P r e v i o u s / } ) ;
110+ const next = navigation . getByRole ( 'link' , { name : / N e x t / } ) ;
111+
112+ await expect ( previous ) . toContainText ( 'User Journey' ) ;
113+ await expect ( next ) . toContainText ( 'Understanding and Tuning Memory' ) ;
114+ } ) ;
115+
57116 test ( 'unknown pages respond with 404' , async ( { page } ) => {
58117 // Only the status is checked: which 404 page renders depends on the host
59118 // (nodejs.org proxies /learn, previews and `serve` use their own).
@@ -124,6 +183,46 @@ test.describe('Small screens', () => {
124183 await expect ( page ) . toHaveURL ( new RegExp ( `${ ARTICLE } $` ) ) ;
125184 } ) ;
126185
186+ test ( 'the first article shows next without an empty mobile slot' , async ( {
187+ page,
188+ } ) => {
189+ await page . goto ( ARTICLE ) ;
190+
191+ const navigation = page . getByRole ( 'navigation' , {
192+ name : 'Article navigation' ,
193+ } ) ;
194+ await navigation . scrollIntoViewIfNeeded ( ) ;
195+
196+ await expect (
197+ navigation . getByRole ( 'link' , { name : / P r e v i o u s / } )
198+ ) . toHaveCount ( 0 ) ;
199+ await expect ( navigation . getByRole ( 'link' , { name : / N e x t / } ) ) . toContainText (
200+ 'How much JavaScript do you need to know to use Node.js?'
201+ ) ;
202+ await expect ( navigation . locator ( ':scope > div:empty' ) ) . toBeHidden ( ) ;
203+ } ) ;
204+
205+ test ( 'article navigation moves to the next article from the bottom' , async ( {
206+ page,
207+ } ) => {
208+ await page . goto ( EVENT_LOOP_ARTICLE ) ;
209+
210+ const navigation = page . getByRole ( 'navigation' , {
211+ name : 'Article navigation' ,
212+ } ) ;
213+ await navigation . scrollIntoViewIfNeeded ( ) ;
214+
215+ const next = navigation . getByRole ( 'link' , { name : / N e x t / } ) ;
216+ await expect ( next ) . toBeVisible ( ) ;
217+ await expect ( next ) . toContainText ( 'The Node.js Event Emitter' ) ;
218+
219+ await next . click ( ) ;
220+
221+ await expect ( page ) . toHaveURL (
222+ / \/ l e a r n \/ a s y n c h r o n o u s - w o r k \/ t h e - n o d e j s - e v e n t - e m i t t e r $ /
223+ ) ;
224+ } ) ;
225+
127226 test ( 'the menu button reveals the site links' , async ( { page } ) => {
128227 await page . goto ( ARTICLE ) ;
129228
0 commit comments