Skip to content

chore: add e2e tests for relationship management COMPASS-9479 #7154

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

Merged
merged 13 commits into from
Aug 4, 2025
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
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/compass-components/src/components/leafygreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ import {
ComboboxGroup,
} from '@leafygreen-ui/combobox';

export { getLgIds as getDrawerIds } from './drawer';

// 2. Wrap and make any changes/workaround to leafygreen components.
const Icon = ({
size,
Expand Down
8 changes: 4 additions & 4 deletions packages/compass-e2e-tests/helpers/commands/connect-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,10 @@ export async function setConnectFormState(
}

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

if (state.connectionFavorite) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { ChainablePromiseElement } from 'webdriverio';
import type { CompassBrowser } from '../compass-browser';

export async function getInputByLabel(
browser: CompassBrowser,
label: ChainablePromiseElement
): Promise<ChainablePromiseElement> {
await label.waitForDisplayed();
const inputId = await label.getAttribute('for');
return browser.$(`[id="${inputId}"]`);
}
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 @@ -65,3 +65,4 @@ export * from './switch-pipeline-mode';
export * from './read-first-document-content';
export * from './read-stage-operators';
export * from './click-confirmation-action';
export * from './get-input-by-label';
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export async function saveFavorite(
Selectors.ConnectionFormConnectionName,
favoriteName
);
await browser.selectOption(Selectors.ConnectionFormConnectionColor, color);
await browser.selectOption({
selectSelector: Selectors.ConnectionFormConnectionColor,
optionText: color,
});

await browser.clickVisible(Selectors.ConnectionModalSaveButton);
await browser.$(Selectors.ConnectionModal).waitForExist({ reverse: true });
Expand Down
29 changes: 21 additions & 8 deletions packages/compass-e2e-tests/helpers/commands/select-option.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import type { ChainablePromiseElement } from 'webdriverio';
import type { CompassBrowser } from '../compass-browser';

type SelectOptionOptions = {
selectSelector: string | ChainablePromiseElement;
} & (
| {
optionText: string;
optionSelector?: never;
}
| {
optionSelector: string;
optionText?: never;
}
);

export async function selectOption(
browser: CompassBrowser,
// selector must match an element (like a div) that contains the leafygreen
// select we want to operate on
selector: string,
optionText: string
{ selectSelector, optionText, optionSelector }: SelectOptionOptions
): Promise<void> {
// click the field's button
const selectButton = browser.$(`${selector}`);
const selectButton = browser.$(selectSelector);
await selectButton.waitForDisplayed();
await selectButton.click();

Expand All @@ -26,9 +37,11 @@ export async function selectOption(
await selectList.waitForDisplayed();

// click the option
const optionSpan = selectList.$(`span=${optionText}`);
await optionSpan.scrollIntoView();
await optionSpan.click();
const option =
optionText !== undefined
? selectList.$(`span=${optionText}`)
: selectList.$(optionSelector);
await browser.clickVisible(option);

// wait for the list to go away again
await selectList.waitForDisplayed({ reverse: true });
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-e2e-tests/helpers/compass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ function redact(value: string): string {
continue;
}

const quoted = `'${process.env[field] as string}'`;
const quoted = `'${process.env[field]}'`;
// /regex/s would be ideal, but we'd have to escape the value to not be
// interpreted as a regex.
while (value.indexOf(quoted) !== -1) {
Expand Down
34 changes: 33 additions & 1 deletion packages/compass-e2e-tests/helpers/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getDrawerIds } from '@mongodb-js/compass-components';

export type WorkspaceTabSelectorOptions = {
id?: string;
connectionName?: string;
Expand Down Expand Up @@ -1442,9 +1444,13 @@ export const CreateDataModelCollectionCheckbox = (
): string =>
`${CreateDataModelModal} [data-testid="new-diagram-collection-checkbox-${collectionName}"]`;
export const DataModelEditor = '[data-testid="diagram-editor-container"]';
export const DataModelZoomOutButton = `${DataModelEditor} [aria-label="Minus Icon"]`;
export const DataModelZoomInButton = `${DataModelEditor} [aria-label="Plus Icon"]`;
export const DataModelPreview = `${DataModelEditor} [data-testid="model-preview"]`;
export const DataModelPreviewCollection = (collectionId: string) =>
`${DataModelPreview} [data-nodeid="${collectionId}"]`;
`${DataModelPreview} [aria-roleDescription="node"][data-id="${collectionId}"]`;
export const DataModelPreviewRelationship = (relationshipId: string) =>
`${DataModelPreview} [aria-roleDescription="edge"][data-id="${relationshipId}"]`;
export const DataModelApplyEditor = `${DataModelEditor} [data-testid="apply-editor"]`;
export const DataModelEditorApplyButton = `${DataModelApplyEditor} [data-testid="apply-button"]`;
export const DataModelUndoButton = 'button[aria-label="Undo"]';
Expand All @@ -1466,3 +1472,29 @@ export const DataModelsListItem = (diagramName?: string) => {
export const DataModelsListItemActions = (diagramName: string) =>
`${DataModelsListItem(diagramName)} [aria-label="Show actions"]`;
export const DataModelsListItemDeleteButton = `[data-action="delete"]`;
export const DataModelAddRelationshipBtn = 'aria/Add relationship';
export const DataModelNameInput = '//label[text()="Name"]';
export const DataModelRelationshipLocalCollectionSelect =
'//label[text()="Local collection"]';
export const DataModelRelationshipLocalFieldSelect =
'//label[text()="Local field"]';
export const DataModelRelationshipLocalCardinalitySelect =
'//label[text()="Local cardinality"]';
export const DataModelRelationshipForeignCollectionSelect =
'//label[text()="Foreign collection"]';
export const DataModelRelationshipForeignFieldSelect =
'//label[text()="Foreign field"]';
export const DataModelRelationshipForeignCardinalitySelect =
'//label[text()="Foreign cardinality"]';
export const DataModelRelationshipCardinalityOption = (value: string) =>
`[role="option"][value="${value}"]`;
export const DataModelCollectionRelationshipItem = (relationshipId: string) =>
`li[data-relationship-id="${relationshipId}"]`;
export const DataModelCollectionRelationshipItemEdit = `[aria-label="Edit relationship"]`;
export const DataModelCollectionRelationshipItemDelete = `[aria-label="Delete relationship"]`;

// Side drawer
export const SideDrawer = `[data-testid="${getDrawerIds().root}"]`;
export const SideDrawerCloseButton = `[data-testid="${
getDrawerIds().closeButton
}"]`;
1 change: 1 addition & 0 deletions packages/compass-e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"devDependencies": {
"@electron/rebuild": "^4.0.1",
"@mongodb-js/compass-components": "^1.46.0",
"@mongodb-js/compass-test-server": "^0.3.16",
"@mongodb-js/connection-info": "^0.16.3",
"@mongodb-js/eslint-config-compass": "^1.4.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1596,10 +1596,12 @@ describe('Collection aggregations tab', function () {
'name'
);

await browser.selectOption(
`${Selectors.AggregationWizardSortFormDirectionSelect(0)} button`,
'Ascending'
);
await browser.selectOption({
selectSelector: `${Selectors.AggregationWizardSortFormDirectionSelect(
0
)} button`,
optionText: 'Ascending',
});

await browser.clickVisible(Selectors.AggregationWizardApplyButton);

Expand Down
Loading
Loading