Skip to content

Commit

Permalink
chore(e2e): remove TEST_MULTIPLE_CONNECTIONS flag from e2e tests (#6393)
Browse files Browse the repository at this point in the history
  • Loading branch information
gribnoysup authored Oct 23, 2024
1 parent 8884e7f commit 6b68561
Show file tree
Hide file tree
Showing 30 changed files with 417 additions and 1,073 deletions.
20 changes: 4 additions & 16 deletions packages/compass-e2e-tests/helpers/commands/close-shell.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
import { TEST_MULTIPLE_CONNECTIONS } from '../compass';
import type { CompassBrowser } from '../compass-browser';
import retryWithBackoff from '../retry-with-backoff';
import * as Selectors from '../selectors';

export async function closeShell(
browser: CompassBrowser,
connectionName: string
): Promise<void> {
if (TEST_MULTIPLE_CONNECTIONS) {
await browser.closeWorkspaceTab({
connectionName,
type: 'Shell',
});
} else {
await retryWithBackoff(async function () {
const shellContentElement = await browser.$(Selectors.ShellContent);
if (await shellContentElement.isDisplayed()) {
await browser.clickVisible(Selectors.ShellExpandButton);
}
});
}
await browser.closeWorkspaceTab({
connectionName,
type: 'Shell',
});
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TEST_MULTIPLE_CONNECTIONS } from '../compass';
import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';
import type { WorkspaceTabSelectorOptions } from '../selectors';
Expand Down Expand Up @@ -119,16 +118,13 @@ async function waitUntilActiveCollectionTab(
) {
const options: WorkspaceTabSelectorOptions = {
type: 'Collection',
connectionName,
namespace: `${dbName}.${collectionName}`,
active: true,
};
// Only add the connectionName for multiple connections because for some
// reason this sometimes flakes in single connections even though the tab is
// definitely there in the screenshot.
if (TEST_MULTIPLE_CONNECTIONS) {
options.connectionName = connectionName;
}

await browser.$(Selectors.workspaceTab(options)).waitForDisplayed();

if (tabName) {
await waitUntilActiveCollectionSubTab(browser, tabName);
}
Expand Down
73 changes: 27 additions & 46 deletions packages/compass-e2e-tests/helpers/commands/connect-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,24 @@ import { expect } from 'chai';
import type { CompassBrowser } from '../compass-browser';
import * as Selectors from '../selectors';
import type { ConnectFormState } from '../connect-form-state';
import { TEST_MULTIPLE_CONNECTIONS } from '../compass';
import Debug from 'debug';
import { DEFAULT_CONNECTIONS } from '../test-runner-context';
import { getConnectionTitle } from '@mongodb-js/connection-info';
const debug = Debug('compass-e2e-tests');

export async function resetConnectForm(browser: CompassBrowser): Promise<void> {
const Sidebar = TEST_MULTIPLE_CONNECTIONS
? Selectors.Multiple
: Selectors.Single;
const Sidebar = Selectors.Multiple;

if (TEST_MULTIPLE_CONNECTIONS) {
if (await browser.$(Selectors.ConnectionModal).isDisplayed()) {
await browser.clickVisible(Selectors.ConnectionModalCloseButton);
await browser
.$(Selectors.ConnectionModal)
.waitForDisplayed({ reverse: true });
}
if (await browser.$(Selectors.ConnectionModal).isDisplayed()) {
await browser.clickVisible(Selectors.ConnectionModalCloseButton);
await browser
.$(Selectors.ConnectionModal)
.waitForDisplayed({ reverse: true });
}

await browser.clickVisible(Sidebar.SidebarNewConnectionButton);

const connectionTitleSelector = TEST_MULTIPLE_CONNECTIONS
? Selectors.ConnectionModalTitle
: Selectors.ConnectionTitle;
const connectionTitleSelector = Selectors.ConnectionModalTitle;

const connectionTitle = await browser.$(connectionTitleSelector);
await connectionTitle.waitUntil(async () => {
Expand Down Expand Up @@ -57,29 +50,20 @@ export async function getConnectFormState(
// General
const initialTab = await browser.navigateToConnectTab('General');

const defaultPromises: Record<string, Promise<any>> = {
const defaultState = await promiseMap({
scheme: getCheckedRadioValue(browser, Selectors.ConnectionFormSchemeRadios),
hosts: getMultipleValues(browser, Selectors.ConnectionFormHostInputs),
directConnection: getCheckboxValue(
browser,
Selectors.ConnectionFormDirectConnectionCheckbox
),
};
if (TEST_MULTIPLE_CONNECTIONS) {
defaultPromises.connectionName = getValue(
browser,
Selectors.ConnectionFormConnectionName
);
defaultPromises.connectionColor = getValue(
browser,
Selectors.ConnectionFormConnectionColor
);
defaultPromises.connectionFavorite = getCheckboxValue(
connectionName: getValue(browser, Selectors.ConnectionFormConnectionName),
connectionColor: getValue(browser, Selectors.ConnectionFormConnectionColor),
connectionFavorite: getCheckboxValue(
browser,
Selectors.ConnectionFormFavoriteCheckbox
);
}
const defaultState = await promiseMap(defaultPromises);
),
});

// Authentication
await browser.navigateToConnectTab('Authentication');
Expand Down Expand Up @@ -506,25 +490,22 @@ export async function setConnectFormState(
await browser.clickParent(Selectors.ConnectionFormDirectConnectionCheckbox);
}

if (TEST_MULTIPLE_CONNECTIONS) {
// Name, Color, Favorite
if (state.connectionName) {
await browser.setValueVisible(
Selectors.ConnectionFormConnectionName,
state.connectionName
);
}
if (state.connectionName) {
await browser.setValueVisible(
Selectors.ConnectionFormConnectionName,
state.connectionName
);
}

if (state.connectionColor) {
await browser.selectOption(
Selectors.ConnectionFormConnectionColor,
colorValueToName(state.connectionColor)
);
}
if (state.connectionColor) {
await browser.selectOption(
Selectors.ConnectionFormConnectionColor,
colorValueToName(state.connectionColor)
);
}

if (state.connectionFavorite) {
await browser.clickParent(Selectors.ConnectionFormFavoriteCheckbox);
}
if (state.connectionFavorite) {
await browser.clickParent(Selectors.ConnectionFormFavoriteCheckbox);
}

// Authentication
Expand Down
145 changes: 46 additions & 99 deletions packages/compass-e2e-tests/helpers/commands/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,14 @@ import {
DEFAULT_CONNECTION_NAME_1,
DEFAULT_CONNECTION_NAME_2,
DEFAULT_CONNECTION_STRING_1,
TEST_MULTIPLE_CONNECTIONS,
connectionNameFromString,
} from '../compass';
import type { CompassBrowser } from '../compass-browser';
import type { ConnectFormState } from '../connect-form-state';
import * as Selectors from '../selectors';
import Debug from 'debug';
const debug = Debug('compass-e2e-tests');

export async function waitForConnectionScreen(
browser: CompassBrowser
): Promise<void> {
// there isn't a separate connection screen in multiple connections, just a modal you can access at any time
if (TEST_MULTIPLE_CONNECTIONS) {
return;
}

const selector = Selectors.ConnectSection;
const connectScreenElement = await browser.$(selector);
await connectScreenElement.waitForDisplayed();
}
const debug = Debug('compass-e2e-tests');

export async function getConnectFormConnectionString(
browser: CompassBrowser,
Expand Down Expand Up @@ -57,32 +44,29 @@ export async function connectWithConnectionString(
// connection string. Most test files should just be using
// browser.connectToDefaults()

if (TEST_MULTIPLE_CONNECTIONS) {
// if the modal is still animating away when we're connecting again, things
// are going to get confused
await browser
.$(Selectors.ConnectionModal)
.waitForDisplayed({ reverse: true });

// 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);
if (await browser.removeConnection(connectionName)) {
debug('Removing existing connection so we do not create a duplicate', {
connectionName,
});
}
// if the modal is still animating away when we're connecting again, things
// are going to get confused
await browser
.$(Selectors.ConnectionModal)
.waitForDisplayed({ reverse: true });

await browser.clickVisible(Selectors.Multiple.SidebarNewConnectionButton);
await browser.$(Selectors.ConnectionModal).waitForDisplayed();
// 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);
if (await browser.removeConnection(connectionName)) {
debug('Removing existing connection so we do not create a duplicate', {
connectionName,
});
}

await browser.clickVisible(Selectors.Multiple.SidebarNewConnectionButton);
await browser.$(Selectors.ConnectionModal).waitForDisplayed();

await browser.setValueVisible(
Selectors.ConnectionFormStringInput,
connectionString
);

const connectionName = connectionNameFromString(connectionString);
await browser.doConnect(connectionName, options);
}

Expand Down Expand Up @@ -133,75 +117,50 @@ export async function waitForConnectionResult(
): Promise<string | undefined> {
const waitOptions = typeof timeout !== 'undefined' ? { timeout } : undefined;

if (TEST_MULTIPLE_CONNECTIONS) {
if (await browser.$(Selectors.SidebarFilterInput).isDisplayed()) {
// Clear the filter to make sure every connection shows
await browser.clickVisible(Selectors.SidebarFilterInput);
await browser.setValueVisible(Selectors.SidebarFilterInput, '');
}
if (await browser.$(Selectors.SidebarFilterInput).isDisplayed()) {
// Clear the filter to make sure every connection shows
await browser.clickVisible(Selectors.SidebarFilterInput);
await browser.setValueVisible(Selectors.SidebarFilterInput, '');
}

if (connectionStatus === 'either') {
// For the very rare cases where we don't care whether it fails or succeeds.
// Usually because the exact result is a race condition.
if (TEST_MULTIPLE_CONNECTIONS) {
const successSelector = Selectors.Multiple.connectionItemByName(
connectionName,
{
connected: true,
}
);
const failureSelector = Selectors.ConnectionToastErrorText;
await browser
.$(`${successSelector},${failureSelector}`)
.waitForDisplayed(waitOptions);
} else {
// TODO(COMPASS-7600): this doesn't support compass-web yet, but also
// isn't encountered yet
await browser
.$(`${Selectors.MyQueriesList},${Selectors.ConnectionFormErrorMessage}`)
.waitForDisplayed();
}
const successSelector = Selectors.Multiple.connectionItemByName(
connectionName,
{
connected: true,
}
);
const failureSelector = Selectors.ConnectionToastErrorText;
await browser
.$(`${successSelector},${failureSelector}`)
.waitForDisplayed(waitOptions);
} else if (connectionStatus === 'success') {
// Wait for the first meaningful thing on the screen after being connected
// and assume that's a good enough indicator that we are connected to the
// server
if (TEST_MULTIPLE_CONNECTIONS) {
await browser
.$(
Selectors.Multiple.connectionItemByName(connectionName, {
connected: true,
})
)
.waitForDisplayed();
} else {
// In the single connection world we land on the My Queries page
await browser.$(Selectors.MyQueriesList).waitForDisplayed();
}
await browser
.$(
Selectors.Multiple.connectionItemByName(connectionName, {
connected: true,
})
)
.waitForDisplayed();
} else if (connectionStatus === 'failure') {
if (TEST_MULTIPLE_CONNECTIONS) {
await browser
.$(Selectors.ConnectionToastErrorText)
.waitForDisplayed(waitOptions);
return await browser.$(Selectors.LGToastTitle).getText();
} else {
// TODO(COMPASS-7600): this doesn't support compass-web yet, but also
// isn't encountered yet
const element = await browser.$(Selectors.ConnectionFormErrorMessage);
await element.waitForDisplayed(waitOptions);
return await element.getText();
}
await browser
.$(Selectors.ConnectionToastErrorText)
.waitForDisplayed(waitOptions);
return await browser.$(Selectors.LGToastTitle).getText();
} else {
const exhaustiveCheck: never = connectionStatus;
throw new Error(`Unhandled connectionStatus case: ${exhaustiveCheck}`);
}

if (TEST_MULTIPLE_CONNECTIONS) {
// make sure the placeholders for databases & collections that are loading are all gone
await browser
.$(Selectors.DatabaseCollectionPlaceholder)
.waitForDisplayed({ reverse: true });
}
// make sure the placeholders for databases & collections that are loading are all gone
await browser
.$(Selectors.DatabaseCollectionPlaceholder)
.waitForDisplayed({ reverse: true });
}

export async function connectByName(
Expand All @@ -210,25 +169,13 @@ export async function connectByName(
options: ConnectionResultOptions = {}
) {
await browser.clickVisible(Selectors.sidebarConnectionButton(connectionName));

if (!TEST_MULTIPLE_CONNECTIONS) {
// for single connections it only fills the connection form and we still
// have to click connect. For multiple connections clicking the connection
// connects
await browser.pause(1000);
await browser.clickVisible(Selectors.ConnectButton);
}

await browser.waitForConnectionResult(connectionName, options);
}

export async function connectToDefaults(browser: CompassBrowser) {
// See setupDefaultConnections() for the details behind the thinking here.
await browser.connectByName(DEFAULT_CONNECTION_NAME_1);

if (TEST_MULTIPLE_CONNECTIONS) {
await browser.connectByName(DEFAULT_CONNECTION_NAME_2);
}
await browser.connectByName(DEFAULT_CONNECTION_NAME_2);

// We assume that we connected successfully, so just close the success toasts
// early to make sure they aren't in the way of tests. Tests that care about
Expand Down
Loading

0 comments on commit 6b68561

Please sign in to comment.