Skip to content

Commit 7c0965d

Browse files
authored
feat: E2E Tests with Playwright (#3430)
* initial commit for e2e * updated readme * activate only stackable for all tests * add tsconfig * add tests for settings page and editor page * add tests for site editor, global settings * minor change to tests for admin and block editor * use custom test utils * run tests * update playwright workflows * add .wp-env.json * add env * fix env slug * log plugins installed * update steps, slug * install playwright browsers * comment out site editor tests, add reporter * add try catch for newly installed plugin * update admin test * update stackable fixture * comment on PR * fix PR comment * add id for upload artifact, update comment body * update yml file * include site editor tests * minor update in yml file * always update comment * upload traces * test script * update comment content * get failed tests * use $GITHUB_OUTPUT * update to multiline * update output name * fix failed tests content * escape special characters * use markdown to output * run mto even on fail * strip Ansi Escapes * try multiple upload * test multiple upload * use test ids and trace file path * update reporter * test matrix * update .wp-env.json and name * update php version, remove unit tests * continue matrix even if one job fails * use different artifact name based on matrix * try all test env * remove comments, update matrix * update php version * update conditions, log wp and php version * add quotes * update php version * run other tests * test custom reporter * update condition * add report to summary * comment site editor tests temporarily * update report url * update wp version * update block editor test * use custom way to get block attributes * fix missing global settings for older wp versions * add comments, update tests * update tests * test with existing post * update command * use tests-cli * run wp-env first * update file path * check post content * update file path * update file path * update reporter * update locator for global settings block defaults * check if settings are open in editor, correct typo * update readme, global settings test * update failing tests in premium * update test to prevent flakiness * make sure global block default gets updated * update to default block page --------- Co-authored-by: [email protected] <>
1 parent 510b288 commit 7c0965d

File tree

4 files changed

+48
-12
lines changed

4 files changed

+48
-12
lines changed

e2e/readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ WP_BASE_URL=http://local.local/
3232
WP_AUTH_STORAGE=wp-auth.json
3333
WP_USERNAME=admin
3434
WP_PASSWORD=password
35+
STACKABLE_SLUG={ STACKABLE SLUG }
36+
WP_TEST_POSTID={ POST_ID }
37+
WP_STK_LICENSE={ STACKABLE LICENSE }
3538
```
3639

40+
In Freemius, make sure the license key is:
41+
- new
42+
- lifetime unlimited quota
43+
- has an owner
44+
- non-blocking and white-labeled
45+
3746
Run this command to run e2e:
3847

3948
```bash

e2e/tests/block-editor.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ test.describe( 'Block Editor', () => {
3939
} )
4040

4141
await editor.selectBlocks( editor.canvas.getByLabel( 'Block: Text' ) )
42+
43+
const settings = page.getByLabel( 'Settings', { exact: true } )
44+
45+
if ( await settings.getAttribute( 'aria-pressed' ) === 'false' ) {
46+
await settings.click()
47+
}
48+
4249
await expect( page.getByLabel( 'Layout Tab' ) ).toBeVisible()
4350
await expect( page.getByLabel( 'Style Tab' ) ).toBeVisible()
4451
await expect( page.getByLabel( 'Advanced Tab' ) ).toBeVisible()
@@ -52,6 +59,12 @@ test.describe( 'Block Editor', () => {
5259
name: 'stackable/text',
5360
} )
5461

62+
const settings = page.getByLabel( 'Settings', { exact: true } )
63+
64+
if ( await settings.getAttribute( 'aria-pressed' ) === 'false' ) {
65+
await settings.click()
66+
}
67+
5568
// Add content and color to Stackable Text Block
5669
await editor.canvas.locator( '[data-type="stackable/text"] > .stk-block-text > p[role="textbox"]' ).fill( 'test' )
5770
await page.locator( '.stk-color-palette-control .stk-control-content > .components-dropdown > .components-button' ).first().click()

e2e/tests/global-settings.spec.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { test, expect } from 'e2e/test-utils'
2-
import { createColor, getRgb } from '~stackable/plugins/global-settings/colors/util'
32

4-
test.describe( 'Global Settigs', () => {
3+
test.describe( 'Global Settings', () => {
54
let pid = null
65

76
// Create Posts for testing
@@ -62,7 +61,15 @@ test.describe( 'Global Settigs', () => {
6261

6362
// Delete added Global Color
6463
await page.getByLabel( 'Stackable Settings' ).click()
65-
await panel.locator( `.ugb-global-settings-color-picker__color-indicators > div > div:nth-child(${ count }) > button.stk-global-settings-color-picker__delete-button` ).click()
64+
65+
page.on( 'dialog', async dialog => await dialog.accept() )
66+
const deleteRequest = page.waitForResponse( response => response.url().includes( 'wp/v2/settings' ) && response.request().method() === 'POST' )
67+
68+
await globalColors.getByLabel( 'Delete' ).nth( count - 1 ).click()
69+
70+
await deleteRequest
71+
const _count = ( await globalColors.evaluate( node => Array.from( node.childNodes ) ) ).length
72+
expect( _count ).toBeLessThan( count )
6673
} )
6774

6875
test( 'Global Typography Styles should be applied when adding a heading', async ( {
@@ -93,18 +100,21 @@ test.describe( 'Global Settigs', () => {
93100

94101
await expect( editor.canvas.locator( '[data-type="stackable/heading"] > .stk-block-heading > h2[role="textbox"]' ) ).toHaveCSS( 'font-size', '32px' )
95102

96-
// Reset Global Typography Styles
97-
await page.getByLabel( 'Stackable Settings' ).click()
98-
await page.locator( '.ugb-global-settings-typography-control' ).nth( 1 ).getByRole( 'button', { name: 'Reset' } ).click()
103+
// Reset Global Typography Styles
104+
await page.getByLabel( 'Stackable Settings' ).click()
105+
106+
const resetButton = page.locator( '.ugb-global-settings-typography-control' ).nth( 1 ).getByLabel( 'Reset' )
107+
const deleteRequest = page.waitForResponse( response => response.url().includes( 'wp/v2/settings' ) && response.request().method() === 'POST' )
108+
await resetButton.click()
109+
110+
await deleteRequest
111+
await expect( resetButton ).not.toBeVisible()
99112
} )
100113

101114
test( 'When a default block is created, adding the block should have the default block\'s attributes', async ( {
102115
page,
103116
editor,
104117
} ) => {
105-
// Generate a color
106-
const color = createColor()
107-
108118
await page.getByLabel( 'Stackable Settings' ).click()
109119
await page.getByRole( 'button', { name: 'Block Defaults' } ).click()
110120

@@ -116,16 +126,20 @@ test.describe( 'Global Settigs', () => {
116126

117127
// Set a color for the default Text Block
118128
await defaultBlockPage.locator( '.stk-color-palette-control .stk-control-content > .components-dropdown > .components-button' ).first().click()
119-
await defaultBlockPage.getByLabel( 'Hex color' ).fill( color )
129+
await defaultBlockPage.getByLabel( 'Hex color' ).fill( 'ff0000' )
120130
await defaultBlockPage.locator( '.stk-color-palette-control .stk-control-content > .components-dropdown > .components-button' ).first().click()
121131

132+
const updateRequest = defaultBlockPage.waitForResponse( response => response.url().includes( 'update_block_style' ) && response.request().method() === 'POST' )
133+
122134
// In older WP versions, the button text is 'Update' instead of 'Save'
123135
if ( await defaultBlockPage.getByRole( 'button', { name: 'Save', exact: true } ).isVisible() ) {
124136
await defaultBlockPage.getByRole( 'button', { name: 'Save', exact: true } ).click()
125137
} else {
126138
await defaultBlockPage.getByRole( 'button', { name: 'Update' } ).click()
127139
}
128140

141+
// Make sure default block has been updated before closing the tab
142+
await updateRequest
129143
await defaultBlockPage.close()
130144

131145
// Insert a Stackable Text Block, and check if the color is the same as the one set in the default block
@@ -137,12 +151,11 @@ test.describe( 'Global Settigs', () => {
137151
},
138152
} )
139153

140-
await expect( editor.canvas.locator( '[data-type="stackable/text"] > .stk-block-text > p[role="textbox"]' ) ).toHaveCSS( 'color', `rgb(${ getRgb( color ) })` )
154+
await expect( editor.canvas.locator( '[data-type="stackable/text"] > .stk-block-text > p[role="textbox"]' ) ).toHaveCSS( 'color', 'rgb(255, 0, 0)' )
141155

142156
// Reset Default Block
143157
await page.getByLabel( 'Stackable Settings' ).click()
144158
await page.getByRole( 'button', { name: 'Block Defaults' } ).click()
145159
await page.locator( '.components-panel__body', { hasText: 'Block Defaults' } ).locator( '.stk-block-default-control', { hasText: /^Text$/ } ).first().getByLabel( 'Reset' ).click()
146160
} )
147161
} )
148-

src/components/sortable-picker/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ const LabeledItemIndicator = props => {
225225
) }
226226
/>
227227
<Button
228+
aria-label="Delete"
228229
className="stk-global-settings-color-picker__delete-button"
229230
icon="trash"
230231
isSmall

0 commit comments

Comments
 (0)