|
| 1 | +describe('Frame', () => { |
| 2 | + beforeEach(() => { |
| 3 | + cy.visit('/'); |
| 4 | + }); |
| 5 | + |
| 6 | + it('should be possible to move the elements around in the frame', () => { |
| 7 | + // at the start the root should have 4 elements |
| 8 | + cy.getByTestId('root-container') |
| 9 | + .as('root-container') |
| 10 | + .children() |
| 11 | + .should('have.length', 4); |
| 12 | + |
| 13 | + // we want to drop the "Click me" Button inside the CardBottom |
| 14 | + // before that the CardBottom should only have one button |
| 15 | + cy.getByTestId('card-bottom') |
| 16 | + .as('card-bottom') |
| 17 | + .children() |
| 18 | + .should('have.length', 1); |
| 19 | + // we verify that the button is draggable and drop it inside the CardBottom |
| 20 | + cy.getByTestId('frame-button') |
| 21 | + .should('have.attr', 'draggable', 'true') |
| 22 | + .dragAndDrop('@card-bottom', { |
| 23 | + position: 'inside', |
| 24 | + }); |
| 25 | + // CardBottom now should have 2 elements |
| 26 | + cy.get('@card-bottom').children().should('have.length', 2); |
| 27 | + |
| 28 | + // we want to drop the "Hi world!" Text as second element in the CardTop |
| 29 | + // before that we verify that CardTop has two children |
| 30 | + cy.getByTestId('card-top') |
| 31 | + .as('card-top') |
| 32 | + .children() |
| 33 | + .should('have.length', 2); |
| 34 | + |
| 35 | + cy.getByTestId('card-top-text-1').as('card-top-text-1'); |
| 36 | + cy.getByTestId('frame-text') |
| 37 | + .should('have.attr', 'draggable', 'true') |
| 38 | + .dragAndDrop('@card-top-text-1', { |
| 39 | + position: 'below', |
| 40 | + }); |
| 41 | + cy.get('@card-top').children().should('have.length', 3); |
| 42 | + |
| 43 | + // the root should now only have 2 children (the Card and the Container) |
| 44 | + cy.get('@root-container').children().should('have.length', 2); |
| 45 | + |
| 46 | + // we now want to drop the Card inside the Container |
| 47 | + cy.getByTestId('frame-container') |
| 48 | + .as('frame-container') |
| 49 | + .children() |
| 50 | + .should('have.length', 1); |
| 51 | + cy.getByTestId('frame-card').dragAndDrop('@frame-container', { |
| 52 | + position: 'inside', |
| 53 | + }); |
| 54 | + cy.get('@frame-container').children().should('have.length', 2); |
| 55 | + cy.get('@root-container').children().should('have.length', 1); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should not be possible to drag anything inside the frame when the editor is disabled', () => { |
| 59 | + // we disable the editor |
| 60 | + cy.contains('Enable').click(); |
| 61 | + |
| 62 | + // no element should be draggable |
| 63 | + cy.getByTestId('frame-card').should('have.attr', 'draggable', 'false'); |
| 64 | + cy.getByTestId('card-top-text-1').should('have.attr', 'draggable', 'false'); |
| 65 | + cy.getByTestId('card-top-text-2').should('have.attr', 'draggable', 'false'); |
| 66 | + cy.getByTestId('card-bottom-button').should( |
| 67 | + 'have.attr', |
| 68 | + 'draggable', |
| 69 | + 'false' |
| 70 | + ); |
| 71 | + cy.getByTestId('frame-button').should('have.attr', 'draggable', 'false'); |
| 72 | + cy.getByTestId('frame-text').should('have.attr', 'draggable', 'false'); |
| 73 | + cy.getByTestId('frame-container').should('have.attr', 'draggable', 'false'); |
| 74 | + cy.getByTestId('frame-container-text').should( |
| 75 | + 'have.attr', |
| 76 | + 'draggable', |
| 77 | + 'false' |
| 78 | + ); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should be possible to delete every element', () => { |
| 82 | + // to keep it DRY we use this simple helper |
| 83 | + const deleteByTestId = (testId: string) => { |
| 84 | + cy.getByTestId(testId).click(); |
| 85 | + cy.contains('Delete').click(); |
| 86 | + }; |
| 87 | + |
| 88 | + // these calls all follow the same schema: |
| 89 | + // 1. verify that the container has a certain number of children before we delete |
| 90 | + // 2. select the element we want to delete |
| 91 | + // 3. delete the element |
| 92 | + // 4. verify that the container now has one less element |
| 93 | + |
| 94 | + cy.getByTestId('root-container') |
| 95 | + .as('root-container') |
| 96 | + .children() |
| 97 | + .should('have.length', 4); |
| 98 | + |
| 99 | + cy.getByTestId('card-top').children().should('have.length', 2); |
| 100 | + deleteByTestId('card-top-text-1'); |
| 101 | + deleteByTestId('card-top-text-2'); |
| 102 | + cy.getByTestId('card-top').children().should('have.length', 0); |
| 103 | + |
| 104 | + cy.getByTestId('card-bottom').children().should('have.length', 1); |
| 105 | + deleteByTestId('card-bottom-button'); |
| 106 | + cy.getByTestId('card-bottom').children().should('have.length', 0); |
| 107 | + |
| 108 | + deleteByTestId('frame-card'); |
| 109 | + cy.get('@root-container').children().should('have.length', 3); |
| 110 | + |
| 111 | + deleteByTestId('frame-button'); |
| 112 | + cy.get('@root-container').children().should('have.length', 2); |
| 113 | + |
| 114 | + deleteByTestId('frame-text'); |
| 115 | + cy.get('@root-container').children().should('have.length', 1); |
| 116 | + |
| 117 | + cy.getByTestId('frame-container').children().should('have.length', 1); |
| 118 | + deleteByTestId('frame-container-text'); |
| 119 | + cy.getByTestId('frame-container').children().should('have.length', 0); |
| 120 | + |
| 121 | + deleteByTestId('frame-container'); |
| 122 | + cy.get('@root-container').children().should('have.length', 0); |
| 123 | + }); |
| 124 | + |
| 125 | + it('should not be possible to delete an element when the editor is disabled', () => { |
| 126 | + // first we disable the editor |
| 127 | + cy.contains('Enable').click(); |
| 128 | + |
| 129 | + // then we check that the SettingsPanel does not open for any of the elements |
| 130 | + [ |
| 131 | + 'card-top-text-1', |
| 132 | + 'card-top-text-2', |
| 133 | + 'card-bottom-button', |
| 134 | + 'card-top', |
| 135 | + 'card-bottom', |
| 136 | + 'frame-card', |
| 137 | + 'frame-button', |
| 138 | + 'frame-text', |
| 139 | + 'frame-container-text', |
| 140 | + 'frame-container', |
| 141 | + ].forEach((testId) => { |
| 142 | + cy.getByTestId(testId).click(); |
| 143 | + cy.contains('Delete').should('not.exist'); |
| 144 | + }); |
| 145 | + }); |
| 146 | +}); |
0 commit comments