Skip to content

Commit aab5ef3

Browse files
authored
chore: add e2e tests for relationship management COMPASS-9479 (#7154)
1 parent 945e0bb commit aab5ef3

File tree

13 files changed

+289
-58
lines changed

13 files changed

+289
-58
lines changed

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-components/src/components/leafygreen.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ import {
9292
ComboboxGroup,
9393
} from '@leafygreen-ui/combobox';
9494

95+
export { getLgIds as getDrawerIds } from './drawer';
96+
9597
// 2. Wrap and make any changes/workaround to leafygreen components.
9698
const Icon = ({
9799
size,

packages/compass-e2e-tests/helpers/commands/connect-form.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,10 @@ export async function setConnectFormState(
498498
}
499499

500500
if (state.connectionColor) {
501-
await browser.selectOption(
502-
Selectors.ConnectionFormConnectionColor,
503-
colorValueToName(state.connectionColor)
504-
);
501+
await browser.selectOption({
502+
selectSelector: Selectors.ConnectionFormConnectionColor,
503+
optionText: colorValueToName(state.connectionColor),
504+
});
505505
}
506506

507507
if (state.connectionFavorite) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { ChainablePromiseElement } from 'webdriverio';
2+
import type { CompassBrowser } from '../compass-browser';
3+
4+
export async function getInputByLabel(
5+
browser: CompassBrowser,
6+
label: ChainablePromiseElement
7+
): Promise<ChainablePromiseElement> {
8+
await label.waitForDisplayed();
9+
const inputId = await label.getAttribute('for');
10+
return browser.$(`[id="${inputId}"]`);
11+
}

packages/compass-e2e-tests/helpers/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ export * from './switch-pipeline-mode';
6565
export * from './read-first-document-content';
6666
export * from './read-stage-operators';
6767
export * from './click-confirmation-action';
68+
export * from './get-input-by-label';

packages/compass-e2e-tests/helpers/commands/save-favorite.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export async function saveFavorite(
1414
Selectors.ConnectionFormConnectionName,
1515
favoriteName
1616
);
17-
await browser.selectOption(Selectors.ConnectionFormConnectionColor, color);
17+
await browser.selectOption({
18+
selectSelector: Selectors.ConnectionFormConnectionColor,
19+
optionText: color,
20+
});
1821

1922
await browser.clickVisible(Selectors.ConnectionModalSaveButton);
2023
await browser.$(Selectors.ConnectionModal).waitForExist({ reverse: true });

packages/compass-e2e-tests/helpers/commands/select-option.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
import type { ChainablePromiseElement } from 'webdriverio';
12
import type { CompassBrowser } from '../compass-browser';
23

4+
type SelectOptionOptions = {
5+
selectSelector: string | ChainablePromiseElement;
6+
} & (
7+
| {
8+
optionText: string;
9+
optionSelector?: never;
10+
}
11+
| {
12+
optionSelector: string;
13+
optionText?: never;
14+
}
15+
);
16+
317
export async function selectOption(
418
browser: CompassBrowser,
5-
// selector must match an element (like a div) that contains the leafygreen
6-
// select we want to operate on
7-
selector: string,
8-
optionText: string
19+
{ selectSelector, optionText, optionSelector }: SelectOptionOptions
920
): Promise<void> {
1021
// click the field's button
11-
const selectButton = browser.$(`${selector}`);
22+
const selectButton = browser.$(selectSelector);
1223
await selectButton.waitForDisplayed();
1324
await selectButton.click();
1425

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

2839
// click the option
29-
const optionSpan = selectList.$(`span=${optionText}`);
30-
await optionSpan.scrollIntoView();
31-
await optionSpan.click();
40+
const option =
41+
optionText !== undefined
42+
? selectList.$(`span=${optionText}`)
43+
: selectList.$(optionSelector);
44+
await browser.clickVisible(option);
3245

3346
// wait for the list to go away again
3447
await selectList.waitForDisplayed({ reverse: true });

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ function redact(value: string): string {
12231223
continue;
12241224
}
12251225

1226-
const quoted = `'${process.env[field] as string}'`;
1226+
const quoted = `'${process.env[field]}'`;
12271227
// /regex/s would be ideal, but we'd have to escape the value to not be
12281228
// interpreted as a regex.
12291229
while (value.indexOf(quoted) !== -1) {

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getDrawerIds } from '@mongodb-js/compass-components';
2+
13
export type WorkspaceTabSelectorOptions = {
24
id?: string;
35
connectionName?: string;
@@ -1444,9 +1446,13 @@ export const CreateDataModelCollectionCheckbox = (
14441446
): string =>
14451447
`${CreateDataModelModal} [data-testid="new-diagram-collection-checkbox-${collectionName}"]`;
14461448
export const DataModelEditor = '[data-testid="diagram-editor-container"]';
1449+
export const DataModelZoomOutButton = `${DataModelEditor} [aria-label="Minus Icon"]`;
1450+
export const DataModelZoomInButton = `${DataModelEditor} [aria-label="Plus Icon"]`;
14471451
export const DataModelPreview = `${DataModelEditor} [data-testid="model-preview"]`;
14481452
export const DataModelPreviewCollection = (collectionId: string) =>
1449-
`${DataModelPreview} [data-nodeid="${collectionId}"]`;
1453+
`${DataModelPreview} [aria-roleDescription="node"][data-id="${collectionId}"]`;
1454+
export const DataModelPreviewRelationship = (relationshipId: string) =>
1455+
`${DataModelPreview} [aria-roleDescription="edge"][data-id="${relationshipId}"]`;
14501456
export const DataModelApplyEditor = `${DataModelEditor} [data-testid="apply-editor"]`;
14511457
export const DataModelEditorApplyButton = `${DataModelApplyEditor} [data-testid="apply-button"]`;
14521458
export const DataModelUndoButton = 'button[aria-label="Undo"]';
@@ -1468,3 +1474,29 @@ export const DataModelsListItem = (diagramName?: string) => {
14681474
export const DataModelsListItemActions = (diagramName: string) =>
14691475
`${DataModelsListItem(diagramName)} [aria-label="Show actions"]`;
14701476
export const DataModelsListItemDeleteButton = `[data-action="delete"]`;
1477+
export const DataModelAddRelationshipBtn = 'aria/Add relationship';
1478+
export const DataModelNameInput = '//label[text()="Name"]';
1479+
export const DataModelRelationshipLocalCollectionSelect =
1480+
'//label[text()="Local collection"]';
1481+
export const DataModelRelationshipLocalFieldSelect =
1482+
'//label[text()="Local field"]';
1483+
export const DataModelRelationshipLocalCardinalitySelect =
1484+
'//label[text()="Local cardinality"]';
1485+
export const DataModelRelationshipForeignCollectionSelect =
1486+
'//label[text()="Foreign collection"]';
1487+
export const DataModelRelationshipForeignFieldSelect =
1488+
'//label[text()="Foreign field"]';
1489+
export const DataModelRelationshipForeignCardinalitySelect =
1490+
'//label[text()="Foreign cardinality"]';
1491+
export const DataModelRelationshipCardinalityOption = (value: string) =>
1492+
`[role="option"][value="${value}"]`;
1493+
export const DataModelCollectionRelationshipItem = (relationshipId: string) =>
1494+
`li[data-relationship-id="${relationshipId}"]`;
1495+
export const DataModelCollectionRelationshipItemEdit = `[aria-label="Edit relationship"]`;
1496+
export const DataModelCollectionRelationshipItemDelete = `[aria-label="Delete relationship"]`;
1497+
1498+
// Side drawer
1499+
export const SideDrawer = `[data-testid="${getDrawerIds().root}"]`;
1500+
export const SideDrawerCloseButton = `[data-testid="${
1501+
getDrawerIds().closeButton
1502+
}"]`;

packages/compass-e2e-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"devDependencies": {
3434
"@electron/rebuild": "^4.0.1",
35+
"@mongodb-js/compass-components": "^1.46.0",
3536
"@mongodb-js/compass-test-server": "^0.3.16",
3637
"@mongodb-js/connection-info": "^0.17.0",
3738
"@mongodb-js/eslint-config-compass": "^1.4.5",

0 commit comments

Comments
 (0)