|
| 1 | +import { test, expect } from '@wordpress/e2e-test-utils-playwright' |
| 2 | + |
| 3 | +import { deletePost } from 'e2e/test-utils' |
| 4 | +import { createColor, getRgb } from '~stackable/plugins/global-settings/colors/util' |
| 5 | + |
| 6 | +test.describe( 'Global Settigs', () => { |
| 7 | + let pid = null |
| 8 | + |
| 9 | + // Create Posts for testing |
| 10 | + test.beforeEach( async ( { editor, admin } ) => { |
| 11 | + await admin.createNewPost( { title: 'Global Settings Test' } ) |
| 12 | + await editor.saveDraft() |
| 13 | + const postQuery = new URL( editor.page.url() ).search |
| 14 | + pid = new URLSearchParams( postQuery ).get( 'post' ) |
| 15 | + } ) |
| 16 | + |
| 17 | + // Delete created post |
| 18 | + test.afterEach( async ( { requestUtils } ) => { |
| 19 | + await deletePost( requestUtils, pid ) |
| 20 | + } ) |
| 21 | + |
| 22 | + test( 'When a color is added in the Global Colors, it should be present in the color picker', async ( { |
| 23 | + page, |
| 24 | + editor, |
| 25 | + } ) => { |
| 26 | + await page.getByLabel( 'Stackable Settings' ).click() |
| 27 | + |
| 28 | + // Add a new Global Color |
| 29 | + const panel = page.locator( '.ugb-global-settings-color-picker ' ).filter( { hasText: 'Global Colors' } ) |
| 30 | + await panel.locator( 'button.ugb-global-settings-color-picker__add-button' ).click() |
| 31 | + |
| 32 | + const globalColors = panel.locator( '.ugb-global-settings-color-picker__color-indicators > div' ) |
| 33 | + const count = ( await globalColors.evaluate( node => Array.from( node.childNodes ) ) ).length |
| 34 | + |
| 35 | + const newColor = globalColors.getByRole( 'button', { name: `Custom Color ${ count } ` } ) |
| 36 | + await expect( newColor ).toBeVisible() |
| 37 | + await newColor.click() |
| 38 | + const hexValue = await page.getByLabel( 'Hex color' ).inputValue() |
| 39 | + |
| 40 | + // Insert a Stackable Text Block and check if the added Global Colors is in the color picker |
| 41 | + await page.getByLabel( 'Settings', { exact: true } ).click() |
| 42 | + editor.insertBlock( { |
| 43 | + name: 'stackable/text', |
| 44 | + attributes: { |
| 45 | + text: 'test', |
| 46 | + }, |
| 47 | + } ) |
| 48 | + await page.locator( '.stk-color-palette-control .stk-control-content > .components-dropdown > .components-button' ).first().click() |
| 49 | + |
| 50 | + await expect( page.getByRole( 'heading', { name: 'Global Colors' } ) ).toBeVisible() |
| 51 | + await expect( page.getByLabel( `Color: Custom Color ${ count }` ) ).toBeVisible() |
| 52 | + await page.getByLabel( `Color: Custom Color ${ count }` ).click() |
| 53 | + await expect( page.getByLabel( 'Hex color' ) ).toHaveValue( hexValue ) |
| 54 | + await page.locator( '.stk-color-palette-control .stk-control-content > .components-dropdown > .components-button' ).first().click() |
| 55 | + |
| 56 | + // Delete added Global Color |
| 57 | + await page.getByLabel( 'Stackable Settings' ).click() |
| 58 | + await panel.locator( `.ugb-global-settings-color-picker__color-indicators > div > div:nth-child(${ count }) > button.stk-global-settings-color-picker__delete-button` ).click() |
| 59 | + } ) |
| 60 | + |
| 61 | + test( 'Global Typography Styles should be applied when adding a heading', async ( { |
| 62 | + page, |
| 63 | + editor, |
| 64 | + } ) => { |
| 65 | + await page.getByLabel( 'Stackable Settings' ).click() |
| 66 | + await page.getByRole( 'button', { name: 'Global Typography' } ).click() |
| 67 | + |
| 68 | + // Set Global Typography Styles of Heading 2 to have a font-size of 32 |
| 69 | + await page.locator( '.ugb-global-settings-typography-control' ).nth( 1 ).locator( '.components-base-control__field > .ugb-button-icon-control__wrapper > .components-button' ).click() |
| 70 | + await page.locator( '.stk-popover .components-base-control:nth-of-type(2)', { hasText: /Size/ } ).getByRole( 'textbox' ).fill( '32' ) |
| 71 | + await page.locator( '.ugb-global-settings-typography-control' ).nth( 1 ).locator( '.components-base-control__field > .ugb-button-icon-control__wrapper > .components-button' ).click() |
| 72 | + await expect( page.getByRole( 'heading', { name: 'Heading 2' } ) ).toHaveCSS( 'font-size', '32px' ) |
| 73 | + await page.getByLabel( 'Settings', { exact: true } ).click() |
| 74 | + |
| 75 | + // Check if the added Stackable Heading Block has a font-size of 32 |
| 76 | + editor.insertBlock( { |
| 77 | + name: 'stackable/heading', |
| 78 | + attributes: { |
| 79 | + text: 'test', |
| 80 | + }, |
| 81 | + } ) |
| 82 | + |
| 83 | + await expect( editor.canvas.locator( '[data-type="stackable/heading"] > .stk-block-heading > h2[role="textbox"]' ) ).toHaveCSS( 'font-size', '32px' ) |
| 84 | + |
| 85 | + // Reset Global Typography Styles |
| 86 | + await page.getByLabel( 'Stackable Settings' ).click() |
| 87 | + await page.locator( '.ugb-global-settings-typography-control' ).nth( 1 ).getByRole( 'button', { name: 'Reset' } ).click() |
| 88 | + } ) |
| 89 | + |
| 90 | + test( 'When a default block is created, adding the block should have the default block\'s attributes', async ( { |
| 91 | + page, |
| 92 | + editor, |
| 93 | + } ) => { |
| 94 | + // Generate a color |
| 95 | + const color = createColor() |
| 96 | + |
| 97 | + await page.getByLabel( 'Stackable Settings' ).click() |
| 98 | + await page.getByRole( 'button', { name: 'Block Defaults' } ).click() |
| 99 | + |
| 100 | + // Open the Default Text Block Editor |
| 101 | + const defaultBlockPagePromise = page.waitForEvent( 'popup' ) |
| 102 | + await page.locator( 'div:nth-child(37) > .components-base-control__field > .ugb-button-icon-control__wrapper > .components-button' ).click() |
| 103 | + const defaultBlockPage = await defaultBlockPagePromise |
| 104 | + |
| 105 | + // Set a color for the default Text Block |
| 106 | + await defaultBlockPage.locator( '.stk-color-palette-control .stk-control-content > .components-dropdown > .components-button' ).first().click() |
| 107 | + await defaultBlockPage.getByLabel( 'Hex color' ).fill( color ) |
| 108 | + await defaultBlockPage.locator( '.stk-color-palette-control .stk-control-content > .components-dropdown > .components-button' ).first().click() |
| 109 | + await defaultBlockPage.getByRole( 'button', { name: 'Save', exact: true } ).click() |
| 110 | + await defaultBlockPage.close() |
| 111 | + |
| 112 | + // Insert a Stackable Text Block, and check if the color is the same as the one set in the default block |
| 113 | + await page.reload() |
| 114 | + await editor.insertBlock( { |
| 115 | + name: 'stackable/text', |
| 116 | + attributes: { |
| 117 | + text: 'test', |
| 118 | + }, |
| 119 | + } ) |
| 120 | + |
| 121 | + await expect( editor.canvas.locator( '[data-type="stackable/text"] > .stk-block-text > p[role="textbox"]' ) ).toHaveCSS( 'color', `rgb(${ getRgb( color ) })` ) |
| 122 | + |
| 123 | + // Reset Default Block |
| 124 | + await page.getByLabel( 'Stackable Settings' ).click() |
| 125 | + await page.getByRole( 'button', { name: 'Block Defaults' } ).click() |
| 126 | + await page.locator( 'div' ).filter( { hasText: /^Text$/ } ).first().getByLabel( 'Reset' ).click() |
| 127 | + } ) |
| 128 | +} ) |
| 129 | + |
0 commit comments