From 1bb912333397ab2e8ef8ce45dda7396de3702122 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 19 Mar 2023 22:58:11 +0530 Subject: [PATCH] Fix Cypress tests (settings security tab, new default tpls). --- frontend/cypress/e2e/bounces.cy.js | 2 +- frontend/cypress/e2e/settings.cy.js | 2 +- frontend/cypress/e2e/templates.cy.js | 69 +++++++++++++--------------- 3 files changed, 34 insertions(+), 39 deletions(-) diff --git a/frontend/cypress/e2e/bounces.cy.js b/frontend/cypress/e2e/bounces.cy.js index 224490e..0cb16c7 100644 --- a/frontend/cypress/e2e/bounces.cy.js +++ b/frontend/cypress/e2e/bounces.cy.js @@ -7,7 +7,7 @@ describe('Bounces', () => { cy.resetDB(); cy.loginAndVisit('/settings'); - cy.get('.b-tabs nav a').eq(5).click(); + cy.get('.b-tabs nav a').eq(6).click(); cy.get('[data-cy=btn-enable-bounce] .switch').click(); cy.get('[data-cy=btn-enable-bounce-webhook] .switch').click(); cy.get('[data-cy=btn-bounce-count] .plus').click(); diff --git a/frontend/cypress/e2e/settings.cy.js b/frontend/cypress/e2e/settings.cy.js index 23f51c3..5e1894c 100644 --- a/frontend/cypress/e2e/settings.cy.js +++ b/frontend/cypress/e2e/settings.cy.js @@ -19,7 +19,7 @@ describe('Templates', () => { .click(); // Enable / disable SMTP and delete one. - cy.get('.b-tabs nav a').eq(4).click(); + cy.get('.b-tabs nav a').eq(5).click(); cy.get('.tab-item:visible [data-cy=btn-enable-smtp]').eq(1).click(); cy.get('.tab-item:visible [data-cy=btn-delete-smtp]').first().click(); cy.get('.modal button.is-primary').click(); diff --git a/frontend/cypress/e2e/templates.cy.js b/frontend/cypress/e2e/templates.cy.js index 91067e0..f43e707 100644 --- a/frontend/cypress/e2e/templates.cy.js +++ b/frontend/cypress/e2e/templates.cy.js @@ -6,27 +6,30 @@ describe('Templates', () => { it('Counts default templates', () => { - cy.get('tbody td[data-label=Name]').should('have.length', 2); + cy.get('tbody td[data-label=Name]').should('have.length', 3); }); it('Clones campaign template', () => { cy.get('[data-cy=btn-clone]').first().click(); - cy.get('.modal input').clear().type('cloned').click(); + cy.get('.modal input').clear().type('cloned campaign').click(); cy.get('.modal button.is-primary').click(); cy.wait(250); // Verify the newly created row. - cy.get('tbody td[data-label="Name"]').eq(2).contains('cloned'); + cy.get('tbody td[data-label="Name"]').contains('td', 'cloned campaign'); }); it('Clones tx template', () => { - cy.get('tbody tr:nth-child(2) [data-cy=btn-clone]').click(); - cy.get('.modal input').clear().type('cloned').click(); - cy.get('.modal button.is-primary').click(); - cy.wait(250); + cy.get('tbody td[data-label="Name"]').contains('td', 'Sample transactional template').then((el) => { + cy.wrap(el).parent().find('[data-cy=btn-clone]').click(); + cy.get('.modal input').clear().type('cloned tx').click(); + cy.get('.modal button.is-primary').click(); + cy.wait(250); + }); + // Verify the newly created row. - cy.get('tbody td[data-label="Name"]').eq(3).contains('cloned'); + cy.get('tbody td[data-label="Name"]').contains('td', 'cloned tx'); }); it('Edits template', () => { @@ -52,7 +55,7 @@ describe('Templates', () => { cy.get('.modal-card-foot button').click(); // Cloned one should have the full template. - cy.get('tbody [data-cy=btn-preview').eq(2).click(); + cy.get('tbody [data-cy=btn-preview').eq(3).click(); cy.wait(500); cy.get('.modal-card-body iframe').iframe(() => { cy.get('.wrap p').first().contains('Hi there'); @@ -62,48 +65,40 @@ describe('Templates', () => { }); it('Previews tx templates', () => { - // Edited one sould have a bare body. - cy.get('tbody tr:nth-child(2) [data-cy=btn-preview').click(); - cy.wait(500); - cy.get('.modal-card-body iframe').iframe(() => { - cy.get('strong').first().contains('Order number'); + cy.get('tbody td[data-label="Name"]').contains('td', 'cloned tx').then((el) => { + cy.wrap(el).parent().find('[data-cy=btn-preview]').click(); + cy.wait(500); + cy.get('.modal-card-body iframe').iframe(() => { + cy.get('strong').first().contains('Order number'); + }); + cy.get('.modal-card-foot button').click(); }); - cy.get('.modal-card-foot button').click(); - - // Cloned one should have the full template. - cy.get('tbody tr:nth-child(4) [data-cy=btn-preview').click(); - cy.wait(500); - cy.get('.modal-card-body iframe').iframe(() => { - cy.get('strong').first().contains('Order number'); - }); - cy.get('.modal-card-foot button').click(); }); it('Sets default', () => { - cy.get('tbody td.actions').eq(2).find('[data-cy=btn-set-default]').click(); - cy.get('.modal button.is-primary').click(); + cy.get('tbody td[data-label="Name"]').contains('td', 'cloned campaign').then((el) => { + cy.wrap(el).parent().find('[data-cy=btn-set-default]').click(); + cy.get('.modal button.is-primary').click(); + + }); // The original default shouldn't have default and the new one should have. - cy.get('tbody td.actions').eq(0).then((el) => { - cy.wrap(el).find('[data-cy=btn-delete]').should('exist'); - cy.wrap(el).find('[data-cy=btn-set-default]').should('exist'); - }); - cy.get('tbody td.actions').eq(2).then((el) => { - cy.wrap(el).find('[data-cy=btn-delete]').should('not.exist'); - cy.wrap(el).find('[data-cy=btn-set-default]').should('not.exist'); - }); + cy.get('tbody').contains('td', 'edited').parent().find('[data-cy=btn-delete]').should('exist'); + cy.get('tbody').contains('td', 'cloned campaign').parent().find('[data-cy=btn-delete]').should('not.exist'); }); it('Deletes template', () => { cy.wait(250); - [1, 1, 2].forEach((n) => { - cy.get(`tbody tr:nth-child(${n}) td.actions [data-cy=btn-delete]`).click(); - cy.get('.modal button.is-primary').click(); + ['Default archive template', 'Sample transactional template'].forEach((t) => { + cy.get('tbody td[data-label="Name"]').contains('td', t).then((el) => { + cy.wrap(el).parent().find('[data-cy=btn-delete]').click(); + cy.get('.modal button.is-primary').click(); + }); cy.wait(250); }) - cy.get('tbody td.actions').should('have.length', 1); + cy.get('tbody td.actions').should('have.length', 3); }); });