From 84cdf1c06e80226addced579ed4bc89057795ccd Mon Sep 17 00:00:00 2001 From: Basit Chonka Date: Fri, 1 Nov 2024 11:52:51 +0100 Subject: [PATCH] clean up confirmation action --- .../commands/click-confirmation-action.ts | 28 +++++++++++++++++++ .../helpers/commands/hide-index.ts | 18 +++--------- .../helpers/commands/index.ts | 1 + .../helpers/commands/unhide-index.ts | 17 +++-------- .../tests/atlas-cloud/global-writes.test.ts | 16 +---------- .../tests/collection-aggregations-tab.test.ts | 22 ++------------- .../tests/connection-form.test.ts | 9 +----- .../tests/my-queries-tab.test.ts | 8 ++---- .../tests/protect-connection-strings.test.ts | 5 +--- .../tests/search-indexes.test.ts | 12 +++----- 10 files changed, 50 insertions(+), 86 deletions(-) create mode 100644 packages/compass-e2e-tests/helpers/commands/click-confirmation-action.ts diff --git a/packages/compass-e2e-tests/helpers/commands/click-confirmation-action.ts b/packages/compass-e2e-tests/helpers/commands/click-confirmation-action.ts new file mode 100644 index 00000000000..9524c4ef5a3 --- /dev/null +++ b/packages/compass-e2e-tests/helpers/commands/click-confirmation-action.ts @@ -0,0 +1,28 @@ +import type { CompassBrowser } from '../compass-browser'; +import * as Selectors from '../selectors'; + +export async function clickConfirmationAction( + browser: CompassBrowser, + actionButtonSelector: string, + confirmationText?: string, + screenshot?: string +) { + await browser.clickVisible(actionButtonSelector); + + const confirmationModal = await browser.$(Selectors.ConfirmationModal); + await confirmationModal.waitForDisplayed(); + + if (confirmationText) { + await browser.setValueVisible( + Selectors.ConfirmationModalInput, + confirmationText + ); + } + + if (screenshot) { + await browser.screenshot(screenshot); + } + + await browser.clickVisible(Selectors.confirmationModalConfirmButton()); + await confirmationModal.waitForDisplayed({ reverse: true }); +} diff --git a/packages/compass-e2e-tests/helpers/commands/hide-index.ts b/packages/compass-e2e-tests/helpers/commands/hide-index.ts index ed1d0e5b6c6..d082ab91a98 100644 --- a/packages/compass-e2e-tests/helpers/commands/hide-index.ts +++ b/packages/compass-e2e-tests/helpers/commands/hide-index.ts @@ -11,21 +11,11 @@ export async function hideIndex( await indexComponent.waitForDisplayed(); await browser.hover(indexComponentSelector); - await browser.clickVisible( - `${indexComponentSelector} ${Selectors.HideIndexButton}` + await browser.clickConfirmationAction( + `${indexComponentSelector} ${Selectors.HideIndexButton}`, + undefined, + screenshotName ); - - const hideModal = await browser.$(Selectors.ConfirmationModal); - await hideModal.waitForDisplayed(); - - if (screenshotName) { - await browser.screenshot(screenshotName); - } - - await browser.clickVisible(Selectors.confirmationModalConfirmButton()); - - await hideModal.waitForDisplayed({ reverse: true }); - const hiddenBadge = await browser.$(Selectors.HiddenIndexBadge(indexName)); await hiddenBadge.waitForDisplayed(); } diff --git a/packages/compass-e2e-tests/helpers/commands/index.ts b/packages/compass-e2e-tests/helpers/commands/index.ts index 2ad04e81f01..080501905f9 100644 --- a/packages/compass-e2e-tests/helpers/commands/index.ts +++ b/packages/compass-e2e-tests/helpers/commands/index.ts @@ -64,3 +64,4 @@ export * from './hide-visible-toasts'; export * from './sidebar-collection'; export * from './read-first-document-content'; export * from './read-stage-operators'; +export * from './click-confirmation-action'; diff --git a/packages/compass-e2e-tests/helpers/commands/unhide-index.ts b/packages/compass-e2e-tests/helpers/commands/unhide-index.ts index 305ce3cea96..4d7e3905b7f 100644 --- a/packages/compass-e2e-tests/helpers/commands/unhide-index.ts +++ b/packages/compass-e2e-tests/helpers/commands/unhide-index.ts @@ -11,21 +11,12 @@ export async function unhideIndex( await indexComponent.waitForDisplayed(); await browser.hover(indexComponentSelector); - await browser.clickVisible( - `${indexComponentSelector} ${Selectors.UnhideIndexButton}` + await browser.clickConfirmationAction( + `${indexComponentSelector} ${Selectors.UnhideIndexButton}`, + undefined, + screenshotName ); - const unhideModal = await browser.$(Selectors.ConfirmationModal); - await unhideModal.waitForDisplayed(); - - if (screenshotName) { - await browser.screenshot(screenshotName); - } - - await browser.clickVisible(Selectors.confirmationModalConfirmButton()); - - await unhideModal.waitForDisplayed({ reverse: true }); - const hiddenBadge = await browser.$(Selectors.HiddenIndexBadge(indexName)); await hiddenBadge.waitForDisplayed({ reverse: true }); } diff --git a/packages/compass-e2e-tests/tests/atlas-cloud/global-writes.test.ts b/packages/compass-e2e-tests/tests/atlas-cloud/global-writes.test.ts index 51cda604c6e..a08135eac57 100644 --- a/packages/compass-e2e-tests/tests/atlas-cloud/global-writes.test.ts +++ b/packages/compass-e2e-tests/tests/atlas-cloud/global-writes.test.ts @@ -48,19 +48,6 @@ async function waitForState( }); } -async function clickConfirmationAction( - browser: CompassBrowser, - actionSelector: string -) { - await browser.clickVisible(actionSelector); - - const modalElement = await browser.$(Selectors.ConfirmationModal); - await modalElement.waitForDisplayed(); - - await browser.clickVisible(Selectors.confirmationModalConfirmButton()); - await modalElement.waitForDisplayed({ reverse: true }); -} - describe('Global writes', function () { let compass: Compass; let browser: CompassBrowser; @@ -146,8 +133,7 @@ describe('Global writes', function () { await waitForState(browser, 'SHARDING'); // Cancel the sharding operation. - await clickConfirmationAction( - browser, + await browser.clickConfirmationAction( Selectors.GlobalWrites.CancelShardingButton ); diff --git a/packages/compass-e2e-tests/tests/collection-aggregations-tab.test.ts b/packages/compass-e2e-tests/tests/collection-aggregations-tab.test.ts index 2dd52fbe505..f4db128dfd3 100644 --- a/packages/compass-e2e-tests/tests/collection-aggregations-tab.test.ts +++ b/packages/compass-e2e-tests/tests/collection-aggregations-tab.test.ts @@ -1011,13 +1011,7 @@ describe('Collection aggregations tab', function () { it('shows confirmation modal when create new pipeline is clicked and aggregation is modified', async function () { await browser.selectStageOperator(0, '$match'); - - await browser.clickVisible(Selectors.CreateNewPipelineButton); - const modalElement = await browser.$(Selectors.ConfirmationModal); - await modalElement.waitForDisplayed(); - - await browser.clickVisible(Selectors.confirmationModalConfirmButton()); - await modalElement.waitForDisplayed({ reverse: true }); + await browser.clickConfirmationAction(Selectors.CreateNewPipelineButton); }); describe('aggregation builder in text mode', function () { @@ -1258,14 +1252,9 @@ describe('Collection aggregations tab', function () { ); await browser.hover(Selectors.AggregationSavedPipelineCard(name)); - await browser.clickVisible( + await browser.clickConfirmationAction( Selectors.AggregationSavedPipelineCardOpenButton(name) ); - - const confirmOpenModal = await browser.$(Selectors.ConfirmationModal); - await confirmOpenModal.waitForDisplayed(); - await browser.clickVisible(Selectors.confirmationModalConfirmButton()); - await confirmOpenModal.waitForDisplayed({ reverse: true }); }); it('deletes an aggregation', async function () { @@ -1278,14 +1267,9 @@ describe('Collection aggregations tab', function () { ); await browser.hover(Selectors.AggregationSavedPipelineCard(name)); - await browser.clickVisible( + await browser.clickConfirmationAction( Selectors.AggregationSavedPipelineCardDeleteButton(name) ); - - const confirmDeleteModal = await browser.$(Selectors.ConfirmationModal); - await confirmDeleteModal.waitForDisplayed(); - await browser.clickVisible(Selectors.confirmationModalConfirmButton()); - await confirmDeleteModal.waitForDisplayed({ reverse: true }); }); }); diff --git a/packages/compass-e2e-tests/tests/connection-form.test.ts b/packages/compass-e2e-tests/tests/connection-form.test.ts index 111c074f761..98a53f17563 100644 --- a/packages/compass-e2e-tests/tests/connection-form.test.ts +++ b/packages/compass-e2e-tests/tests/connection-form.test.ts @@ -670,14 +670,7 @@ describe('Connection form', function () { // toggle the edit connection string toggle twice await browser.clickVisible(Selectors.EditConnectionStringToggle); expect(await toggle.getAttribute('aria-checked')).to.equal('false'); - await browser.clickVisible(Selectors.EditConnectionStringToggle); - - const confirmModal = await browser.$(Selectors.ConfirmationModal); - await confirmModal.waitForDisplayed(); - - await browser.clickVisible(Selectors.confirmationModalConfirmButton()); - - await confirmModal.waitForDisplayed({ reverse: true }); + await browser.clickConfirmationAction(Selectors.EditConnectionStringToggle); // the toggle should now be on expect(await toggle.getAttribute('aria-checked')).to.equal('true'); diff --git a/packages/compass-e2e-tests/tests/my-queries-tab.test.ts b/packages/compass-e2e-tests/tests/my-queries-tab.test.ts index 58d833dfdf1..2b57d35e2c1 100644 --- a/packages/compass-e2e-tests/tests/my-queries-tab.test.ts +++ b/packages/compass-e2e-tests/tests/my-queries-tab.test.ts @@ -301,11 +301,9 @@ describe('My Queries tab', function () { await openMenuForQueryItem(browser, newFavoriteQueryName); // delete it - await browser.clickVisible(Selectors.SavedItemMenuItemDelete); - const deleteModal = await browser.$(Selectors.ConfirmationModal); - await deleteModal.waitForDisplayed(); - await browser.clickVisible(Selectors.confirmationModalConfirmButton()); - await renameModal.waitForDisplayed({ reverse: true }); + await browser.clickConfirmationAction( + Selectors.SavedItemMenuItemDelete + ); }); it('opens a saved aggregation', async function () { diff --git a/packages/compass-e2e-tests/tests/protect-connection-strings.test.ts b/packages/compass-e2e-tests/tests/protect-connection-strings.test.ts index c20ebc3476f..69197382d29 100644 --- a/packages/compass-e2e-tests/tests/protect-connection-strings.test.ts +++ b/packages/compass-e2e-tests/tests/protect-connection-strings.test.ts @@ -87,10 +87,7 @@ describe('protectConnectionStrings', function () { ); // Enter edit connection string mode - await browser.clickVisible(Selectors.EditConnectionStringToggle); - const confirmModal = await browser.$(Selectors.ConfirmationModal); - await confirmModal.waitForDisplayed(); - await browser.clickVisible(Selectors.confirmationModalConfirmButton()); + await browser.clickConfirmationAction(Selectors.EditConnectionStringToggle); expect( await browser.getConnectFormConnectionString(), diff --git a/packages/compass-e2e-tests/tests/search-indexes.test.ts b/packages/compass-e2e-tests/tests/search-indexes.test.ts index dbe41df9ada..264ecbc40ec 100644 --- a/packages/compass-e2e-tests/tests/search-indexes.test.ts +++ b/packages/compass-e2e-tests/tests/search-indexes.test.ts @@ -108,15 +108,11 @@ async function dropSearchIndex(browser: CompassBrowser, indexName: string) { await indexRow.waitForDisplayed(); await browser.hover(indexRowSelector); - await browser.clickVisible(Selectors.searchIndexDropButton(indexName)); - const modal = await browser.$(Selectors.ConfirmationModal); - await modal.waitForDisplayed(); - - await browser.setValueVisible(Selectors.ConfirmationModalInput, indexName); - - await browser.clickVisible(Selectors.confirmationModalConfirmButton()); - await modal.waitForDisplayed({ reverse: true }); + await browser.clickConfirmationAction( + Selectors.searchIndexDropButton(indexName), + indexName + ); await indexRow.waitForExist({ reverse: true,