From 2f356dd3a4e12b10af8125c0cb70267972274bbd Mon Sep 17 00:00:00 2001 From: Suzanne Aitchison Date: Tue, 15 Jun 2021 11:46:18 +0100 Subject: [PATCH] [15 min fix] Improve reliability of profile dropdown test (#13986) * wait for profile init * complete logged out tests first * add comment --- .../profileUserActionsMenu.spec.js | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/cypress/integration/profileFlows/profileUserActionsMenu.spec.js b/cypress/integration/profileFlows/profileUserActionsMenu.spec.js index f52f35d92..d97eb62d8 100644 --- a/cypress/integration/profileFlows/profileUserActionsMenu.spec.js +++ b/cypress/integration/profileFlows/profileUserActionsMenu.spec.js @@ -1,4 +1,29 @@ describe('Profile User Actions Menu', () => { + // We complete logged out tests first, as unfinished network requests relating to logged-in users can cause unexpected failures + // See: https://github.com/forem/forem/issues/13988 + describe('Logged out users', () => { + beforeEach(() => { + cy.testSetup(); + }); + + it('should show a dropdown menu with only the Report Abuse link when the user is not logged in', () => { + cy.visit('/article_editor_v1_user'); + // Make sure the dropdown has initialized + cy.get('[data-dropdown-initialized]'); + + cy.findByRole('button', { name: 'User actions' }).click(); + + cy.findByRole('link', { name: 'Report Abuse' }).should('have.focus'); + + cy.findByRole('link', { name: 'Block @article_editor_v1_user' }).should( + 'not.exist', + ); + cy.findByRole('link', { name: 'Flag @article_editor_v1_user' }).should( + 'not.exist', + ); + }); + }); + describe('Logged in users', () => { beforeEach(() => { cy.testSetup(); @@ -14,6 +39,9 @@ describe('Profile User Actions Menu', () => { it("should show a dropdown menu when a user views another user's profile", () => { cy.visit('/article_editor_v1_user'); + // Make sure the dropdown has initialized + cy.get('[data-dropdown-initialized]'); + cy.findByRole('button', { name: 'User actions' }).as('dropdownButton'); cy.get('@dropdownButton').click(); cy.findByRole('link', { name: 'Block @article_editor_v1_user' }).should( @@ -48,6 +76,10 @@ describe('Profile User Actions Menu', () => { cy.on('window:confirm', () => true); cy.visit('/article_editor_v1_user'); + + // Make sure the dropdown has initialized + cy.get('[data-dropdown-initialized]'); + cy.findByRole('button', { name: 'User actions' }).click(); cy.findByRole('link', { name: 'Block @article_editor_v1_user' }).click(); @@ -66,6 +98,10 @@ describe('Profile User Actions Menu', () => { cy.on('window:confirm', () => true); cy.visit('/article_editor_v1_user'); + + // Make sure the dropdown has initialized + cy.get('[data-dropdown-initialized]'); + cy.findByRole('button', { name: 'User actions' }).click(); cy.findByRole('link', { name: 'Flag @article_editor_v1_user' }).click(); @@ -84,6 +120,10 @@ describe('Profile User Actions Menu', () => { it('should link to report abuse from user', () => { cy.visit('/article_editor_v1_user'); + + // Make sure the dropdown has initialized + cy.get('[data-dropdown-initialized]'); + cy.findByRole('button', { name: 'User actions' }).click(); cy.findByRole('link', { name: 'Report Abuse' }).click(); @@ -91,24 +131,4 @@ describe('Profile User Actions Menu', () => { cy.url().should('contain', 'article_editor_v1_user'); }); }); - - describe('Logged out users', () => { - beforeEach(() => { - cy.testSetup(); - }); - - it('should show a dropdown menu with only the Report Abuse link when the user is not logged in', () => { - cy.visit('/article_editor_v1_user'); - cy.findByRole('button', { name: 'User actions' }).click(); - - cy.findByRole('link', { name: 'Report Abuse' }).should('have.focus'); - - cy.findByRole('link', { name: 'Block @article_editor_v1_user' }).should( - 'not.exist', - ); - cy.findByRole('link', { name: 'Flag @article_editor_v1_user' }).should( - 'not.exist', - ); - }); - }); });