Skip to content

Commit

Permalink
Fix race conditions in Cypress tests (sigh).
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Aug 6, 2023
1 parent 1164afa commit acca61f
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions frontend/cypress/e2e/campaigns.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ describe('Campaigns', () => {

cy.get('a[data-cy=btn-attach]').click();
cy.get('input[type=file]').attachFile('example.json');
cy.get('.modal button.is-primary').click();
cy.get('.modal .thumb a.link').click();
cy.get('.modal button.is-primary:eq(0)').click();
cy.wait(500);
cy.get('.modal td[data-label=Name] a.link').click();
cy.get('button[data-cy=btn-save]').click();
cy.wait(500);

Expand All @@ -40,7 +41,7 @@ describe('Campaigns', () => {

// Start.
cy.get('button[data-cy=btn-start]').click();
cy.get('.modal button.is-primary').click();
cy.get('.modal button.is-primary:eq(0)').click();
cy.wait(500);
cy.get('tbody tr').eq(0).get('td[data-label=Status] .tag.running');
});
Expand Down Expand Up @@ -81,15 +82,15 @@ describe('Campaigns', () => {

// Switch format to plain text.
cy.get('label[data-cy=check-plain]').click();
cy.get('.modal button.is-primary').click();
cy.get('.modal button.is-primary:eq(0)').click();

// Enter body value.
cy.get('textarea[name=content]').clear().type('new-content');
cy.get('button[data-cy=btn-save]').click();

// Schedule.
cy.get('button[data-cy=btn-schedule]').click();
cy.get('.modal button.is-primary').click();
cy.get('.modal button.is-primary:eq(0)').click();

cy.wait(250);

Expand Down Expand Up @@ -141,11 +142,11 @@ describe('Campaigns', () => {

// Switch format.
cy.get(`label[data-cy=check-${c}]`).click();
cy.get('.modal button.is-primary').click();
cy.get('.modal button.is-primary:eq(0)').click();

// Check content.
cy.get('button[data-cy=btn-preview]').click();
cy.wait(200);
cy.wait(500);
cy.get("#iframe").then(($f) => {
if (c === 'plain') {
return;
Expand All @@ -164,7 +165,7 @@ describe('Campaigns', () => {
// Clone the campaign.
cy.get('[data-cy=btn-clone]').first().click();
cy.get('.modal input').clear().type(`clone${n}`).click();
cy.get('.modal button.is-primary').click();
cy.get('.modal button.is-primary:eq(0)').click();
cy.wait(250);
cy.clickMenu('all-campaigns');
cy.wait(100);
Expand All @@ -187,7 +188,7 @@ describe('Campaigns', () => {
// Delete all visible lists.
cy.get('tbody tr').each(() => {
cy.get('tbody a[data-cy=btn-delete]').first().click();
cy.get('.modal button.is-primary').click();
cy.get('.modal button.is-primary:eq(0)').click();
});

// Confirm deletion.
Expand Down Expand Up @@ -253,12 +254,13 @@ describe('Campaigns', () => {
const plainBody = `hello${n} Demo Subscriber from Bengaluru`;
const markdownBody = `**hello${n}** Demo Subscriber from Bengaluru`;

cy.log(`format = ${c}`)
if (c === 'richtext') {
cy.window().then((win) => {
win.tinymce.editors[0].setContent(htmlBody);
win.tinymce.editors[0].save();
});
cy.wait(200);
cy.wait(500);
} else if (c === 'html') {
cy.get('code-flask').shadow().find('.codeflask textarea').invoke('val', htmlBody).trigger('input');
} else if (c === 'markdown') {
Expand All @@ -272,7 +274,7 @@ describe('Campaigns', () => {

// Preview and match the body.
cy.get('button[data-cy=btn-preview]').click();
cy.wait(200);
cy.wait(1000);
cy.get("#iframe").then(($f) => {
if (c === 'plain') {
return;
Expand All @@ -284,7 +286,7 @@ describe('Campaigns', () => {
cy.get('.modal-card-foot button').click();

cy.clickMenu('all-campaigns');
cy.wait(250);
cy.wait(500);

// Verify the newly created campaign in the table.
cy.get('tbody td[data-label="Name"]').first().contains(`name${n}`);
Expand Down Expand Up @@ -316,13 +318,13 @@ describe('Campaigns', () => {
it('Starts and cancels campaigns', () => {
for (let n = 1; n <= 2; n++) {
cy.get(`tbody tr:nth-child(${n}) [data-cy=btn-start]`).click();
cy.get('.modal button.is-primary').click();
cy.get('.modal button.is-primary:eq(0)').click();
cy.wait(250);
cy.get(`tbody tr:nth-child(${n}) td[data-label=Status] .tag.running`);

if (n > 1) {
cy.get(`tbody tr:nth-child(${n}) [data-cy=btn-cancel]`).click();
cy.get('.modal button.is-primary').click();
cy.get('.modal button.is-primary:eq(0)').click();
cy.wait(250);
cy.get(`tbody tr:nth-child(${n}) td[data-label=Status] .tag.cancelled`);
}
Expand Down

0 comments on commit acca61f

Please sign in to comment.