Skip to content

Commit

Permalink
Fix flaky cypress spec (forem#20185)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mac Siri authored Oct 3, 2023
1 parent a17bdd2 commit f73ee94
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ describe('Article flagged by an admin user', () => {

cy.wait('@request');

cy.get('.flex .c-indicator').should('be.visible').as('flagStatus');
cy.get('.flex .c-indicator').as('flagStatus');
cy.get('@flagStatus').should('be.visible');
cy.get('@flagStatus').should('contain', 'Invalid');
});
});
Expand Down Expand Up @@ -186,7 +187,8 @@ describe('Article flagged by a trusted user', () => {
.should('contain', 'Mark as Valid')
.click();

cy.get('.crayons-dropdown').should('not.be.visible');
cy.get('.crayons-dropdown').as('dropdown');
cy.get('@dropdown').should('not.be.visible');
});

it('should update status to Invalid on click of "Mark as Invalid"', () => {
Expand Down Expand Up @@ -222,7 +224,8 @@ describe('Article flagged by a trusted user', () => {

cy.wait('@request');

cy.get('.flex .c-indicator').should('be.visible').as('flagStatus');
cy.get('.flex .c-indicator').as('flagStatus');
cy.get('@flagStatus').should('be.visible');
cy.get('@flagStatus')
.should('have.class', 'c-indicator--relaxed')
.and('contain', 'Invalid');
Expand Down
121 changes: 45 additions & 76 deletions cypress/e2e/seededFlows/articleFlows/postModerationTools.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,97 +323,66 @@ describe('Moderation Tools for Posts', () => {
});

context('as trusted user', () => {
beforeEach(() => {
it('can flag and unflag', () => {
cy.fixture('users/trustedUser.json').as('trustedUser');
});

it('should load appropriate moderation tools on a post', () => {
cy.get('@trustedUser').then((user) => {
cy.loginAndVisit(user, '/admin_mcadmin/test-article-slug').then(() => {
cy.findByRole('button', { name: 'Moderation' }).should('exist');
});

cy.findByRole('button', { name: 'Moderation' }).click();

// should not show Feature Post button on a post
cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Feature Post' }).should('not.exist');
});
cy.loginAndVisit(user, '/admin_mcadmin/test-article-slug');
});
});
cy.findByRole('button', { name: 'Moderation' }).should('be.visible');
cy.findByRole('button', { name: 'Moderation' }).click();

describe('flag-user flow', () => {
beforeEach(() => {
cy.get('@trustedUser').then((user) => {
cy.loginAndVisit(user, '/admin_mcadmin/test-article-slug').then(
() => {
cy.findByRole('heading', { level: 1, name: 'Test article' });
cy.findByRole('button', { name: 'Moderation' }).click();
},
);
});
cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Feature Post' }).should('not.exist');
});

it('should flag the user', () => {
cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Open admin actions' })
.as('moderatingActionsButton')
.pipe(click)
.should('have.attr', 'aria-expanded', 'true');
cy.findByRole('button', { name: 'Flag admin_mcadmin' }).click();
});
// should show error message if flag-user radio is unchecked
cy.getModal().within(() => {
cy.findByRole('button', { name: 'Confirm Flag' }).click();
cy.findByTestId('unselected-radio-error')
.contains('You must check the radio button first.')
.should('exist');
});

cy.getModal().within(() => {
const flagUserRadioName =
"Make all posts by admin_mcadmin less visible admin_mcadmin consistently posts content that violates DEV(local)'s code of conduct because it is harassing, offensive or spammy.";
cy.findByRole('radio', {
name: flagUserRadioName,
}).check();
cy.findByRole('button', { name: 'Confirm Flag' }).click();
});

cy.findByTestId('snackbar')
.contains('All posts by this author will be less visible.')
// flag works
cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Open admin actions' })
.as('moderatingActionsButton')
.pipe(click)
.should('have.attr', 'aria-expanded', 'true');
cy.findByRole('button', { name: 'Flag admin_mcadmin' }).click();
});
// should show error message if flag-user radio is unchecked
cy.getModal().within(() => {
cy.findByRole('button', { name: 'Confirm Flag' }).click();
cy.findByTestId('unselected-radio-error')
.contains('You must check the radio button first.')
.should('exist');
});

it('should unflag the user if user was previously flagged', () => {
cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Open admin actions' })
.as('moderatingActionsButton')
.pipe(click)
.should('have.attr', 'aria-expanded', 'true');
cy.findByRole('button', { name: 'Flag admin_mcadmin' }).click();
});
cy.getModal().within(() => {
const flagUserRadioName =
"Make all posts by admin_mcadmin less visible admin_mcadmin consistently posts content that violates DEV(local)'s code of conduct because it is harassing, offensive or spammy.";
cy.findByRole('radio', {
name: flagUserRadioName,
}).check();
cy.findByRole('button', { name: 'Confirm Flag' }).click();
});

cy.getModal().within(() => {
cy.get('#flag-user-radio-input').check();
cy.findByRole('button', { name: 'Confirm Flag' }).click();
});
cy.findByTestId('snackbar')
.contains('All posts by this author will be less visible.')
.should('exist');

cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Open admin actions' })
.as('moderatingActionsButton')
.pipe(click)
.should('have.attr', 'aria-expanded', 'true');
cy.findByRole('button', { name: 'Unflag admin_mcadmin' }).click();
});
// unflag works
cy.visit('/admin_mcadmin/test-article-slug');

cy.getModal().within(() => {
cy.findByRole('button', { name: 'Confirm Unflag' }).click();
});
cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Open admin actions' })
.as('moderatingActionsButton')
.pipe(click)
.should('have.attr', 'aria-expanded', 'true');
cy.findByRole('button', { name: 'Unflag admin_mcadmin' }).click();
});

cy.findByTestId('snackbar')
.contains('You have unflagged this author successfully.')
.should('exist');
cy.getModal().within(() => {
cy.findByRole('button', { name: 'Confirm Unflag' }).click();
});

cy.findByTestId('snackbar')
.contains('You have unflagged this author successfully.')
.should('exist');
});
});
});

0 comments on commit f73ee94

Please sign in to comment.