@@ -112,6 +112,40 @@ test.describe('View Transitions', () => {
112112 ) . toEqual ( 2 ) ;
113113 } ) ;
114114
115+ test ( 'Moving within a page without ViewTransitions does not trigger a full page navigation' , async ( {
116+ page,
117+ astro,
118+ } ) => {
119+ const loads = [ ] ;
120+ page . addListener ( 'load' , async ( p ) => {
121+ loads . push ( p . title ( ) ) ;
122+ } ) ;
123+ // Go to page 1
124+ await page . goto ( astro . resolveUrl ( '/one' ) ) ;
125+ let p = page . locator ( '#one' ) ;
126+ await expect ( p , 'should have content' ) . toHaveText ( 'Page 1' ) ;
127+
128+ // Go to page 3 which does *not* have ViewTransitions enabled
129+ await page . click ( '#click-three' ) ;
130+ p = page . locator ( '#three' ) ;
131+ await expect ( p , 'should have content' ) . toHaveText ( 'Page 3' ) ;
132+
133+ // click a hash link to navigate further down the page
134+ await page . click ( '#click-hash' ) ;
135+ // still on page 3
136+ p = page . locator ( '#three' ) ;
137+ await expect ( p , 'should have content' ) . toHaveText ( 'Page 3' ) ;
138+
139+ // check that we are further down the page
140+ const Y = await page . evaluate ( ( ) => window . scrollY ) ;
141+ expect ( Y , 'The target is further down the page' ) . toBeGreaterThan ( 0 ) ;
142+
143+ expect (
144+ loads . length ,
145+ 'There should be only 1 page load. The original, but no additional loads for the hash change'
146+ ) . toEqual ( 1 ) ;
147+ } ) ;
148+
115149 test ( 'Moving from a page without ViewTransitions w/ back button' , async ( { page, astro } ) => {
116150 const loads = [ ] ;
117151 page . addListener ( 'load' , ( p ) => {
@@ -332,4 +366,34 @@ test.describe('View Transitions', () => {
332366
333367 await expect ( loads . length , 'There should only be 1 page load' ) . toEqual ( 1 ) ;
334368 } ) ;
369+
370+ test ( 'Importing ViewTransitions w/o using the component must not mess with history' , async ( {
371+ page,
372+ astro,
373+ } ) => {
374+ const loads = [ ] ;
375+ page . addListener ( 'load' , async ( p ) => {
376+ loads . push ( p ) ;
377+ } ) ;
378+ // Go to the half bakeed page
379+ await page . goto ( astro . resolveUrl ( '/half-baked' ) ) ;
380+ let p = page . locator ( '#half-baked' ) ;
381+ await expect ( p , 'should have content' ) . toHaveText ( 'Half Baked' ) ;
382+
383+ // click a hash link to navigate further down the page
384+ await page . click ( '#click-hash' ) ;
385+ // still on page
386+ p = page . locator ( '#half-baked' ) ;
387+ await expect ( p , 'should have content' ) . toHaveText ( 'Half Baked' ) ;
388+
389+ // go back within same page without reloading
390+ await page . goBack ( ) ;
391+ p = page . locator ( '#half-baked' ) ;
392+ await expect ( p , 'should have content' ) . toHaveText ( 'Half Baked' ) ;
393+
394+ expect (
395+ loads . length ,
396+ 'There should be only 1 page load. No additional loads for going back on same page'
397+ ) . toEqual ( 1 ) ;
398+ } ) ;
335399} ) ;
0 commit comments