Skip to content

Commit

Permalink
test(e2e): add Modal and Popup anchor check
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Aug 7, 2024
1 parent ce610a5 commit f981a59
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/blocks/test/e2e/blocks/modal.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* WordPress dependencies
*/
import { test, expect } from '@wordpress/e2e-test-utils-playwright';

test.describe( 'Modal', () => {
test.beforeEach( async({ admin }) => {
await admin.createNewPost();
});

test( 'anchor to a button', async({ editor, page }) => {
await editor.insertBlock({
name: 'core/buttons',
attributes: {},
innerBlocks: [
{
name: 'core/button',
attributes: {
text: 'Open Modal',
anchor: 'modal-trigger'
}
}
]
});

await editor.insertBlock({
name: 'themeisle-blocks/modal',
attributes: {
anchor: 'modal-trigger'
},
innerBlocks: [
{
name: 'core/paragraph',
attributes: {
content: 'Popup Content Test'
}
}
]
});

const postId = await editor.publishPost();
await page.goto( `/?p=${postId}` );

await page.locator( 'div' ).filter({ hasText: /^Open Modal$/ }).click();

await expect( page.getByText( 'Popup Content Test' ) ).toBeVisible();
});

test( 'close on escape', async({ editor, page }) => {

await editor.insertBlock({
name: 'core/buttons',
attributes: {},
innerBlocks: [
{
name: 'core/button',
attributes: {
text: 'Open Modal',
anchor: 'modal-trigger'
}
}
]
});

await editor.insertBlock({
name: 'themeisle-blocks/modal',
attributes: {
anchor: 'modal-trigger'
},
innerBlocks: [
{
name: 'core/paragraph',
attributes: {
content: 'Popup Content Test'
}
}
]
});

const postId = await editor.publishPost();
await page.goto( `/?p=${postId}` );

await page.locator( 'div' ).filter({ hasText: /^Open Modal$/ }).click();

await expect( page.getByText( 'Popup Content Test' ) ).toBeVisible();
await page.keyboard.press( 'Escape' );
await expect( page.getByText( 'Popup Content Test' ) ).toBeHidden();
});
});
39 changes: 39 additions & 0 deletions src/blocks/test/e2e/blocks/popup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,45 @@ test.describe( 'Popup', () => {
await admin.createNewPost();
});

test( 'anchor to a button', async({ editor, page }) => {
await editor.insertBlock({
name: 'core/buttons',
attributes: {},
innerBlocks: [
{
name: 'core/button',
attributes: {
text: 'Open Popup',
anchor: 'popup-trigger'
}
}
]
});

await editor.insertBlock({
name: 'themeisle-blocks/popup',
attributes: {
anchor: 'popup-trigger',
trigger: 'onClick'
},
innerBlocks: [
{
name: 'core/paragraph',
attributes: {
content: 'Popup Content Test'
}
}
]
});

const postId = await editor.publishPost();
await page.goto( `/?p=${postId}` );

await page.locator( 'div' ).filter({ hasText: /^Open Popup$/ }).click();

await expect( page.getByText( 'Popup Content Test' ) ).toBeVisible();
});

test( 'close on escape', async({ editor, page }) => {

await editor.insertBlock({
Expand Down

0 comments on commit f981a59

Please sign in to comment.