Skip to content

Commit

Permalink
Refactor template tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jul 9, 2022
1 parent bc07a45 commit f26f7c6
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions frontend/cypress/integration/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@ describe('Templates', () => {


it('Counts default templates', () => {
cy.get('tbody td[data-label=Name]').should('have.length', 1);
cy.get('tbody td[data-label=Name]').should('have.length', 2);
});

it('Clones template', () => {
// Clone the campaign.
it('Clones campaign template', () => {
cy.get('[data-cy=btn-clone]').first().click();
cy.get('.modal input').clear().type('cloned').click();
cy.get('.modal button.is-primary').click();
cy.wait(250);

// Verify the newly created row.
cy.get('tbody td[data-label="Name"]').eq(1).contains('cloned');
cy.get('tbody td[data-label="Name"]').eq(2).contains('cloned');
});

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);

// Verify the newly created row.
cy.get('tbody td[data-label="Name"]').eq(3).contains('cloned');
});

it('Edits template', () => {
Expand All @@ -43,7 +52,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(1).click();
cy.get('tbody [data-cy=btn-preview').eq(2).click();
cy.wait(500);
cy.get('.modal-card-body iframe').iframe(() => {
cy.get('.wrap p').first().contains('Hi there');
Expand All @@ -53,15 +62,15 @@ describe('Templates', () => {
});

it('Sets default', () => {
cy.get('tbody td.actions').eq(1).find('[data-cy=btn-set-default]').click();
cy.get('tbody td.actions').eq(2).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(1).then((el) => {
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');
});
Expand All @@ -70,9 +79,13 @@ describe('Templates', () => {

it('Deletes template', () => {
cy.wait(250);
cy.get('tbody td.actions [data-cy=btn-delete]').first().click();
cy.get('.modal button.is-primary').click();
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();
cy.wait(250);
})

cy.get('tbody td.actions').should('have.length', 1);
});
});

0 comments on commit f26f7c6

Please sign in to comment.