Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(e2e): remove TEST_MULTIPLE_CONNECTIONS flag from e2e tests #6393

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 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);
}
});
}
}
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
35 changes: 8 additions & 27 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 });
}
}

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,8 +490,6 @@ export async function setConnectFormState(
await browser.clickParent(Selectors.ConnectionFormDirectConnectionCheckbox);
}

if (TEST_MULTIPLE_CONNECTIONS) {
// Name, Color, Favorite
if (state.connectionName) {
await browser.setValueVisible(
Selectors.ConnectionFormConnectionName,
Expand All @@ -525,7 +507,6 @@ export async function setConnectFormState(
if (state.connectionFavorite) {
await browser.clickParent(Selectors.ConnectionFormFavoriteCheckbox);
}
}

// Authentication
if (
Expand Down
55 changes: 1 addition & 54 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,7 +44,6 @@ 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
Expand All @@ -75,14 +61,12 @@ export async function connectWithConnectionString(

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,18 +117,15 @@ 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 (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,
{
Expand All @@ -155,80 +136,46 @@ export async function waitForConnectionResult(
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();
}
} 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();
}
} 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();
}
} 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 });
}
}

export async function connectByName(
browser: CompassBrowser,
connectionName: string,
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);
}

// 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
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 All @@ -8,7 +7,6 @@ export async function navigateToConnectionTab(
connectionName: string,
tabType: 'Performance' | 'Databases'
): Promise<void> {
if (TEST_MULTIPLE_CONNECTIONS) {
if (tabType === 'Databases') {
await browser.clickVisible(Selectors.sidebarConnection(connectionName));
} else {
Expand All @@ -19,25 +17,17 @@ export async function navigateToConnectionTab(
}

await waitUntilActiveConnectionTab(browser, connectionName, tabType);
} else {
const itemSelector = Selectors.sidebarInstanceNavigationItem(tabType);
await browser.clickVisible(itemSelector);
await waitUntilActiveConnectionTab(browser, connectionName, tabType);
}
}

export async function waitUntilActiveConnectionTab(
browser: CompassBrowser,
connectionName: string,
tabType: 'Performance' | 'Databases'
) {
const options: WorkspaceTabSelectorOptions = { type: tabType, 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;
}
const options: WorkspaceTabSelectorOptions = {
type: tabType,
connectionName,
active: true,
};
await browser.$(Selectors.workspaceTab(options)).waitForDisplayed();
}
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 All @@ -19,16 +18,10 @@ export async function waitUntilActiveDatabaseTab(
dbName: string
) {
const options: WorkspaceTabSelectorOptions = {
connectionName,
namespace: dbName,
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();
}
Loading
Loading