Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test in window events
Browse files Browse the repository at this point in the history
cbravobernal committed Apr 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 4173531 commit 656a2d6
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -21,4 +21,8 @@
<p data-wp-text="state.counter" data-testid="counter">0</p>
</div>
</div>
<div data-wp-on-window--resize="actions.resizeHandler" data-wp-on-window--resize--second="actions.resizeSecondHandler">
<p data-wp-text="state.resizeHandler" data-testid="resizeHandler">no</p>
<p data-wp-text="state.resizeSecondHandler" data-testid="resizeSecondHandler">no</p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -25,6 +25,8 @@ const { state } = store( 'directive-on-window', {
counter: 0,
isVisible: true,
isEventAttached: 'no',
resizeHandler: 'no',
resizeSecondHandler: 'no',
},
callbacks: {
resizeHandler() {
@@ -39,5 +41,11 @@ const { state } = store( 'directive-on-window', {
state.isEventAttached = 'no';
state.isVisible = ! state.isVisible;
},
resizeHandler: () => {
state.resizeHandler = 'yes';
},
resizeSecondHandler: () => {
state.resizeSecondHandler = 'yes';
}
}
} );
21 changes: 21 additions & 0 deletions test/e2e/specs/interactivity/directive-on-window.spec.ts
Original file line number Diff line number Diff line change
@@ -65,4 +65,25 @@ test.describe( 'data-wp-on-window', () => {
await page.setViewportSize( { width: 200, height: 600 } );
await expect( counter ).toHaveText( '2' );
} );
test( 'should work with multiple event handlers on the same event type', async ( {
page,
} ) => {
const resizeHandler = page.getByTestId( 'resizeHandler' );
const resizeSecondHandler = page.getByTestId( 'resizeSecondHandler' );

// Initial value.
await expect( resizeHandler ).toHaveText( 'no' );
await expect( resizeSecondHandler ).toHaveText( 'no' );

// Make sure the event listener is attached.
await page
.getByTestId( 'isEventAttached' )
.filter( { hasText: 'yes' } )
.waitFor();

// This keyboard press should increase the counter.
await page.setViewportSize( { width: 600, height: 600 } );
await expect( resizeHandler ).toHaveText( 'yes' );
await expect( resizeSecondHandler ).toHaveText( 'yes' );
} );
} );

0 comments on commit 656a2d6

Please sign in to comment.