Skip to content

Commit 4b80703

Browse files
authored
chore(e2e) take into account the connection name in e2e tests COMPASS-8002 COMPASS-7970 (#5975)
1 parent cc3acaf commit 4b80703

File tree

10 files changed

+184
-105
lines changed

10 files changed

+184
-105
lines changed

packages/compass-connections-navigation/src/constants.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type Actions =
2222
| 'open-connection-info'
2323
| 'copy-connection-string'
2424
| 'connection-toggle-favorite'
25+
| 'refresh-databases'
2526
// database item related actions
2627
| 'select-database'
2728
| 'create-database'

packages/compass-connections-navigation/src/item-actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ export const connectedConnectionItemActions = ({
100100
icon: 'InfoWithCircle',
101101
label: 'Show connection info',
102102
},
103+
{
104+
action: 'refresh-databases',
105+
label: 'Refresh databases',
106+
icon: 'Refresh',
107+
},
103108
{
104109
action: 'connection-disconnect',
105110
icon: 'Disconnect',

packages/compass-e2e-tests/helpers/commands/connection-workspaces.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export async function navigateToConnectionTab(
1111
if (tabName === 'Databases') {
1212
await browser.clickVisible(Selectors.sidebarConnection(connectionName));
1313
} else {
14-
// TODO(COMPASS-8002): click the three dots menu then the relevant option. (View performance metrics)
14+
await browser.selectConnectionMenuItem(
15+
connectionName,
16+
Selectors.Multiple.ViewPerformanceItem
17+
);
1518
}
1619

1720
await waitUntilActiveConnectionTab(browser, connectionName, tabName);
@@ -29,6 +32,6 @@ export async function waitUntilActiveConnectionTab(
2932
) {
3033
// TODO(COMPASS-8002): we should differentiate by connectionName somehow
3134
await browser
32-
.$(Selectors.instanceWorkspaceTab(tabName, true))
35+
.$(Selectors.connectionWorkspaceTab(tabName, true))
3336
.waitForDisplayed();
3437
}

packages/compass-e2e-tests/helpers/selectors.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,14 @@ export const Single = {
235235
DuplicateConnectionItem: `[data-testid="connection-menu-duplicate-connection-action"]`,
236236
RemoveConnectionItem: `[data-testid="connection-menu-remove-connection-action"]`,
237237
RecentConnections: '[data-testid="recent-connection"]',
238-
238+
CreateDatabaseButton:
239+
'[data-testid="sidebar-navigation-item-actions-open-create-database-action"]',
240+
// for single connections refresh is a button next to add, not a menu item
241+
RefreshDatabasesButton:
242+
'[data-testid="sidebar-navigation-item-actions-refresh-databases-action"]',
243+
ShowTitleActionsButton: '[data-testid="sidebar-title-actions-show-actions"]',
244+
ClusterInfoItem:
245+
'[data-testid="sidebar-title-actions-open-connection-info-action"]',
239246
ConnectionsMenuButton: `[data-testid="favorite-connections-list-header"] button[title="Show actions"]`,
240247
ConnectionsMenu: '[data-testid="favorites-menu"]',
241248
ExportConnectionsModalOpen:
@@ -249,8 +256,7 @@ export const Multiple = {
249256
ConnectionsTitle: '[data-testid="sidebar-header"]',
250257
SidebarNewConnectionButton: '[data-action="add-new-connection"]',
251258
ConnectionMenu: '[data-testid="sidebar-navigation-item-actions"]',
252-
253-
CreateDatabaseItem:
259+
CreateDatabaseButton:
254260
'[data-testid="sidebar-navigation-item-actions-create-database-action"]',
255261
OpenShellItem:
256262
'[data-testid="sidebar-navigation-item-actions-open-shell-action"]',
@@ -260,7 +266,6 @@ export const Multiple = {
260266
'[data-testid="sidebar-navigation-item-actions-open-connection-info-action"]',
261267
DisconnectConnectionItem:
262268
'[data-testid="sidebar-navigation-item-actions-connection-disconnect-action"]',
263-
264269
EditConnectionItem:
265270
'[data-testid="sidebar-navigation-item-actions-edit-connection-action"]',
266271
CopyConnectionStringItem:
@@ -270,6 +275,11 @@ export const Multiple = {
270275
DuplicateConnectionItem: `[data-testid="sidebar-navigation-item-actions-duplicate-connection-action"]`,
271276
RemoveConnectionItem: `[data-testid="sidebar-navigation-item-actions-remove-connection-action"]`,
272277

278+
// for multiple connections refresh is a menu item, not a button next to add database
279+
RefreshDatabasesItem:
280+
'[data-testid="sidebar-navigation-item-actions-refresh-databases-action"]',
281+
ClusterInfoItem:
282+
'[data-testid="sidebar-navigation-item-actions-open-connection-info-action"]',
273283
ConnectionsMenuButton:
274284
'[data-testid="connections-list-title-actions-show-actions"]',
275285
ConnectionsMenu: '[data-testid="connections-list-title-actions"]',
@@ -299,28 +309,16 @@ export const SidebarNavigationTree = '[data-testid="sidebar-navigation-tree"]';
299309
export const SidebarTreeItems = `${SidebarNavigationTree} [role="treeitem"]`;
300310
export const SidebarFilterInput = '[data-testid="sidebar-filter-input"]';
301311
export const SidebarTitle = '[data-testid="sidebar-title"]';
302-
export const SidebarShowActions =
303-
'[data-testid="sidebar-title-actions-show-actions"]';
304-
export const SidebarActionClusterInfo =
305-
'[data-testid="sidebar-title-actions-open-connection-info-action"]';
306-
export const SidebarCreateDatabaseButton =
307-
'[data-testid="sidebar-navigation-item-actions-open-create-database-action"]';
308-
export const SidebarRefreshDatabasesButton =
309-
'[data-testid="sidebar-navigation-item-actions-refresh-databases-action"]';
310312
export const SidebarNavigationItemShowActionsButton =
311313
'[data-testid="sidebar-navigation-item-actions-show-actions"]';
312-
export const DropDatabaseButton = '[data-action="drop-database"]';
313-
export const CreateCollectionButton = '[data-action="create-collection"]';
314314
export const RenameCollectionButton =
315315
'[data-testid="sidebar-navigation-item-actions-rename-collection-action"]';
316+
export const DropDatabaseButton = '[data-action="drop-database"]';
317+
export const CreateCollectionButton = '[data-action="create-collection"]';
316318
export const DropCollectionButton = '[data-action="drop-collection"]';
319+
317320
export const FleConnectionConfigurationBanner =
318321
'[data-testid="fle-connection-configuration"]';
319-
export const SetCSFLEEnabledLabel = '[id="set-csfle-enabled"]';
320-
export const CSFLEConnectionModal = '[data-testid="csfle-connection-modal"]';
321-
export const CSFLEConnectionModalCloseButton = `${CSFLEConnectionModal} [aria-label*="Close"]`;
322-
export const ConnectionInfoModal = '[data-testid="connection-info-modal"]';
323-
export const ConnectionInfoModalCloseButton = `${ConnectionInfoModal} [aria-label*="Close"]`;
324322

325323
export const sidebarDatabase = (dbName: string): string => {
326324
return `${Sidebar} [data-database-name="${dbName}"]`;
@@ -358,6 +356,15 @@ export const sidebarFavorite = (favoriteName: string): string => {
358356
return `${Single.FavoriteConnections}[data-id="favorite-connection-${favoriteName}"]`;
359357
};
360358

359+
// CSFLE modal
360+
export const SetCSFLEEnabledLabel = '[id="set-csfle-enabled"]';
361+
export const CSFLEConnectionModal = '[data-testid="csfle-connection-modal"]';
362+
export const CSFLEConnectionModalCloseButton = `${CSFLEConnectionModal} [aria-label*="Close"]`;
363+
364+
// Connection Info modal
365+
export const ConnectionInfoModal = '[data-testid="connection-info-modal"]';
366+
export const ConnectionInfoModalCloseButton = `${ConnectionInfoModal} [aria-label*="Close"]`;
367+
361368
// Favorite modal
362369
export const FavoriteModal = '[data-testid="favorite-modal"]';
363370
export const FavoriteNameInput = '[data-testid="favorite-name-input"]';
@@ -1184,7 +1191,7 @@ export const workspaceTab = (
11841191
: `[data-namespace="${title}"]`;
11851192
return `${WorkspaceTab}${_title}${_active}`;
11861193
};
1187-
export const instanceWorkspaceTab = (
1194+
export const connectionWorkspaceTab = (
11881195
tabName: 'Performance' | 'Databases',
11891196
active: boolean | null = null
11901197
) => {

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

Lines changed: 100 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
skipForWeb,
1515
TEST_COMPASS_WEB,
1616
TEST_MULTIPLE_CONNECTIONS,
17+
connectionNameFromString,
1718
} from '../helpers/compass';
1819
import type { Compass } from '../helpers/compass';
1920
import type { ConnectFormState } from '../helpers/connect-form-state';
@@ -125,6 +126,8 @@ function generateIamSessionToken(): {
125126

126127
async function assertCanReadData(
127128
browser: CompassBrowser,
129+
// TODO(COMPASS-8002): take into account connectionName
130+
connectionName: string,
128131
dbName: string,
129132
collectionName: string
130133
): Promise<void> {
@@ -139,6 +142,8 @@ async function assertCanReadData(
139142

140143
async function assertCannotInsertData(
141144
browser: CompassBrowser,
145+
// TODO(COMPASS-8002): take into account connectionName
146+
connectionName: string,
142147
dbName: string,
143148
collectionName: string
144149
): Promise<void> {
@@ -178,12 +183,23 @@ async function assertCannotInsertData(
178183

179184
async function assertCannotCreateDb(
180185
browser: CompassBrowser,
186+
connectionName: string,
181187
dbName: string,
182188
collectionName: string
183189
): Promise<void> {
190+
const Sidebar = TEST_MULTIPLE_CONNECTIONS
191+
? Selectors.Multiple
192+
: Selectors.Single;
193+
194+
if (TEST_MULTIPLE_CONNECTIONS) {
195+
// navigate to the databases tab so that the connection is
196+
// active/highlighted and then the add button and three dot menu will
197+
// display without needing to hover
198+
await browser.navigateToConnectionTab(connectionName, 'Databases');
199+
}
200+
184201
// open the create database modal from the sidebar
185-
// TODO(COMPASS-8002): add support for multiple connections
186-
await browser.clickVisible(Selectors.SidebarCreateDatabaseButton);
202+
await browser.clickVisible(Sidebar.CreateDatabaseButton);
187203

188204
const createModalElement = await browser.$(Selectors.CreateDatabaseModal);
189205
await createModalElement.waitForDisplayed();
@@ -212,6 +228,8 @@ async function assertCannotCreateDb(
212228

213229
async function assertCannotCreateCollection(
214230
browser: CompassBrowser,
231+
// TODO(COMPASS-8002): take into account connectionName
232+
connectionName: string,
215233
dbName: string,
216234
collectionName: string
217235
): Promise<void> {
@@ -436,7 +454,16 @@ describe('Connection string', function () {
436454
expect(result).to.have.property('ok', 1);
437455
}
438456

439-
await assertCanReadData(browser, 'compass_e2e', 'companies_info');
457+
const connectionName = connectionNameFromString(
458+
process.env.E2E_TESTS_ATLAS_READWRITEANY_STRING ?? ''
459+
);
460+
461+
await assertCanReadData(
462+
browser,
463+
connectionName,
464+
'compass_e2e',
465+
'companies_info'
466+
);
440467
});
441468

442469
it('can connect with readAnyDatabase builtin role', async function () {
@@ -457,16 +484,31 @@ describe('Connection string', function () {
457484
expect(result).to.have.property('ok', 1);
458485
}
459486

460-
await assertCanReadData(browser, 'compass_e2e', 'companies_info');
461-
await assertCannotInsertData(browser, 'compass_e2e', 'companies_info');
462-
// TODO(COMPASS-8002: we need to click the active connection's add database
463-
// button and therefore might as well wait for the active&saved connections
464-
// to be unified
465-
if (!TEST_MULTIPLE_CONNECTIONS) {
466-
await assertCannotCreateDb(browser, 'new-db', 'new-collection');
467-
}
487+
const connectionName = connectionNameFromString(
488+
process.env.E2E_TESTS_ATLAS_READANYDATABASE_STRING ?? ''
489+
);
490+
491+
await assertCanReadData(
492+
browser,
493+
connectionName,
494+
'compass_e2e',
495+
'companies_info'
496+
);
497+
await assertCannotInsertData(
498+
browser,
499+
connectionName,
500+
'compass_e2e',
501+
'companies_info'
502+
);
503+
await assertCannotCreateDb(
504+
browser,
505+
connectionName,
506+
'new-db',
507+
'new-collection'
508+
);
468509
await assertCannotCreateCollection(
469510
browser,
511+
connectionName,
470512
'compass_e2e',
471513
'new-collection'
472514
);
@@ -490,14 +532,23 @@ describe('Connection string', function () {
490532
expect(result).to.have.property('ok', 1);
491533
}
492534

493-
await assertCanReadData(browser, 'test', 'users');
494-
// TODO(COMPASS-8002: we need to click the active connection's add database
495-
// button and therefore might as well wait for the active&saved connections
496-
// to be unified
497-
if (!TEST_MULTIPLE_CONNECTIONS) {
498-
await assertCannotCreateDb(browser, 'new-db', 'new-collection');
499-
}
500-
await assertCannotCreateCollection(browser, 'test', 'new-collection');
535+
const connectionName = connectionNameFromString(
536+
process.env.E2E_TESTS_ATLAS_CUSTOMROLE_STRING ?? ''
537+
);
538+
539+
await assertCanReadData(browser, connectionName, 'test', 'users');
540+
await assertCannotCreateDb(
541+
browser,
542+
connectionName,
543+
'new-db',
544+
'new-collection'
545+
);
546+
await assertCannotCreateCollection(
547+
browser,
548+
connectionName,
549+
'test',
550+
'new-collection'
551+
);
501552
});
502553

503554
it('can connect with read one collection specific permission', async function () {
@@ -518,15 +569,24 @@ describe('Connection string', function () {
518569
expect(result).to.have.property('ok', 1);
519570
}
520571

521-
await assertCanReadData(browser, 'test', 'users');
522-
await assertCannotInsertData(browser, 'test', 'users');
523-
// TODO(COMPASS-8002: we need to click the active connection's add database
524-
// button and therefore might as well wait for the active&saved connections
525-
// to be unified
526-
if (!TEST_MULTIPLE_CONNECTIONS) {
527-
await assertCannotCreateDb(browser, 'new-db', 'new-collection');
528-
}
529-
await assertCannotCreateCollection(browser, 'test', 'new-collection');
572+
const connectionName = connectionNameFromString(
573+
process.env.E2E_TESTS_ATLAS_CUSTOMROLE_STRING ?? ''
574+
);
575+
576+
await assertCanReadData(browser, connectionName, 'test', 'users');
577+
await assertCannotInsertData(browser, connectionName, 'test', 'users');
578+
await assertCannotCreateDb(
579+
browser,
580+
connectionName,
581+
'new-db',
582+
'new-collection'
583+
);
584+
await assertCannotCreateCollection(
585+
browser,
586+
connectionName,
587+
'test',
588+
'new-collection'
589+
);
530590
});
531591
});
532592

@@ -555,9 +615,11 @@ describe('Connection form', function () {
555615
});
556616

557617
it('can connect using connection form', async function () {
618+
const connectionName = this.test?.fullTitle();
619+
558620
await browser.connectWithConnectionForm({
559621
hosts: ['127.0.0.1:27091'],
560-
connectionName: this.test?.fullTitle(),
622+
connectionName,
561623
});
562624
if (!TEST_MULTIPLE_CONNECTIONS) {
563625
const result = await browser.shellEval(
@@ -574,12 +636,14 @@ describe('Connection form', function () {
574636
return this.skip();
575637
}
576638

639+
const connectionName = this.test?.fullTitle();
640+
577641
const atlasConnectionOptions: ConnectFormState = basicAtlasOptions(
578642
process.env.E2E_TESTS_ATLAS_HOST ?? ''
579643
);
580644
await browser.connectWithConnectionForm({
581645
...atlasConnectionOptions,
582-
connectionName: this.test?.fullTitle(),
646+
connectionName,
583647
});
584648
if (!TEST_MULTIPLE_CONNECTIONS) {
585649
const result = await browser.shellEval(
@@ -596,6 +660,8 @@ describe('Connection form', function () {
596660
return this.skip();
597661
}
598662

663+
const connectionName = this.test?.fullTitle();
664+
599665
let tempdir;
600666
try {
601667
tempdir = await fs.mkdtemp(path.join(os.tmpdir(), 'connect-tests-'));
@@ -611,7 +677,7 @@ describe('Connection form', function () {
611677
};
612678
await browser.connectWithConnectionForm({
613679
...atlasConnectionOptions,
614-
connectionName: this.test?.fullTitle(),
680+
connectionName,
615681
});
616682
if (!TEST_MULTIPLE_CONNECTIONS) {
617683
const result = await browser.shellEval(
@@ -633,6 +699,8 @@ describe('Connection form', function () {
633699
return this.skip();
634700
}
635701

702+
const connectionName = this.test?.fullTitle();
703+
636704
const atlasConnectionOptions: ConnectFormState = {
637705
hosts: [process.env.E2E_TESTS_FREE_TIER_HOST ?? ''],
638706
authMethod: 'MONGODB-AWS',
@@ -643,7 +711,7 @@ describe('Connection form', function () {
643711
};
644712
await browser.connectWithConnectionForm({
645713
...atlasConnectionOptions,
646-
connectionName: this.test?.fullTitle(),
714+
connectionName,
647715
});
648716
if (!TEST_MULTIPLE_CONNECTIONS) {
649717
const result = await browser.shellEval(

0 commit comments

Comments
 (0)