|
| 1 | +describe('createContent Tests', () => { |
| 2 | + beforeEach(() => { |
| 3 | + cy.autologin(); |
| 4 | + cy.createContent({ |
| 5 | + contentType: 'Document', |
| 6 | + contentId: 'comments-page', |
| 7 | + contentTitle: 'Comments Page', |
| 8 | + allow_discussion: true, |
| 9 | + }); |
| 10 | + cy.setRegistry( |
| 11 | + 'plone.app.discussion.interfaces.IDiscussionSettings.globally_enabled', |
| 12 | + true, |
| 13 | + ); |
| 14 | + cy.createContent({ |
| 15 | + contentType: 'Document', |
| 16 | + contentId: 'my-first-page', |
| 17 | + contentTitle: 'My First Page', |
| 18 | + }); |
| 19 | + cy.createContent({ |
| 20 | + contentType: 'Document', |
| 21 | + contentId: 'my-second-page', |
| 22 | + contentTitle: 'My Second Page', |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + it('As editor I can autosave when editing a content item', () => { |
| 27 | + cy.visit('/my-first-page'); |
| 28 | + |
| 29 | + cy.log('adding a text block on the first page'); |
| 30 | + |
| 31 | + cy.navigate('/my-first-page/edit'); |
| 32 | + cy.getSlateEditorAndType('My first text').contains('My first text'); |
| 33 | + cy.wait(1000); |
| 34 | + |
| 35 | + cy.visit('/my-second-page'); |
| 36 | + |
| 37 | + cy.log('adding a text block on the second page'); |
| 38 | + cy.navigate('/my-second-page/edit'); |
| 39 | + |
| 40 | + cy.getSlateEditorAndType('My second text').contains('My second text'); |
| 41 | + cy.wait(1000); |
| 42 | + |
| 43 | + cy.log('visit first page and start editing'); |
| 44 | + |
| 45 | + cy.visit('/my-first-page'); |
| 46 | + cy.navigate('/my-first-page/edit'); |
| 47 | + cy.wait(1000); |
| 48 | + |
| 49 | + cy.findByRole('alert') |
| 50 | + .get('.toast-inner-content') |
| 51 | + .contains('Autosaved content found') |
| 52 | + .get('button.ui.icon.button.save.toast-box') |
| 53 | + .eq(0) |
| 54 | + .click(); |
| 55 | + |
| 56 | + cy.wait(1000); |
| 57 | + |
| 58 | + cy.getSlate().contains('My first text'); |
| 59 | + |
| 60 | + cy.log('visit second page and start editing'); |
| 61 | + |
| 62 | + cy.visit('/my-second-page'); |
| 63 | + cy.navigate('/my-second-page/edit'); |
| 64 | + cy.wait(1000); |
| 65 | + |
| 66 | + cy.findByRole('alert') |
| 67 | + .get('.toast-inner-content') |
| 68 | + .contains('Autosaved content found') |
| 69 | + .get('button.ui.icon.button.save.toast-box') |
| 70 | + .eq(0) |
| 71 | + .click(); |
| 72 | + |
| 73 | + cy.wait(1000); |
| 74 | + |
| 75 | + cy.getSlate().contains('My second text'); |
| 76 | + cy.reload(); |
| 77 | + |
| 78 | + cy.log( |
| 79 | + 'test is cancel load data will delete from storage (toast does not show)', |
| 80 | + ); |
| 81 | + cy.findByRole('alert') |
| 82 | + .get('.toast-inner-content') |
| 83 | + .contains('Autosaved content found') |
| 84 | + .get('button.ui.icon.button.save.toast-box') |
| 85 | + .eq(1) |
| 86 | + .click(); |
| 87 | + |
| 88 | + cy.wait(1000); |
| 89 | + cy.reload(); |
| 90 | + |
| 91 | + cy.wait(1000); |
| 92 | + |
| 93 | + cy.contains('Autosaved content found').should('not.exist'); |
| 94 | + }); |
| 95 | + |
| 96 | + it('As editor I can autosave when adding a content item', function () { |
| 97 | + cy.visit('/'); |
| 98 | + |
| 99 | + cy.log( |
| 100 | + 'adding a Document content type and refresh to verify if content is autosaved and retrieved', |
| 101 | + ); |
| 102 | + cy.get('#toolbar-add').click().get('#toolbar-add-document').click(); |
| 103 | + cy.getSlateTitle().type('Page 1 title'); |
| 104 | + cy.getSlateEditorAndType('Page 1 content').contains('Page 1 content'); |
| 105 | + cy.wait(1000); |
| 106 | + cy.reload(); |
| 107 | + |
| 108 | + cy.log('test if autosaved toast shows retrieved data and click OK to load'); |
| 109 | + cy.findByRole('alert') |
| 110 | + .get('.toast-inner-content') |
| 111 | + .contains('Autosaved content found') |
| 112 | + .get('button.ui.icon.button.save.toast-box') |
| 113 | + .eq(0) |
| 114 | + .click(); |
| 115 | + |
| 116 | + cy.wait(1000); |
| 117 | + |
| 118 | + cy.log('test if autosaved data is loaded'); |
| 119 | + cy.getSlateTitle().contains('Page 1 title'); |
| 120 | + cy.getSlate().contains('Page 1 content'); |
| 121 | + |
| 122 | + cy.log( |
| 123 | + 'test if draft is autosaved after I cancel adding a new page content type', |
| 124 | + ); |
| 125 | + |
| 126 | + cy.get('button.button.cancel').click(); |
| 127 | + |
| 128 | + cy.wait(1000); |
| 129 | + |
| 130 | + cy.get('#toolbar-add').click().get('#toolbar-add-document').click(); |
| 131 | + |
| 132 | + cy.findByRole('alert') |
| 133 | + .get('.toast-inner-content') |
| 134 | + .contains('Autosaved content found') |
| 135 | + .get('button.ui.icon.button.save.toast-box') |
| 136 | + .eq(0) |
| 137 | + .click(); |
| 138 | + |
| 139 | + cy.wait(1000); |
| 140 | + cy.getSlateTitle().contains('Page 1 title'); |
| 141 | + cy.getSlate().contains('Page 1 content'); |
| 142 | + |
| 143 | + cy.wait(1000); |
| 144 | + |
| 145 | + cy.log('test if page content type is added as new page after Toolbar Save'); |
| 146 | + |
| 147 | + cy.get('#toolbar-save').focus().click(); |
| 148 | + cy.wait(2000); |
| 149 | + cy.contains('Page 1 title'); |
| 150 | + cy.wait(1000); |
| 151 | + |
| 152 | + cy.log('test draft is deleted from local storage after save'); |
| 153 | + |
| 154 | + cy.visit('/'); |
| 155 | + cy.get('#toolbar-add').click().get('#toolbar-add-document').click(); |
| 156 | + |
| 157 | + cy.wait(1000); |
| 158 | + |
| 159 | + cy.contains('Autosaved content found').should('not.exist'); |
| 160 | + }); |
| 161 | + |
| 162 | + it('As editor I can autosave comments', function () { |
| 163 | + cy.log('adding a comment and refresh,'); |
| 164 | + cy.visit('/comments-page'); |
| 165 | + cy.get('textarea[id="field-comment"]').clear().type('This is a comment'); |
| 166 | + cy.wait(1000); |
| 167 | + cy.reload(); |
| 168 | + |
| 169 | + cy.log('test if comment is retrieved from local storage'); |
| 170 | + |
| 171 | + cy.findByRole('alert') |
| 172 | + .get('.toast-inner-content') |
| 173 | + .contains('Autosaved content found') |
| 174 | + .get('button.ui.icon.button.save.toast-box') |
| 175 | + .eq(0) |
| 176 | + .click(); |
| 177 | + |
| 178 | + cy.get('#field-comment').contains('This is a comment'); |
| 179 | + |
| 180 | + cy.wait(1000); |
| 181 | + cy.reload(); |
| 182 | + |
| 183 | + cy.log( |
| 184 | + 'test if comment is deleted from local storage after selecting Cancel in the Autosave toast', |
| 185 | + ); |
| 186 | + |
| 187 | + cy.findByRole('alert') |
| 188 | + .get('.toast-inner-content') |
| 189 | + .contains('Autosaved content found') |
| 190 | + .get('button.ui.icon.button.save.toast-box') |
| 191 | + .eq(1) |
| 192 | + .click(); |
| 193 | + |
| 194 | + cy.wait(1000); |
| 195 | + cy.reload(); |
| 196 | + cy.contains('Autosaved content found').should('not.exist'); |
| 197 | + |
| 198 | + cy.log('adding another comment and save it'); |
| 199 | + |
| 200 | + cy.get('textarea[id="field-comment"]') |
| 201 | + .clear() |
| 202 | + .type('This is a another comment'); |
| 203 | + cy.wait(1000); |
| 204 | + cy.reload(); |
| 205 | + |
| 206 | + cy.findByRole('alert') |
| 207 | + .get('.toast-inner-content') |
| 208 | + .contains('Autosaved content found') |
| 209 | + .get('button.ui.icon.button.save.toast-box') |
| 210 | + .eq(0) |
| 211 | + .click(); |
| 212 | + |
| 213 | + cy.wait(1000); |
| 214 | + |
| 215 | + cy.get('button[type="submit"').click(); |
| 216 | + |
| 217 | + cy.get('.comment').contains('This is a another comment'); |
| 218 | + |
| 219 | + cy.log('test if the local storage comment was deleted after submit'); |
| 220 | + |
| 221 | + cy.wait(1000); |
| 222 | + cy.reload(); |
| 223 | + cy.contains('Autosaved content found').should('not.exist'); |
| 224 | + }); |
| 225 | +}); |
0 commit comments