|
| 1 | +import { test, expect } from '@wordpress/e2e-test-utils-playwright' |
| 2 | + |
| 3 | +test( 'Stackable blocks can be added in the editor', async ( { |
| 4 | + page, |
| 5 | + admin, |
| 6 | + editor, |
| 7 | +} ) => { |
| 8 | + await admin.createNewPost() |
| 9 | + await page.getByLabel( 'Toggle block inserter' ).click() |
| 10 | + |
| 11 | + await page.locator( '.editor-block-list-item-stackable-text' ).click() |
| 12 | + |
| 13 | + const blocks = await editor.getBlocks() |
| 14 | + |
| 15 | + expect( blocks[ 0 ].name ).toContain( 'stackable/text' ) |
| 16 | +} ) |
| 17 | + |
| 18 | +test( 'Stackable Inspector Controls should show up upon clicking a Stackable block', async ( { |
| 19 | + page, |
| 20 | + admin, |
| 21 | + editor, |
| 22 | +} ) => { |
| 23 | + await admin.createNewPost() |
| 24 | + |
| 25 | + await editor.insertBlock( { |
| 26 | + name: 'stackable/text', |
| 27 | + } ) |
| 28 | + |
| 29 | + await editor.selectBlocks( page.locator( 'iframe[name="editor-canvas"]' ).contentFrame().getByLabel( 'Block: Text' ) ) |
| 30 | + await expect( page.getByLabel( 'Layout Tab' ) ).toBeVisible() |
| 31 | + await expect( page.getByLabel( 'Style Tab' ) ).toBeVisible() |
| 32 | + await expect( page.getByLabel( 'Advanced Tab' ) ).toBeVisible() |
| 33 | +} ) |
| 34 | + |
| 35 | +test( 'A Stackable block\'s attributes should update when settings are changed in the Inspector Controls.', async ( { |
| 36 | + page, |
| 37 | + admin, |
| 38 | + editor, |
| 39 | +} ) => { |
| 40 | + await admin.createNewPost() |
| 41 | + |
| 42 | + await editor.insertBlock( { |
| 43 | + name: 'stackable/text', |
| 44 | + } ) |
| 45 | + |
| 46 | + const editorCanvas = page.locator( 'iframe[name="editor-canvas"]' ).contentFrame() |
| 47 | + await editorCanvas.locator( '[data-type="stackable/text"] > .stk-block-text > p[role="textbox"]' ).fill( 'test' ) |
| 48 | + await page.locator( '.stk-color-palette-control .stk-control-content > .components-dropdown > .components-button' ).first().click() |
| 49 | + await page.getByLabel( 'Hex color' ).fill( 'ff0000' ) |
| 50 | + await editorCanvas.locator( 'body' ).click() |
| 51 | + |
| 52 | + await expect( editorCanvas.locator( '[data-type="stackable/text"]' ) ).toContainText( 'test' ) |
| 53 | + await expect( editorCanvas.locator( '[data-type="stackable/text"] > .stk-block-text > p[role="textbox"]' ) ).toHaveCSS( 'color', 'rgb(255, 0, 0)' ) |
| 54 | + |
| 55 | + await editor.saveDraft() |
| 56 | + |
| 57 | + const blocks = await editor.getBlocks() |
| 58 | + const attributes = blocks[ 0 ].attributes |
| 59 | + |
| 60 | + expect( attributes.textColor1 ).toBe( '#ff0000' ) |
| 61 | + expect( attributes.text ).toBe( 'test' ) |
| 62 | +} ) |
| 63 | + |
| 64 | +test( 'The Stackable block added in the editor should be visible in the frontend', async ( { |
| 65 | + admin, |
| 66 | + editor, |
| 67 | +} ) => { |
| 68 | + await admin.createNewPost() |
| 69 | + |
| 70 | + await editor.insertBlock( { |
| 71 | + name: 'stackable/text', |
| 72 | + attributes: { |
| 73 | + text: 'test', |
| 74 | + textColor1: '#ff0000', |
| 75 | + }, |
| 76 | + } ) |
| 77 | + |
| 78 | + const blocks = await editor.getBlocks() |
| 79 | + const uniqueId = blocks[ 0 ].attributes.uniqueId |
| 80 | + |
| 81 | + await editor.saveDraft() |
| 82 | + |
| 83 | + const preview = await editor.openPreviewPage() |
| 84 | + |
| 85 | + await expect( preview.locator( `[data-block-id="${ uniqueId }"]` ) ).toBeVisible() |
| 86 | + await expect( preview.locator( `[data-block-id="${ uniqueId }"]` ) ).toContainText( 'test' ) |
| 87 | + await expect( preview.locator( `[data-block-id="${ uniqueId }"] p` ) ).toHaveCSS( 'color', 'rgb(255, 0, 0)' ) |
| 88 | +} ) |
0 commit comments