From 2aaeea68a96f9d500c2b9218d9379d0c971af106 Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Mon, 17 Oct 2022 10:54:41 -0500 Subject: [PATCH] Merge pull request #9993 from overleaf/jel-fix-flaky-test [web] Fix flaky frontend test GitOrigin-RevId: 580678473f09cb21ac2ca20cf9d16ecc05cd4236 --- .../components/project-list-root.test.tsx | 65 ++++++++++++------- .../table/project-list-table.test.tsx | 1 - 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/services/web/test/frontend/features/project-list/components/project-list-root.test.tsx b/services/web/test/frontend/features/project-list/components/project-list-root.test.tsx index ecc46483e5..332d0206ec 100644 --- a/services/web/test/frontend/features/project-list/components/project-list-root.test.tsx +++ b/services/web/test/frontend/features/project-list/components/project-list-root.test.tsx @@ -517,25 +517,18 @@ describe('', function () { .null }) - it('opens the rename modal, and can rename the project, and view updated', async function () { - const renameProjectMock = fetchMock.post( - `express:/project/:id/rename`, - { - status: 200, - } - ) - - await waitFor(() => { - const moreDropdown = - within(actionsToolbar).getByText('More') - fireEvent.click(moreDropdown) - }) + it('validates the project name', async function () { + const moreDropdown = await within( + actionsToolbar + ).findByText('More') + fireEvent.click(moreDropdown) const renameButton = screen.getAllByText('Rename')[1] // first one is for the tag in the sidebar fireEvent.click(renameButton) - const modal = screen.getAllByRole('dialog')[0] + const modals = await screen.findAllByRole('dialog') + const modal = modals[0] expect(sendSpy).to.be.calledOnce expect(sendSpy).calledWith('project-list-page-interaction') @@ -545,25 +538,47 @@ describe('', function () { within(modal).getByText('Rename') expect(confirmButton.disabled).to.be.true let input = screen.getByLabelText('New Name') as HTMLButtonElement - const oldName = input.value // no name - let newProjectName = '' input = screen.getByLabelText('New Name') as HTMLButtonElement fireEvent.change(input, { - target: { value: newProjectName }, + target: { value: '' }, }) confirmButton = within(modal).getByText('Rename') expect(confirmButton.disabled).to.be.true + }) + + it('opens the rename modal, and can rename the project, and view updated', async function () { + const renameProjectMock = fetchMock.post( + `express:/project/:id/rename`, + { + status: 200, + } + ) + const moreDropdown = await within( + actionsToolbar + ).findByText('More') + fireEvent.click(moreDropdown) + + const renameButton = + screen.getAllByText('Rename')[1] // first one is for the tag in the sidebar + fireEvent.click(renameButton) + + const modals = await screen.findAllByRole('dialog') + const modal = modals[0] // a valid name - newProjectName = 'A new project name' - input = screen.getByLabelText('New Name') as HTMLButtonElement + const newProjectName = 'A new project name' + const input = (await screen.findByLabelText( + 'New Name' + )) as HTMLButtonElement + const oldName = input.value fireEvent.change(input, { target: { value: newProjectName }, }) - confirmButton = within(modal).getByText('Rename') + const confirmButton = + within(modal).getByText('Rename') expect(confirmButton.disabled).to.be.false fireEvent.click(confirmButton) @@ -576,11 +591,13 @@ describe('', function () { ).to.be.true ) - screen.findByText(newProjectName) - expect(screen.queryByText(oldName)).to.be.null + const table = await screen.findByRole('table') + within(table).getByText(newProjectName) + expect(within(table).queryByText(oldName)).to.be.null - const allCheckboxes = - screen.getAllByRole('checkbox') + const allCheckboxes = await within( + table + ).findAllByRole('checkbox') const allCheckboxesChecked = allCheckboxes.filter(c => c.checked) expect(allCheckboxesChecked.length).to.equal(0) }) diff --git a/services/web/test/frontend/features/project-list/components/table/project-list-table.test.tsx b/services/web/test/frontend/features/project-list/components/table/project-list-table.test.tsx index 354eb563ed..4c617cc081 100644 --- a/services/web/test/frontend/features/project-list/components/table/project-list-table.test.tsx +++ b/services/web/test/frontend/features/project-list/components/table/project-list-table.test.tsx @@ -109,7 +109,6 @@ describe('', function () { // Action Column // temporary count tests until we add filtering for archived/trashed const copyButtons = screen.getAllByLabelText('Copy') - screen.debug() expect(copyButtons.length).to.equal(currentProjects.length) const downloadButtons = screen.getAllByLabelText('Download') expect(downloadButtons.length).to.equal(currentProjects.length)