|
| 1 | +describe('Test in backend that the content history list', () => { |
| 2 | + beforeEach(() => { |
| 3 | + cy.task('queryDB', "DELETE FROM #__content WHERE title = 'Test article versions'"); |
| 4 | + cy.doAdministratorLogin(); |
| 5 | + }); |
| 6 | + |
| 7 | + afterEach(() => { |
| 8 | + cy.task('queryDB', "DELETE FROM #__content WHERE title = 'Test article versions'"); |
| 9 | + }); |
| 10 | + |
| 11 | + it('has a title', () => { |
| 12 | + cy.visit('/administrator/index.php?option=com_content&task=article.add'); |
| 13 | + cy.get('#jform_title').clear().type('Test article versions'); |
| 14 | + cy.clickToolbarButton('Save'); |
| 15 | + cy.clickToolbarButton('Versions'); |
| 16 | + cy.get('.joomla-dialog-header').should('contain.text', 'Versions'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('can display a list of content history', () => { |
| 20 | + cy.visit('/administrator/index.php?option=com_content&task=article.add'); |
| 21 | + cy.get('#jform_title').clear().type('Test article versions'); |
| 22 | + cy.clickToolbarButton('Save'); |
| 23 | + cy.clickToolbarButton('Versions'); |
| 24 | + |
| 25 | + const currentDate = new Date(); |
| 26 | + const formattedDate = `${currentDate.getFullYear()}-${(currentDate.getMonth() + 1).toString().padStart(2, '0')}-${currentDate.getDate().toString().padStart(2, '0')}`; |
| 27 | + cy.log(formattedDate); |
| 28 | + cy.wait(5000); |
| 29 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 30 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 31 | + .should('not.be.empty') // Ensure the body is loaded |
| 32 | + .then(cy.wrap) // Wrap the body for further Cypress commands |
| 33 | + .find('a') // Find the specific element containing the string |
| 34 | + .should('contain.text', formattedDate); |
| 35 | + cy.get('button.button-close.btn-close').click(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('can open the history content item modal', () => { |
| 39 | + cy.visit('/administrator/index.php?option=com_content&task=article.add'); |
| 40 | + cy.get('#jform_title').clear().type('Test article versions'); |
| 41 | + cy.clickToolbarButton('Save'); |
| 42 | + cy.clickToolbarButton('Versions'); |
| 43 | + cy.wait(5000); |
| 44 | + |
| 45 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 46 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 47 | + .should('not.be.empty') // Ensure the body is loaded |
| 48 | + .then(cy.wrap) // Wrap the body for further Cypress commands |
| 49 | + .find('a') |
| 50 | + .invoke('attr', 'data-url') |
| 51 | + .then((url) => { |
| 52 | + // Get the base URL from the Cypress configuration |
| 53 | + const baseUrl = Cypress.config('baseUrl'); |
| 54 | + // Combine the base URL and the relative URL |
| 55 | + const completeUrl = new URL(url, baseUrl).href; |
| 56 | + |
| 57 | + // Remove the subdomain (in this case, the base URL's hostname) |
| 58 | + const basePath = new URL(baseUrl).pathname; // Get the base path |
| 59 | + const modifiedUrl = completeUrl.replace(new URL(baseUrl).origin + basePath, ''); |
| 60 | + |
| 61 | + cy.log('new window url', modifiedUrl); |
| 62 | + // Visit the URL directly |
| 63 | + cy.visit(modifiedUrl); |
| 64 | + // Verify the text on the new page |
| 65 | + cy.contains('Test article versions').should('be.visible'); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + it('cannot compare one history content item only', () => { |
| 70 | + cy.visit('/administrator/index.php?option=com_content&task=article.add'); |
| 71 | + cy.get('#jform_title').clear().type('Test article versions'); |
| 72 | + cy.clickToolbarButton('Save'); |
| 73 | + cy.clickToolbarButton('Versions'); |
| 74 | + |
| 75 | + cy.wait(5000); |
| 76 | + |
| 77 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 78 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 79 | + .should('not.be.empty') // Ensure the body is loaded |
| 80 | + .find('input.form-check-input[name="checkall-toggle"]') |
| 81 | + .check(); |
| 82 | + // Target the button using its parent id and class |
| 83 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 84 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 85 | + .should('not.be.empty') // Ensure the body is loaded |
| 86 | + |
| 87 | + .find('button.button-compare') // Locate the button inside it |
| 88 | + .should('contain.text', 'Compare') // Validate the button text |
| 89 | + .click(); // Perform the click action |
| 90 | + // Verify the text on the new page |
| 91 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 92 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 93 | + .should('not.be.empty') |
| 94 | + .should('contain.text', 'Please select two versions'); |
| 95 | + }); |
| 96 | + |
| 97 | + it('can delete an history content item', () => { |
| 98 | + cy.visit('/administrator/index.php?option=com_content&task=article.add'); |
| 99 | + cy.get('#jform_title').clear().type('Test article versions'); |
| 100 | + cy.clickToolbarButton('Save'); |
| 101 | + cy.clickToolbarButton('Versions'); |
| 102 | + cy.wait(5000); |
| 103 | + |
| 104 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 105 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 106 | + .should('not.be.empty') // Ensure the body is loaded |
| 107 | + .find('input.form-check-input[name="checkall-toggle"]') |
| 108 | + .check(); |
| 109 | + // Target the button using its parent id and class |
| 110 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 111 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 112 | + .should('not.be.empty') // Ensure the body is loaded |
| 113 | + |
| 114 | + .find('button.button-delete') // Locate the button inside it |
| 115 | + .should('contain.text', 'Delete') // Validate the button text |
| 116 | + .click(); // Perform the click action |
| 117 | + cy.wait(5000); |
| 118 | + // Verify the text on the new page |
| 119 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 120 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 121 | + .should('not.be.empty') |
| 122 | + .should('contain.text', 'History version deleted'); |
| 123 | + }); |
| 124 | + |
| 125 | + it('can keep on a history content item', () => { |
| 126 | + cy.visit('/administrator/index.php?option=com_content&task=article.add'); |
| 127 | + cy.get('#jform_title').clear().type('Test article versions'); |
| 128 | + cy.clickToolbarButton('Save'); |
| 129 | + cy.clickToolbarButton('Versions'); |
| 130 | + cy.wait(5000); |
| 131 | + |
| 132 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 133 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 134 | + .should('not.be.empty') // Ensure the body is loaded |
| 135 | + .find('input.form-check-input[name="checkall-toggle"]') |
| 136 | + .check(); |
| 137 | + // Target the button using its parent id and class |
| 138 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 139 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 140 | + .should('not.be.empty') // Ensure the body is loaded |
| 141 | + |
| 142 | + .find('button.button-keep') // Locate the button inside it |
| 143 | + .should('contain.text', 'Keep On/Off') // Validate the button text |
| 144 | + .click(); // Perform the click action |
| 145 | + cy.wait(5000); |
| 146 | + // Verify the text on the new page |
| 147 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 148 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 149 | + .should('not.be.empty') |
| 150 | + .should('contain.text', 'Changed the keep forever value for a history version'); |
| 151 | + }); |
| 152 | + |
| 153 | + it('can restore a history content item', () => { |
| 154 | + cy.visit('/administrator/index.php?option=com_content&task=article.add'); |
| 155 | + cy.get('#jform_title').clear().type('Test article versions'); |
| 156 | + cy.clickToolbarButton('Save'); |
| 157 | + cy.clickToolbarButton('Versions'); |
| 158 | + cy.wait(5000); |
| 159 | + |
| 160 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 161 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 162 | + .should('not.be.empty') // Ensure the body is loaded |
| 163 | + .find('input.form-check-input[name="checkall-toggle"]') |
| 164 | + .check(); |
| 165 | + // Target the button using its parent id and class |
| 166 | + cy.get('iframe.iframe-content') // the iframe's selector |
| 167 | + .its('0.contentDocument.body') // Access the iframe's document body |
| 168 | + .should('not.be.empty') // Ensure the body is loaded |
| 169 | + |
| 170 | + .find('button.button-load') // Locate the button inside it |
| 171 | + .should('contain.text', 'Restore') // Validate the button text |
| 172 | + .click(); // Perform the click action |
| 173 | + cy.wait(5000); |
| 174 | + cy.get('.button-close').click(); |
| 175 | + // Verify the text |
| 176 | + cy.get('.alert-message') |
| 177 | + .should('contain.text', 'Article saved'); |
| 178 | + }); |
| 179 | +}); |
0 commit comments