@@ -2,6 +2,7 @@ import { nextTestSetup } from 'e2e-utils'
22import { createRouterAct } from 'router-act'
33import { browserConfigWithFixedTime , fastForwardTo } from './test-utils'
44import path from 'path'
5+ import { Playwright } from 'next-webdriver'
56
67describe ( 'app dir client cache with parallel routes' , ( ) => {
78 const { next, isNextDev } = nextTestSetup ( {
@@ -14,6 +15,18 @@ describe('app dir client cache with parallel routes', () => {
1415 return
1516 }
1617
18+ async function reveal ( browser : Playwright , href : string ) {
19+ // Get the reveal element and scroll it into view.
20+ const reveal = await browser . elementByCss ( `[data-link-accordion="${ href } "]` )
21+ await reveal . scrollIntoViewIfNeeded ( )
22+
23+ // Click the reveal element to reveal the content.
24+ await reveal . click ( )
25+
26+ // Return the anchor link element.
27+ return browser . elementByCss ( `a[href="${ href } "]` )
28+ }
29+
1730 describe ( 'prefetch={true}' , ( ) => {
1831 it ( 'should prefetch the full page' , async ( ) => {
1932 let act : ReturnType < typeof createRouterAct >
@@ -27,11 +40,7 @@ describe('app dir client cache with parallel routes', () => {
2740 // Reveal the link to trigger prefetch and wait for it to complete
2841 const link = await act (
2942 async ( ) => {
30- const reveal = await browser . elementByCss (
31- '[data-link-accordion="/0"]'
32- )
33- await reveal . click ( )
34- return await browser . elementByCss ( '[href="/0"]' )
43+ return reveal ( browser , '/0' )
3544 } ,
3645 { includes : 'random-number' }
3746 )
@@ -55,11 +64,8 @@ describe('app dir client cache with parallel routes', () => {
5564 // Toggle the link, assert on the prefetch content
5665 const link = await act (
5766 async ( ) => {
58- const reveal = await browser . elementByCss (
59- '[data-link-accordion="/0"]'
60- )
61- await reveal . click ( )
62- return await browser . elementByCss ( '[href="/0"]' )
67+ await reveal ( browser , '/0' )
68+ return browser . elementByCss ( '[href="/0"]' )
6369 } ,
6470 { includes : 'random-number' }
6571 )
@@ -68,15 +74,13 @@ describe('app dir client cache with parallel routes', () => {
6874 const randomNumber = await act ( async ( ) => {
6975 await link . click ( )
7076 await browser . waitForElementByCss ( '#random-number' )
71- return await browser . elementByCss ( '#random-number' ) . text ( )
77+ return browser . elementByCss ( '#random-number' ) . text ( )
7278 } , 'no-requests' )
7379
7480 // Toggle the home link, assert on the homepage content
7581 const homeLink = await act (
7682 async ( ) => {
77- const reveal = await browser . elementByCss ( '[data-link-accordion="/"]' )
78- await reveal . click ( )
79- return await browser . elementByCss ( '[href="/"]' )
83+ return reveal ( browser , '/' )
8084 } ,
8185 { includes : 'home-page' }
8286 )
@@ -89,22 +93,18 @@ describe('app dir client cache with parallel routes', () => {
8993
9094 // Toggle the link to the other page again, navigate, assert no requests (because it's cached)
9195 const number = await act ( async ( ) => {
92- const reveal = await browser . elementByCss ( '[data-link-accordion="/0"]' )
93- await reveal . click ( )
94- const link = await browser . elementByCss ( '[href="/0"]' )
96+ const link = await reveal ( browser , '/0' )
9597 await link . click ( )
9698 await browser . waitForElementByCss ( '#random-number' )
97- return await browser . elementByCss ( '#random-number' ) . text ( )
99+ return browser . elementByCss ( '#random-number' ) . text ( )
98100 } , 'no-requests' )
99101
100102 expect ( number ) . toBe ( randomNumber )
101103
102104 // Navigate back home
103105 await act ( async ( ) => {
104- const reveal = await browser . elementByCss ( '[data-link-accordion="/"]' )
105- await reveal . click ( )
106- const homeLink = await browser . elementByCss ( '[href="/"]' )
107- await homeLink . click ( )
106+ const link = await reveal ( browser , '/' )
107+ await link . click ( )
108108 await browser . waitForElementByCss ( '#home-page' )
109109 } , 'no-requests' )
110110
@@ -114,11 +114,7 @@ describe('app dir client cache with parallel routes', () => {
114114 // Toggle the link to the other page again, assert on prefetch content
115115 const linkAfterExpiry = await act (
116116 async ( ) => {
117- const reveal = await browser . elementByCss (
118- '[data-link-accordion="/0"]'
119- )
120- await reveal . click ( )
121- return await browser . elementByCss ( '[href="/0"]' )
117+ return reveal ( browser , '/0' )
122118 } ,
123119 { includes : 'random-number' }
124120 )
@@ -127,7 +123,7 @@ describe('app dir client cache with parallel routes', () => {
127123 const newNumber = await act ( async ( ) => {
128124 await linkAfterExpiry . click ( )
129125 await browser . waitForElementByCss ( '#random-number' )
130- return await browser . elementByCss ( '#random-number' ) . text ( )
126+ return browser . elementByCss ( '#random-number' ) . text ( )
131127 } , 'no-requests' )
132128
133129 expect ( newNumber ) . not . toBe ( randomNumber )
0 commit comments