|
| 1 | +/// <reference types="Cypress" /> |
| 2 | + |
| 3 | +const NEW_TAB_REL_DEFAULT_VALUE = 'noreferrer noopener'; |
| 4 | + |
| 5 | +describe( 'Button Block', () => { |
| 6 | + beforeEach( () => { |
| 7 | + cy.loginUser(); |
| 8 | + cy.createNewPost(); |
| 9 | + } ); |
| 10 | + |
| 11 | + it( 'Button block should be initialized with default attributes', () => { |
| 12 | + cy.insertButtonBlock(); |
| 13 | + cy.selectButtonBlock(); |
| 14 | + |
| 15 | + // Editor content should match snapshot |
| 16 | + cy.postContentMatchesSnapshot(); |
| 17 | + } ); |
| 18 | + |
| 19 | + it( 'Should be possible to set link url and text', () => { |
| 20 | + cy.insertButtonBlock(); |
| 21 | + cy.selectButtonBlock(); |
| 22 | + |
| 23 | + // Set button text |
| 24 | + cy.get( |
| 25 | + '[aria-label="Add text..."].block-editor-rich-text__editable' |
| 26 | + ).type( 'Liip' ); |
| 27 | + |
| 28 | + // Editor content should match snapshot |
| 29 | + cy.postContentMatchesSnapshot(); |
| 30 | + |
| 31 | + // Set button url |
| 32 | + cy.get( 'input[aria-label="URL"]' ).type( 'https://liip.ch' ); |
| 33 | + |
| 34 | + // Editor content should match snapshot |
| 35 | + cy.postContentMatchesSnapshot(); |
| 36 | + } ); |
| 37 | + |
| 38 | + it( 'Should be possible to select style', () => { |
| 39 | + cy.insertButtonBlock(); |
| 40 | + cy.selectButtonBlock(); |
| 41 | + cy.ensureSidebarOpened(); |
| 42 | + |
| 43 | + // Style option should be applied |
| 44 | + cy.getSelectByLabel( 'Style' ).select( 'secondary' ); |
| 45 | + |
| 46 | + // Editor content should match snapshot |
| 47 | + cy.postContentMatchesSnapshot(); |
| 48 | + } ); |
| 49 | + |
| 50 | + it( 'Should be possible to change alignment', () => { |
| 51 | + cy.insertButtonBlock(); |
| 52 | + cy.selectButtonBlock(); |
| 53 | + |
| 54 | + // Change alignment |
| 55 | + cy.clickBlockToolbarButton( 'Change button alignment' ); |
| 56 | + cy.clickButton( 'Align text center' ); |
| 57 | + cy.get( |
| 58 | + '.block-editor-block-list__block[data-type="wp-bootstrap-blocks/button"][data-alignment="center"]' |
| 59 | + ).should( 'exist' ); |
| 60 | + |
| 61 | + // Editor content should match snapshot |
| 62 | + cy.postContentMatchesSnapshot(); |
| 63 | + } ); |
| 64 | + |
| 65 | + it( 'Should be possible to enable and disable open in new tab', () => { |
| 66 | + cy.insertButtonBlock(); |
| 67 | + cy.selectButtonBlock(); |
| 68 | + cy.ensureSidebarOpened(); |
| 69 | + |
| 70 | + // Enable open in new tab |
| 71 | + cy.clickElementByText( 'label', 'Open in new tab' ); |
| 72 | + |
| 73 | + // Check if default rel value is set |
| 74 | + cy.getTextControlByLabel( 'Link rel' ).should( |
| 75 | + 'have.value', |
| 76 | + NEW_TAB_REL_DEFAULT_VALUE |
| 77 | + ); |
| 78 | + |
| 79 | + // Editor content should match snapshot |
| 80 | + cy.postContentMatchesSnapshot(); |
| 81 | + |
| 82 | + // Disable open in new tab |
| 83 | + cy.clickElementByText( 'label', 'Open in new tab' ); |
| 84 | + |
| 85 | + // Check if default rel value is removed |
| 86 | + cy.getTextControlByLabel( 'Link rel' ).should( 'have.value', '' ); |
| 87 | + |
| 88 | + // Editor content should match snapshot |
| 89 | + cy.postContentMatchesSnapshot(); |
| 90 | + } ); |
| 91 | + |
| 92 | + it( 'Should keep rel value if set when open in new tab is enabled or disabled', () => { |
| 93 | + cy.insertButtonBlock(); |
| 94 | + cy.selectButtonBlock(); |
| 95 | + cy.ensureSidebarOpened(); |
| 96 | + |
| 97 | + const customRelValue = 'custom rel value'; |
| 98 | + |
| 99 | + // Enable no gutters option |
| 100 | + cy.setTextControlValueByLabel( 'Link rel', customRelValue ); |
| 101 | + |
| 102 | + // Enable open in new tab |
| 103 | + cy.clickElementByText( 'label', 'Open in new tab' ); |
| 104 | + |
| 105 | + // Check if rel value hasn't changed |
| 106 | + cy.getTextControlByLabel( 'Link rel' ).should( |
| 107 | + 'have.value', |
| 108 | + customRelValue |
| 109 | + ); |
| 110 | + |
| 111 | + // Editor content should match snapshot |
| 112 | + cy.postContentMatchesSnapshot(); |
| 113 | + |
| 114 | + // Disable open in new tab |
| 115 | + cy.clickElementByText( 'label', 'Open in new tab' ); |
| 116 | + |
| 117 | + // Check if rel value hasn't changed |
| 118 | + cy.getTextControlByLabel( 'Link rel' ).should( |
| 119 | + 'have.value', |
| 120 | + customRelValue |
| 121 | + ); |
| 122 | + |
| 123 | + // Editor content should match snapshot |
| 124 | + cy.postContentMatchesSnapshot(); |
| 125 | + } ); |
| 126 | +} ); |
0 commit comments