Skip to content

Commit 84cdf1c

Browse files
committed
clean up confirmation action
1 parent 90fbc55 commit 84cdf1c

File tree

10 files changed

+50
-86
lines changed

10 files changed

+50
-86
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { CompassBrowser } from '../compass-browser';
2+
import * as Selectors from '../selectors';
3+
4+
export async function clickConfirmationAction(
5+
browser: CompassBrowser,
6+
actionButtonSelector: string,
7+
confirmationText?: string,
8+
screenshot?: string
9+
) {
10+
await browser.clickVisible(actionButtonSelector);
11+
12+
const confirmationModal = await browser.$(Selectors.ConfirmationModal);
13+
await confirmationModal.waitForDisplayed();
14+
15+
if (confirmationText) {
16+
await browser.setValueVisible(
17+
Selectors.ConfirmationModalInput,
18+
confirmationText
19+
);
20+
}
21+
22+
if (screenshot) {
23+
await browser.screenshot(screenshot);
24+
}
25+
26+
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
27+
await confirmationModal.waitForDisplayed({ reverse: true });
28+
}

packages/compass-e2e-tests/helpers/commands/hide-index.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,11 @@ export async function hideIndex(
1111
await indexComponent.waitForDisplayed();
1212

1313
await browser.hover(indexComponentSelector);
14-
await browser.clickVisible(
15-
`${indexComponentSelector} ${Selectors.HideIndexButton}`
14+
await browser.clickConfirmationAction(
15+
`${indexComponentSelector} ${Selectors.HideIndexButton}`,
16+
undefined,
17+
screenshotName
1618
);
17-
18-
const hideModal = await browser.$(Selectors.ConfirmationModal);
19-
await hideModal.waitForDisplayed();
20-
21-
if (screenshotName) {
22-
await browser.screenshot(screenshotName);
23-
}
24-
25-
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
26-
27-
await hideModal.waitForDisplayed({ reverse: true });
28-
2919
const hiddenBadge = await browser.$(Selectors.HiddenIndexBadge(indexName));
3020
await hiddenBadge.waitForDisplayed();
3121
}

packages/compass-e2e-tests/helpers/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ export * from './hide-visible-toasts';
6464
export * from './sidebar-collection';
6565
export * from './read-first-document-content';
6666
export * from './read-stage-operators';
67+
export * from './click-confirmation-action';

packages/compass-e2e-tests/helpers/commands/unhide-index.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,12 @@ export async function unhideIndex(
1111
await indexComponent.waitForDisplayed();
1212

1313
await browser.hover(indexComponentSelector);
14-
await browser.clickVisible(
15-
`${indexComponentSelector} ${Selectors.UnhideIndexButton}`
14+
await browser.clickConfirmationAction(
15+
`${indexComponentSelector} ${Selectors.UnhideIndexButton}`,
16+
undefined,
17+
screenshotName
1618
);
1719

18-
const unhideModal = await browser.$(Selectors.ConfirmationModal);
19-
await unhideModal.waitForDisplayed();
20-
21-
if (screenshotName) {
22-
await browser.screenshot(screenshotName);
23-
}
24-
25-
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
26-
27-
await unhideModal.waitForDisplayed({ reverse: true });
28-
2920
const hiddenBadge = await browser.$(Selectors.HiddenIndexBadge(indexName));
3021
await hiddenBadge.waitForDisplayed({ reverse: true });
3122
}

packages/compass-e2e-tests/tests/atlas-cloud/global-writes.test.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ async function waitForState(
4848
});
4949
}
5050

51-
async function clickConfirmationAction(
52-
browser: CompassBrowser,
53-
actionSelector: string
54-
) {
55-
await browser.clickVisible(actionSelector);
56-
57-
const modalElement = await browser.$(Selectors.ConfirmationModal);
58-
await modalElement.waitForDisplayed();
59-
60-
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
61-
await modalElement.waitForDisplayed({ reverse: true });
62-
}
63-
6451
describe('Global writes', function () {
6552
let compass: Compass;
6653
let browser: CompassBrowser;
@@ -146,8 +133,7 @@ describe('Global writes', function () {
146133
await waitForState(browser, 'SHARDING');
147134

148135
// Cancel the sharding operation.
149-
await clickConfirmationAction(
150-
browser,
136+
await browser.clickConfirmationAction(
151137
Selectors.GlobalWrites.CancelShardingButton
152138
);
153139

packages/compass-e2e-tests/tests/collection-aggregations-tab.test.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,13 +1011,7 @@ describe('Collection aggregations tab', function () {
10111011

10121012
it('shows confirmation modal when create new pipeline is clicked and aggregation is modified', async function () {
10131013
await browser.selectStageOperator(0, '$match');
1014-
1015-
await browser.clickVisible(Selectors.CreateNewPipelineButton);
1016-
const modalElement = await browser.$(Selectors.ConfirmationModal);
1017-
await modalElement.waitForDisplayed();
1018-
1019-
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
1020-
await modalElement.waitForDisplayed({ reverse: true });
1014+
await browser.clickConfirmationAction(Selectors.CreateNewPipelineButton);
10211015
});
10221016

10231017
describe('aggregation builder in text mode', function () {
@@ -1258,14 +1252,9 @@ describe('Collection aggregations tab', function () {
12581252
);
12591253
await browser.hover(Selectors.AggregationSavedPipelineCard(name));
12601254

1261-
await browser.clickVisible(
1255+
await browser.clickConfirmationAction(
12621256
Selectors.AggregationSavedPipelineCardOpenButton(name)
12631257
);
1264-
1265-
const confirmOpenModal = await browser.$(Selectors.ConfirmationModal);
1266-
await confirmOpenModal.waitForDisplayed();
1267-
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
1268-
await confirmOpenModal.waitForDisplayed({ reverse: true });
12691258
});
12701259

12711260
it('deletes an aggregation', async function () {
@@ -1278,14 +1267,9 @@ describe('Collection aggregations tab', function () {
12781267
);
12791268
await browser.hover(Selectors.AggregationSavedPipelineCard(name));
12801269

1281-
await browser.clickVisible(
1270+
await browser.clickConfirmationAction(
12821271
Selectors.AggregationSavedPipelineCardDeleteButton(name)
12831272
);
1284-
1285-
const confirmDeleteModal = await browser.$(Selectors.ConfirmationModal);
1286-
await confirmDeleteModal.waitForDisplayed();
1287-
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
1288-
await confirmDeleteModal.waitForDisplayed({ reverse: true });
12891273
});
12901274
});
12911275

packages/compass-e2e-tests/tests/connection-form.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,14 +670,7 @@ describe('Connection form', function () {
670670
// toggle the edit connection string toggle twice
671671
await browser.clickVisible(Selectors.EditConnectionStringToggle);
672672
expect(await toggle.getAttribute('aria-checked')).to.equal('false');
673-
await browser.clickVisible(Selectors.EditConnectionStringToggle);
674-
675-
const confirmModal = await browser.$(Selectors.ConfirmationModal);
676-
await confirmModal.waitForDisplayed();
677-
678-
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
679-
680-
await confirmModal.waitForDisplayed({ reverse: true });
673+
await browser.clickConfirmationAction(Selectors.EditConnectionStringToggle);
681674

682675
// the toggle should now be on
683676
expect(await toggle.getAttribute('aria-checked')).to.equal('true');

packages/compass-e2e-tests/tests/my-queries-tab.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,9 @@ describe('My Queries tab', function () {
301301
await openMenuForQueryItem(browser, newFavoriteQueryName);
302302

303303
// delete it
304-
await browser.clickVisible(Selectors.SavedItemMenuItemDelete);
305-
const deleteModal = await browser.$(Selectors.ConfirmationModal);
306-
await deleteModal.waitForDisplayed();
307-
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
308-
await renameModal.waitForDisplayed({ reverse: true });
304+
await browser.clickConfirmationAction(
305+
Selectors.SavedItemMenuItemDelete
306+
);
309307
});
310308

311309
it('opens a saved aggregation', async function () {

packages/compass-e2e-tests/tests/protect-connection-strings.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ describe('protectConnectionStrings', function () {
8787
);
8888

8989
// Enter edit connection string mode
90-
await browser.clickVisible(Selectors.EditConnectionStringToggle);
91-
const confirmModal = await browser.$(Selectors.ConfirmationModal);
92-
await confirmModal.waitForDisplayed();
93-
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
90+
await browser.clickConfirmationAction(Selectors.EditConnectionStringToggle);
9491

9592
expect(
9693
await browser.getConnectFormConnectionString(),

packages/compass-e2e-tests/tests/search-indexes.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,11 @@ async function dropSearchIndex(browser: CompassBrowser, indexName: string) {
108108
await indexRow.waitForDisplayed();
109109

110110
await browser.hover(indexRowSelector);
111-
await browser.clickVisible(Selectors.searchIndexDropButton(indexName));
112111

113-
const modal = await browser.$(Selectors.ConfirmationModal);
114-
await modal.waitForDisplayed();
115-
116-
await browser.setValueVisible(Selectors.ConfirmationModalInput, indexName);
117-
118-
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
119-
await modal.waitForDisplayed({ reverse: true });
112+
await browser.clickConfirmationAction(
113+
Selectors.searchIndexDropButton(indexName),
114+
indexName
115+
);
120116

121117
await indexRow.waitForExist({
122118
reverse: true,

0 commit comments

Comments
 (0)