-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1775 from Codeinwp/dev/e2e-tests
[Rock] Add more E2E tests
- Loading branch information
Showing
7 changed files
with
491 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { test, expect } from '@wordpress/e2e-test-utils-playwright'; | ||
|
||
test.describe( 'Accordion Block', () => { | ||
test.beforeEach( async({ admin }) => { | ||
await admin.createNewPost(); | ||
}); | ||
|
||
test( 'can be created by typing "/accordion"', async({ editor, page }) => { | ||
|
||
// Create a Progress Block with the slash block shortcut. | ||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await page.keyboard.type( '/accordion' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
const blocks = await editor.getBlocks(); | ||
const hasAccordion = blocks.some( ( block ) => 'themeisle-blocks/accordion' === block.name ); | ||
|
||
expect( hasAccordion ).toBeTruthy(); | ||
}); | ||
|
||
|
||
test( 'check if it has content by default', async({ editor, page }) => { | ||
await editor.insertBlock({ | ||
name: 'themeisle-blocks/accordion' | ||
}); | ||
|
||
let accordionBlock = ( await editor.getBlocks() ).find( ( block ) => 'themeisle-blocks/accordion' === block.name ); | ||
|
||
expect( accordionBlock.innerBlocks.length ).toBeGreaterThan( 0 ); | ||
}); | ||
|
||
test( 'add new item via button', async({ editor, page }) => { | ||
await editor.insertBlock({ | ||
name: 'themeisle-blocks/accordion' | ||
}); | ||
|
||
let accordionBlock = ( await editor.getBlocks() ).find( ( block ) => 'themeisle-blocks/accordion' === block.name ); | ||
|
||
const { clientId } = accordionBlock; | ||
const currentAccordionItems = accordionBlock.innerBlocks.length; | ||
|
||
await page.click( `#block-${clientId}` ); | ||
await page.getByRole( 'button', { name: 'Select Accordion' }).click(); | ||
|
||
await page.getByRole( 'button', { name: 'Add Accordion Item' }).click(); | ||
|
||
accordionBlock = ( await editor.getBlocks() ).find( ( block ) => 'themeisle-blocks/accordion' === block.name ); | ||
|
||
expect( accordionBlock.innerBlocks.length ).toBeGreaterThan( currentAccordionItems ); | ||
}); | ||
|
||
test( 'show/hide with default content', async({ editor, page }) => { | ||
await editor.insertBlock({ | ||
name: 'themeisle-blocks/accordion' | ||
}); | ||
|
||
let accordionBlock = ( await editor.getBlocks() ).find( ( block ) => 'themeisle-blocks/accordion' === block.name ); | ||
|
||
expect( accordionBlock.innerBlocks.length ).toBeGreaterThan( 0 ); | ||
|
||
const postId = await editor.publishPost(); | ||
|
||
await page.goto( `/?p=${postId}` ); | ||
|
||
// No tabs should be opened by default | ||
expect( await page.getByRole( 'paragraph' ).filter({ hasText: 'This is a placeholder tab content. It is important to have the necessary informa' }).isVisible() ).toBeFalsy(); | ||
|
||
// Open the first tab | ||
await page.locator( 'summary' ).filter({ hasText: 'Accordion title 1' }).click(); | ||
|
||
expect( await page.getByRole( 'paragraph' ).filter({ hasText: 'This is a placeholder tab content. It is important to have the necessary informa' }).isVisible() ).toBeTruthy(); | ||
|
||
// Close the first tab | ||
await page.locator( 'summary' ).filter({ hasText: 'Accordion title 1' }).click(); | ||
|
||
expect( await page.getByRole( 'paragraph' ).filter({ hasText: 'This is a placeholder tab content. It is important to have the necessary informa' }).isVisible() ).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { test, expect } from '@wordpress/e2e-test-utils-playwright'; | ||
|
||
test.describe( 'Countdown Block', () => { | ||
test.beforeEach( async({ admin }) => { | ||
await admin.createNewPost(); | ||
}); | ||
|
||
test( 'can be created by typing "/countdown"', async({ editor, page }) => { | ||
|
||
// Create a Progress Block with the slash block shortcut. | ||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await page.keyboard.type( '/countdown' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
const blocks = await editor.getBlocks(); | ||
const hasCountdown = blocks.some( ( block ) => 'themeisle-blocks/countdown' === block.name ); | ||
|
||
expect( hasCountdown ).toBeTruthy(); | ||
}); | ||
|
||
test( 'select a data and check the rendering', async({ editor, page }) => { | ||
await editor.insertBlock({ | ||
name: 'themeisle-blocks/countdown' | ||
}); | ||
|
||
let countdownBlock = ( await editor.getBlocks() ).find( ( block ) => 'themeisle-blocks/countdown' === block.name ); | ||
const otterId = countdownBlock.attributes.id; | ||
|
||
await page.getByRole( 'button', { name: 'Select Date' }).click(); | ||
|
||
await page.getByLabel( 'Day' ).fill( '17' ); | ||
await page.getByRole( 'combobox', { name: 'Month' }).selectOption( 'August' ); | ||
await page.getByLabel( 'Year' ).fill( '2030' ); | ||
|
||
await page.getByLabel( 'Year' ).press( 'Enter' ); | ||
|
||
// If everything is ok, the day label text should be changed to "Days". | ||
await expect( page.getByText( 'Days' ) ).toBeVisible(); | ||
|
||
await page.locator( '.editor-styles-wrapper' ).click(); | ||
const postId = await editor.publishPost(); | ||
|
||
await page.goto( `/?p=${postId}` ); | ||
|
||
expect( ( await page.$eval( `#${otterId}`, ( el ) => el.getAttribute( 'data-date' ) ) ).startsWith( '2030-08-17' ) ).toBeTruthy(); | ||
|
||
// If everything is ok, the day label text should be changed to "Days". | ||
await expect( page.getByText( 'Days' ) ).toBeVisible(); | ||
|
||
// Capture the current value of the seconds. | ||
const currentValue = await page.locator( '.otter-countdown__display-area' ) | ||
.filter({ | ||
hasText: 'Seconds' | ||
}) | ||
.locator( '.otter-countdown__value' ) | ||
.innerHTML(); | ||
|
||
// Wait for 1 second for the seconds to change. | ||
await page.waitForTimeout( 1000 ); | ||
|
||
// Capture the new value of the seconds. | ||
const newValue = await page.locator( '.otter-countdown__display-area' ) | ||
.filter({ | ||
hasText: 'Seconds' | ||
}) | ||
.locator( '.otter-countdown__value' ) | ||
.innerHTML(); | ||
|
||
// Check if the new value is different from the old one. | ||
expect( currentValue ).not.toEqual( newValue ); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { test, expect } from '@wordpress/e2e-test-utils-playwright'; | ||
|
||
test.describe( 'Section Block', () => { | ||
test.beforeEach( async({ admin }) => { | ||
await admin.createNewPost(); | ||
}); | ||
|
||
test( 'can be created by typing "/section"', async({ editor, page }) => { | ||
|
||
// Create a Progress Block with the slash block shortcut. | ||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await page.keyboard.type( '/section' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
const blocks = await editor.getBlocks(); | ||
const hasSection = blocks.some( ( block ) => 'themeisle-blocks/advanced-columns' === block.name ); | ||
|
||
expect( hasSection ).toBeTruthy(); | ||
}); | ||
|
||
test( 'can be created by typing "/section" and choose Single Column', async({ editor, page }) => { | ||
|
||
// Create a Progress Block with the slash block shortcut. | ||
await page.click( 'role=button[name="Add default block"i]' ); | ||
await page.keyboard.type( '/section' ); | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
const hasSection = ( await editor.getBlocks() ).some( ( block ) => 'themeisle-blocks/advanced-columns' === block.name ); | ||
|
||
expect( hasSection ).toBeTruthy(); | ||
|
||
await page.getByRole( 'button', { name: 'Single column' }).click(); | ||
|
||
const blocks = await editor.getBlocks(); | ||
|
||
const sectionBlock = blocks.find( ( block ) => 'themeisle-blocks/advanced-columns' === block.name ); | ||
|
||
// Check if w have a column in innerBlocks | ||
expect( sectionBlock.innerBlocks.length ).toBe( 1 ); | ||
}); | ||
|
||
test( 'add new column', async({ editor, page }) => { | ||
await editor.insertBlock({ | ||
name: 'themeisle-blocks/advanced-columns', | ||
innerBlocks: [ | ||
{ | ||
name: 'themeisle-blocks/advanced-column' | ||
} | ||
] | ||
}); | ||
|
||
let sectionBlock = ( await editor.getBlocks() ).find( ( block ) => 'themeisle-blocks/advanced-columns' === block.name ); | ||
|
||
const { clientId } = sectionBlock; | ||
|
||
await page.click( `#block-${clientId}` ); | ||
|
||
const columnController = page.getByRole( 'spinbutton', { name: 'Columns' }); | ||
|
||
await columnController.click(); | ||
|
||
// Press the up arrow one time | ||
await columnController.press( 'ArrowUp' ); | ||
|
||
sectionBlock = ( await editor.getBlocks() ).find( ( block ) => 'themeisle-blocks/advanced-columns' === block.name ); | ||
|
||
expect( sectionBlock.innerBlocks.length ).toBe( 2 ); | ||
}); | ||
|
||
test( 'delete one column', async({ editor, page }) => { | ||
await editor.insertBlock({ | ||
name: 'themeisle-blocks/advanced-columns', | ||
innerBlocks: [ | ||
{ | ||
name: 'themeisle-blocks/advanced-column' | ||
}, | ||
{ | ||
name: 'themeisle-blocks/advanced-column' | ||
} | ||
] | ||
}); | ||
|
||
let sectionBlock = ( await editor.getBlocks() ).find( ( block ) => 'themeisle-blocks/advanced-columns' === block.name ); | ||
|
||
const { clientId } = sectionBlock; | ||
|
||
await page.click( `#block-${clientId}` ); | ||
|
||
const columnController = page.getByRole( 'spinbutton', { name: 'Columns' }); | ||
|
||
await columnController.click(); | ||
|
||
// Press the up arrow one time | ||
await columnController.press( 'ArrowDown' ); | ||
|
||
sectionBlock = ( await editor.getBlocks() ).find( ( block ) => 'themeisle-blocks/advanced-columns' === block.name ); | ||
|
||
expect( sectionBlock.innerBlocks.length ).toBe( 1 ); | ||
}); | ||
}); |
Oops, something went wrong.