Skip to content

Commit

Permalink
Add failing test for URLs with hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
DAreRodz committed Sep 6, 2023
1 parent 43556a0 commit 83ae05f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
data-wp-on--click="actions.router.navigate"
href="$link"
>link $i</a>
<a
data-testid="link $i with hash"
data-wp-on--click="actions.router.navigate"
data-force-navigation="true"
href="$link#link-$i-with-hash"
>link $i with hash</a>
HTML;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
state.router.navigations += 1;
state.router.status = 'busy';

await navigate( e.target.href );
const force = e.target.dataset.forceNavigation === 'true';

await navigate( e.target.href, { force } );

state.router.navigations -= 1;

Expand Down
52 changes: 52 additions & 0 deletions test/e2e/specs/interactivity/router-navigate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,56 @@ test.describe( 'Router navigate', () => {
await expect( status ).toHaveText( 'idle' );
await expect( title ).toHaveText( 'Link 2' );
} );

test( 'should update the URL from the last navigation if only varies in the URL fragment', async ( {
page,
interactivityUtils: utils,
} ) => {
const link1 = utils.getLink( 'router navigate - link 1' );

const navigations = page.getByTestId( 'router navigations' );
const status = page.getByTestId( 'router status' );
const title = page.getByTestId( 'title' );

await expect( navigations ).toHaveText( '0' );
await expect( status ).toHaveText( 'idle' );

const resolvers: Function[] = [];

await page.route( link1, async ( route ) => {
await new Promise( ( r ) => resolvers.push( r ) );
await route.continue();
} );

await page.getByTestId( 'link 1' ).click();
await page.getByTestId( 'link 1 with hash' ).click();

const href = ( await page
.getByTestId( 'link 1 with hash' )
.getAttribute( 'href' ) ) as string;

await expect( navigations ).toHaveText( '2' );
await expect( status ).toHaveText( 'busy' );
await expect( title ).toHaveText( 'Main' );

{
const resolver = resolvers.pop();
if ( resolver ) resolver();
}

await expect( navigations ).toHaveText( '1' );
await expect( status ).toHaveText( 'busy' );
await expect( title ).toHaveText( 'Link 1' );
await expect( page ).toHaveURL( href );

{
const resolver = resolvers.pop();
if ( resolver ) resolver();
}

await expect( navigations ).toHaveText( '0' );
await expect( status ).toHaveText( 'idle' );
await expect( title ).toHaveText( 'Link 1' );
await expect( page ).toHaveURL( href );
} );
} );

0 comments on commit 83ae05f

Please sign in to comment.