Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test to test data-wp-interactive topmost behaviour
  • Loading branch information
luisherranz authored and DAreRodz committed Jun 4, 2025
commit 68d079b22a74f79eff31e27548b6f89565093af5
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
>not hydrated</p>
</div>


<section>
<h2>Region 2</h2>
<div
Expand All @@ -74,7 +73,7 @@
data-wp-on--click="actions.counter.increment"
>NaN</button>

<div data-wp-ignore>
<div>
<div>
<p
data-testid="no-region-text-2"
Expand All @@ -92,10 +91,11 @@
content from page <?php echo $attributes['page']; ?>
</p>

<ul
data-wp-interactive="router-regions"
data-wp-router-region="nested-region-2"
>
<button data-testid="add-item" data-wp-on--click="actions.addItem">
Add item
</button>

<ul>
<template data-wp-each="state.items">
<li data-testid="nested-item" data-wp-key="context.item" data-wp-text="context.item"></li>
</template>
Expand All @@ -107,4 +107,17 @@
</section>
</div>
</div>
</section>
</section>

<div data-wp-interactive="router-regions">
<div data-wp-router-region="invalid-region-1">
<p data-testid="invalid-region-text-1">
content from page <?php echo $attributes['page']; ?>
</p>
</div>
<div data-wp-interactive="router-regions" data-wp-router-region="invalid-region-2">
<p data-testid="invalid-region-text-2">
content from page <?php echo $attributes['page']; ?>
</p>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ const { state } = store( 'router-regions', {
}
},
},
addItem() {
state.items.push( `item ${ state.items.length + 1 }` );
},
},
} );
34 changes: 31 additions & 3 deletions test/e2e/specs/interactivity/router-regions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ test.describe( 'Router regions', () => {
const region1Text = page.getByTestId( 'region-1-text' );
const region2Text = page.getByTestId( 'region-2-text' );
const noRegionText1 = page.getByTestId( 'no-region-text-1' );
const noRegionText2 = page.getByTestId( 'no-region-text-2' );

await expect( region1Text ).toHaveText( 'hydrated' );
await expect( region2Text ).toHaveText( 'hydrated' );
await expect( noRegionText1 ).toHaveText( 'not hydrated' );
await expect( noRegionText2 ).toHaveText( 'not hydrated' );
} );

test( 'should update after navigation', async ( { page } ) => {
Expand Down Expand Up @@ -97,10 +95,12 @@ test.describe( 'Router regions', () => {
await page.getByTestId( 'next' ).click();
await expect( nestedRegionSsr ).toHaveText( 'content from page 2' );
await expect( innerContent ).toHaveCount( 3 );
await page.getByTestId( 'add-item' ).click();
await expect( innerContent ).toHaveCount( 4 );

await page.getByTestId( 'back' ).click();
await expect( nestedRegionSsr ).toHaveText( 'content from page 1' );
await expect( innerContent ).toHaveCount( 3 );
await expect( innerContent ).toHaveCount( 4 );
} );

test( 'Page title is updated 2', async ( { page } ) => {
Expand All @@ -116,4 +116,32 @@ test.describe( 'Router regions', () => {
'router regions – page 1 – gutenberg'
);
} );

test( 'should not take into account regions that are not in the topmost `data-wp-interactive`.', async ( {
page,
} ) => {
const invalidRegionText1 = page.getByTestId( 'invalid-region-text-1' );
const invalidRegionText2 = page.getByTestId( 'invalid-region-text-2' );

await expect( invalidRegionText1 ).toHaveText( 'content from page 1' );
await expect( invalidRegionText2 ).toHaveText( 'content from page 1' );

await page.getByTestId( 'next' ).click();
// Waits until the navigation finishes so it doesn't read the text from
// the previous page.
await expect( page ).toHaveTitle(
'router regions – page 2 – gutenberg'
);
await expect( invalidRegionText1 ).toHaveText( 'content from page 1' );
await expect( invalidRegionText2 ).toHaveText( 'content from page 1' );

await page.getByTestId( 'back' ).click();
// Waits until the navigation finishes so it doesn't read the text from
// the previous page.
await expect( page ).toHaveTitle(
'router regions – page 1 – gutenberg'
);
await expect( invalidRegionText1 ).toHaveText( 'content from page 1' );
await expect( invalidRegionText2 ).toHaveText( 'content from page 1' );
} );
} );