Skip to content

Commit

Permalink
chore(e2e): Port usage of saving favourites including all of the in-u…
Browse files Browse the repository at this point in the history
…se-encryption e2e tests to multiple connections COMPASS-8003 (#6021)

* prettier weirdness

* WIP

* port in-use-encryption tests to multiple connections

* remove debugging

* scope some selectors

* inverted check

* rename disconnect to disconnectAll

* move numLines

* non-standard usage
  • Loading branch information
lerouxb authored Jul 15, 2024
1 parent b448512 commit d4ac9df
Show file tree
Hide file tree
Showing 20 changed files with 413 additions and 347 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import type { CompassBrowser } from '../compass-browser';
import type { ConnectFormState } from '../connect-form-state';
import * as Selectors from '../selectors';

export async function connectWithConnectionForm(
browser: CompassBrowser,
options: ConnectFormState,
connectionStatus: 'success' | 'failure' | 'either' = 'success',
timeout?: number
): Promise<void> {
const sidebar = await browser.$(Selectors.SidebarTitle);
if (await sidebar.isDisplayed()) {
await browser.disconnect();
await browser.disconnectAll();

// If a connectionName is specified and a connection already exists with this
// name, make sure we don't add a duplicate so that tests can always address
// this new connection.
if (options.connectionName) {
await browser.removeConnection(options.connectionName);
}

await browser.setConnectFormState(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function connectWithConnectionString(
connectionStatus: 'success' | 'failure' | 'either' = 'success',
timeout?: number
): Promise<void> {
await browser.disconnect();
await browser.disconnectAll();

if (TEST_MULTIPLE_CONNECTIONS) {
// if the modal is still animating away when we're connecting again, things
Expand All @@ -24,25 +24,7 @@ export async function connectWithConnectionString(
// if a connection with this name already exists, remove it otherwise we'll
// add a duplicate and things will get complicated fast
const connectionName = connectionNameFromString(connectionString);

// make sure there's no filter because if the connection is not displayed then we can't remove it
if (await browser.$(Selectors.SidebarFilterInput).isExisting()) {
await browser.clickVisible(Selectors.SidebarFilterInput);
await browser.setValueVisible(Selectors.SidebarFilterInput, '');

// wait for a connection to appear. It must because if there are no
// connections the filter field wouldn't exist in the first place
await browser.$(Selectors.SidebarTreeItems).waitForDisplayed();
}

const selector = Selectors.sidebarConnection(connectionName);
if (await browser.$(selector).isExisting()) {
await browser.selectConnectionMenuItem(
connectionName,
Selectors.Multiple.RemoveConnectionItem
);
await browser.$(selector).waitForExist({ reverse: true });
}
await browser.removeConnection(connectionName);

await browser.clickVisible(Selectors.Multiple.SidebarNewConnectionButton);
await browser.$(Selectors.ConnectionModal).waitForDisplayed();
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-e2e-tests/helpers/commands/disconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Debug from 'debug';

const debug = Debug('compass-e2e-tests');

export async function disconnect(browser: CompassBrowser): Promise<void> {
export async function disconnectAll(browser: CompassBrowser): Promise<void> {
if (TEST_COMPASS_WEB) {
const url = new URL(await browser.getUrl());
url.pathname = '/';
Expand Down
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 @@ -67,3 +67,4 @@ export * from './drop-index';
export * from './hide-index';
export * from './unhide-index';
export * from './hide-visible-toasts';
export * from './remove-connection';
31 changes: 31 additions & 0 deletions packages/compass-e2e-tests/helpers/commands/remove-connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { TEST_MULTIPLE_CONNECTIONS } from '../compass';
import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';

export async function removeConnection(
browser: CompassBrowser,
connectionName: string
): Promise<void> {
if (!TEST_MULTIPLE_CONNECTIONS) {
return;
}

// make sure there's no filter because if the connection is not displayed then we can't remove it
if (await browser.$(Selectors.SidebarFilterInput).isExisting()) {
await browser.clickVisible(Selectors.SidebarFilterInput);
await browser.setValueVisible(Selectors.SidebarFilterInput, '');

// wait for a connection to appear. It must because if there are no
// connections the filter field wouldn't exist in the first place
await browser.$(Selectors.SidebarTreeItems).waitForDisplayed();
}

const selector = Selectors.sidebarConnection(connectionName);
if (await browser.$(selector).isExisting()) {
await browser.selectConnectionMenuItem(
connectionName,
Selectors.Multiple.RemoveConnectionItem
);
await browser.$(selector).waitForExist({ reverse: true });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';
import { TEST_MULTIPLE_CONNECTIONS } from '../compass';

// TODO(COMPASS-8003,COMPASS-8023): Just remove this command and use
// setConnectionFormState() once we remove the single connection code
// TODO(COMPASS-8023): Just remove this command and use setConnectionFormState()
// once we remove the single connection code
export async function saveConnectionStringAsFavorite(
browser: CompassBrowser,
connectionString: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';
import { expect } from 'chai';

// TODO(COMPASS-8003,COMPASS-8023): Just remove this command and use
// TODO(COMPASS-8023): Just remove this command and use
// setConnectionFormState() once we remove the single connection code
export async function saveFavorite(
browser: CompassBrowser,
Expand Down
45 changes: 28 additions & 17 deletions packages/compass-e2e-tests/helpers/commands/shell-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,43 @@ async function getOutputText(browser: CompassBrowser): Promise<string[]> {
export async function shellEval(
browser: CompassBrowser,
connectionName: string,
str: string,
input: string | string[],
parse = false
): Promise<string> {
// Keep in mind that for multiple connections this will open a new tab and
// focus it.
await browser.openShell(connectionName);

const numLines = (await getOutputText(browser)).length;
const strings = Array.isArray(input) ? input : [input];

const command = parse === true ? `JSON.stringify(${str})` : str;
for (const str of strings) {
const numLines = (await getOutputText(browser)).length;

await browser.setCodemirrorEditorValue(Selectors.ShellInputEditor, command);
await browser.keys(['Enter']);
const command = parse === true ? `JSON.stringify(${str})` : str;

// wait until more output appears
await browser.waitUntil(async () => {
const lines = await getOutputText(browser);
return (
lines.length >
/**
* input line becomes an output line on enter press, so we are waiting
* for two new lines to appear, not just one
*/
numLines + 1
);
});
await browser.setCodemirrorEditorValue(Selectors.ShellInputEditor, command);
await browser.keys(['Enter']);

// wait until more output appears
await browser.waitUntil(async () => {
const lines = await getOutputText(browser);
if (
lines.length >
/**
* input line becomes an output line on enter press, so we are waiting
* for two new lines to appear, not just one
*/
numLines + 1
) {
// make sure the prompt shows up before entering another line or continueing on
await browser
.$(`${Selectors.ShellInput} [aria-label="Chevron Right Icon"]`)
.waitForDisplayed();
return true;
}
return false;
});
}

const output = await getOutputText(browser);

Expand Down
15 changes: 12 additions & 3 deletions packages/compass-e2e-tests/helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ export const Single = {
'[data-testid="favorites-menu-export-saved-connections-action"]',
ImportConnectionsModalOpen:
'[data-testid="favorites-menu-import-saved-connections-action"]',

InUseEncryptionMarker: '[data-testid="fle-connection-configuration"]',
};

// Multiple Connections sidebar
Expand Down Expand Up @@ -296,6 +298,8 @@ export const Multiple = {
'[data-testid="connections-list-title-actions-export-saved-connections-action"]',
ImportConnectionsModalOpen:
'[data-testid="connections-list-title-actions-import-saved-connections-action"]',

InUseEncryptionMarker: '[data-action="open-csfle-modal"]',
};

// Rename Collection Modal
Expand Down Expand Up @@ -327,9 +331,6 @@ export const CreateCollectionButton = '[data-action="create-collection"]';
export const DropCollectionButton = '[data-action="drop-collection"]';
export const DatabaseCollectionPlaceholder = '[data-testid="placeholder"]';

export const FleConnectionConfigurationBanner =
'[data-testid="fle-connection-configuration"]';

export const sidebarDatabase = (dbName: string): string => {
return `${Sidebar} [data-database-name="${dbName}"]`;
};
Expand Down Expand Up @@ -357,6 +358,13 @@ export const sidebarConnectionButton = (connectionName: string): string => {
return `${sidebarConnection(connectionName)} > div > button`;
};

export const sidebarConnectionActionButton = (
connectionName: string,
selector: string
): string => {
return `${sidebarConnection(connectionName)} ${selector}`;
};

export const sidebarConnectionMenuButton = (connectionName: string): string => {
return `${sidebarConnection(connectionName)} button[title="Show actions"]`;
};
Expand Down Expand Up @@ -473,6 +481,7 @@ export const ShellSection = '[data-testid="shell-section"]';
export const ShellContent = '[data-testid="shell-content"]';
export const ShellExpandButton = '[data-testid="shell-expand-button"]';
export const ShellInputEditor = '[data-testid="shell-input"] [data-codemirror]';
export const ShellInput = '[data-testid="shell-input"]';
export const ShellOutput = '[data-testid="shell-output"]';

// Instance screen
Expand Down
4 changes: 2 additions & 2 deletions packages/compass-e2e-tests/tests/auto-connect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('Automatically connecting from the command line', function () {
location.reload();
});
await browser.waitForConnectionResult('success');
await browser.disconnect();
await browser.disconnectAll();
await browser.execute(() => {
location.reload();
});
Expand Down Expand Up @@ -276,7 +276,7 @@ describe('Automatically connecting from the command line', function () {
try {
const browser = compass.browser;
await browser.waitForConnectionResult('success');
await browser.disconnect();
await browser.disconnectAll();

// this is not the ideal check because by default the recent connections
// list doesn't exist either
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-e2e-tests/tests/collection-export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ describe('Collection export', function () {
const exportAbortButton = await browser.$(Selectors.ExportToastAbort);
await exportAbortButton.waitForDisplayed();

await browser.disconnect();
await browser.disconnectAll();
await browser
.$(Selectors.SidebarTitle)
.waitForDisplayed({ reverse: true });
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-e2e-tests/tests/collection-import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ describe('Collection import', function () {
// Wait for the in progress toast to appear.
await browser.$(Selectors.ImportToastAbort).waitForDisplayed();

await browser.disconnect();
await browser.disconnectAll();
await browser
.$(Selectors.SidebarTitle)
.waitForDisplayed({ reverse: true });
Expand Down
3 changes: 1 addition & 2 deletions packages/compass-e2e-tests/tests/collection-rename.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { CompassBrowser } from '../helpers/compass-browser';
import { createBlankCollection, dropDatabase } from '../helpers/insert-data';
import * as Selectors from '../helpers/selectors';

import { setFeature } from '../helpers/commands';
const initialName = 'numbers';
const newName = 'renamed';

Expand Down Expand Up @@ -114,7 +113,7 @@ describe('Collection Rename Modal', () => {
compass = await init(this.test?.fullTitle());
browser = compass.browser;

await setFeature(browser, 'enableRenameCollectionModal', true);
await browser.setFeature('enableRenameCollectionModal', true);
});

beforeEach(async function () {
Expand Down
Loading

0 comments on commit d4ac9df

Please sign in to comment.