Skip to content

Commit

Permalink
clean up confirmation action
Browse files Browse the repository at this point in the history
  • Loading branch information
mabaasit committed Nov 1, 2024
1 parent 90fbc55 commit 84cdf1c
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -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 });
}
18 changes: 4 additions & 14 deletions packages/compass-e2e-tests/helpers/commands/hide-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions packages/compass-e2e-tests/helpers/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
17 changes: 4 additions & 13 deletions packages/compass-e2e-tests/helpers/commands/unhide-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand All @@ -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 });
});
});

Expand Down
9 changes: 1 addition & 8 deletions packages/compass-e2e-tests/tests/connection-form.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 3 additions & 5 deletions packages/compass-e2e-tests/tests/my-queries-tab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
12 changes: 4 additions & 8 deletions packages/compass-e2e-tests/tests/search-indexes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 84cdf1c

Please sign in to comment.