From 79dc78e5e0ee20415f0cd8ea80908aa120477484 Mon Sep 17 00:00:00 2001 From: jpaten Date: Wed, 30 Oct 2024 14:08:07 -0700 Subject: [PATCH] test: reduced duplication between index and details export workflows (#4117) --- explorer/e2e/testFunctions.ts | 111 ++++++++++++++-------------------- 1 file changed, 44 insertions(+), 67 deletions(-) diff --git a/explorer/e2e/testFunctions.ts b/explorer/e2e/testFunctions.ts index 9446dd1cd..83b9e7593 100644 --- a/explorer/e2e/testFunctions.ts +++ b/explorer/e2e/testFunctions.ts @@ -755,6 +755,46 @@ const getBackpageLinkLocatorByAccess = (page: Page, access: string): Locator => .first() .getByRole("link"); +const makeMinimalExportRequest = async ( + page: Page, + exportRequestButtonLocator: Locator +): Promise => { + await expect(exportRequestButtonLocator).toBeEnabled(); + // Expect there to be exactly one table on the backpage + await expect(page.getByRole("table")).toHaveCount(1); + // Select all checkboxes that are not in a table + const allNonTableCheckboxLocators = await page + .locator("input[type='checkbox']:not(table input[type='checkbox'])") + .all(); + for (const checkboxLocator of allNonTableCheckboxLocators) { + await checkboxLocator.click(); + await expect(checkboxLocator).toBeChecked(); + await expect(checkboxLocator).toBeEnabled({ timeout: 10000 }); + } + + // Check the second checkbox in the table (this should be the checkbox after the "select all checkbox") + const tableLocator = page.getByRole("table"); + const allInTableCheckboxLocators = await tableLocator + .getByRole("checkbox") + .all(); + const secondCheckboxInTableLocator = allInTableCheckboxLocators[1]; + await secondCheckboxInTableLocator.click(); + await expect(secondCheckboxInTableLocator).toBeChecked(); + await expect(secondCheckboxInTableLocator).toBeEnabled({ timeout: 10000 }); + // Make sure that no other checkboxes are selected + const otherInTableCheckboxLocators = [ + allInTableCheckboxLocators[0], + ...allInTableCheckboxLocators.slice(2), + ]; + for (const otherCheckboxLocator of otherInTableCheckboxLocators) { + await expect(otherCheckboxLocator).not.toBeChecked(); + await expect(otherCheckboxLocator).toBeEnabled(); + } + // Click the Export Request button + await expect(exportRequestButtonLocator).toBeEnabled({ timeout: 10000 }); + await exportRequestButtonLocator.click(); +}; + /** * Test the export process for the specified tab * @param context - a Playwright browser context object @@ -800,39 +840,8 @@ export async function testExportBackpage( const exportRequestButtonLocator = page.getByRole("button", { name: tab.backpageExportButtons.exportRequestButtonText, }); - await expect(exportRequestButtonLocator).toBeEnabled(); - // Select all checkboxes that are not in a table - const allNonTableCheckboxLocators = await page - .locator("input[type='checkbox']:not(table input[type='checkbox'])") - .all(); - for (const checkboxLocator of allNonTableCheckboxLocators) { - await checkboxLocator.click(); - await expect(checkboxLocator).toBeChecked(); - await expect(checkboxLocator).toBeEnabled({ timeout: 10000 }); - } - // Expect there to be exactly one table on the backpage - await expect(page.getByRole("table")).toHaveCount(1); - // Check the second checkbox in the table (this should be the checkbox after the "select all checkbox") - const tableLocator = page.getByRole("table"); - const allInTableCheckboxLocators = await tableLocator - .getByRole("checkbox") - .all(); - const secondCheckboxInTableLocator = allInTableCheckboxLocators[1]; - await secondCheckboxInTableLocator.click(); - await expect(secondCheckboxInTableLocator).toBeChecked(); - await expect(secondCheckboxInTableLocator).toBeEnabled({ timeout: 10000 }); - // Make sure that no other checkboxes are selected - const otherInTableCheckboxLocators = [ - allInTableCheckboxLocators[0], - ...allInTableCheckboxLocators.slice(2), - ]; - for (const otherCheckboxLocator of otherInTableCheckboxLocators) { - await expect(otherCheckboxLocator).not.toBeChecked(); - await expect(otherCheckboxLocator).toBeEnabled(); - } - // Click the Export Request button - await expect(exportRequestButtonLocator).toBeEnabled({ timeout: 10000 }); - await exportRequestButtonLocator.click(); + // Complete the export request form + await makeMinimalExportRequest(page, exportRequestButtonLocator); await expect( page.getByText(tab.backpageExportButtons.firstLoadingMessage, { exact: true, @@ -1110,39 +1119,8 @@ export async function testIndexExportWorkflow( const exportRequestButtonLocator = page.getByRole("button", { name: tab.indexExportPage.exportRequestButtonText, }); - await expect(exportRequestButtonLocator).toBeEnabled(); - // TODO: below is code copied from #4080, refactor this to a separate function to call that instead - // Expect there to be exactly one table on the backpage - await expect(page.getByRole("table")).toHaveCount(1); - const allNonTableCheckboxLocators = await page - .locator("input[type='checkbox']:not(table input[type='checkbox'])") - .all(); - for (const checkboxLocator of allNonTableCheckboxLocators) { - await checkboxLocator.click(); - await expect(checkboxLocator).toBeChecked(); - await expect(checkboxLocator).toBeEnabled({ timeout: 10000 }); - } - // Check the second checkbox in the table (this should be the checkbox after the "select all checkbox") - const tableLocator = page.getByRole("table"); - const allInTableCheckboxLocators = await tableLocator - .getByRole("checkbox") - .all(); - const secondCheckboxInTableLocator = allInTableCheckboxLocators[1]; - await secondCheckboxInTableLocator.click(); - await expect(secondCheckboxInTableLocator).toBeChecked(); - await expect(secondCheckboxInTableLocator).toBeEnabled({ timeout: 10000 }); - // Make sure that no other checkboxes are selected - const otherInTableCheckboxLocators = [ - allInTableCheckboxLocators[0], - ...allInTableCheckboxLocators.slice(2), - ]; - for (const otherCheckboxLocator of otherInTableCheckboxLocators) { - await expect(otherCheckboxLocator).not.toBeChecked(); - await expect(otherCheckboxLocator).toBeEnabled(); - } - // Click the Export Request button - await expect(exportRequestButtonLocator).toBeEnabled({ timeout: 10000 }); - await exportRequestButtonLocator.click(); + // Complete the export request form + await makeMinimalExportRequest(page, exportRequestButtonLocator); if (tab.indexExportPage?.secondLoadingMessage !== undefined) { await expect( page.getByText(tab.indexExportPage.secondLoadingMessage, { @@ -1150,7 +1128,6 @@ export async function testIndexExportWorkflow( }) ).toBeVisible(); } - // END copying from #4080 const exportActionButtonLocator = page.getByRole("link", { name: tab.indexExportPage?.exportActionButtonText, });