Skip to content

Commit 8d6417a

Browse files
committed
add e2e test
1 parent 7e1fffb commit 8d6417a

File tree

6 files changed

+97
-23
lines changed

6 files changed

+97
-23
lines changed

packages/compass-components/src/components/modals/error-details-modal.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ function ErrorDetailsModal({
3636
<Modal setOpen={onClose} {...modalProps}>
3737
<ModalHeader title={title} subtitle={subtitle} />
3838
<ModalBody>
39-
<Code language="json">{prettyDetails}</Code>
39+
<Code language="json" data-testid="error-details-json">
40+
{prettyDetails}
41+
</Code>
4042
</ModalBody>
4143
<ModalFooter>
4244
<Button
43-
data-testid="close-button"
45+
data-testid={`error-details-${closeAction}-button`}
4446
onClick={() => {
4547
console.log('onClick');
4648
onClose();

packages/compass-crud/src/components/insert-document-dialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ const InsertDocumentDialog: React.FC<InsertDocumentDialogProps> = ({
344344
size="xsmall"
345345
className={errorDetailsBtnStyles}
346346
onClick={showErrorDetails}
347+
data-testid="insert-document-error-details-button"
347348
>
348349
VIEW ERROR DETAILS
349350
</Button>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { CompassBrowser } from '../compass-browser';
2+
import * as Selectors from '../selectors';
3+
import { expect } from 'chai';
4+
5+
export async function tryToInsertDocument(
6+
browser: CompassBrowser,
7+
document?: string
8+
) {
9+
// browse to the "Insert to Collection" modal
10+
await browser.clickVisible(Selectors.AddDataButton);
11+
const insertDocumentOption = browser.$(Selectors.InsertDocumentOption);
12+
await insertDocumentOption.waitForDisplayed();
13+
await browser.clickVisible(Selectors.InsertDocumentOption);
14+
15+
// wait for the modal to appear
16+
const insertDialog = browser.$(Selectors.InsertDialog);
17+
await insertDialog.waitForDisplayed();
18+
19+
if (document) {
20+
// set the text in the editor
21+
await browser.setCodemirrorEditorValue(
22+
Selectors.InsertJSONEditor,
23+
document
24+
);
25+
}
26+
27+
// confirm
28+
const insertConfirm = browser.$(Selectors.InsertConfirm);
29+
// this selector is very brittle, so just make sure it works
30+
expect(await insertConfirm.isDisplayed()).to.be.true;
31+
expect(await insertConfirm.getText()).to.equal('Insert');
32+
await insertConfirm.waitForEnabled();
33+
await browser.clickVisible(Selectors.InsertConfirm);
34+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,12 +615,19 @@ export const JSONEditDocumentButton = `${JSONDocumentCard} [data-testid="editor-
615615
export const ShowMoreFieldsButton = '[data-testid="show-more-fields-button"]';
616616
export const OpenBulkUpdateButton = '[data-testid="crud-update"]';
617617
export const OpenBulkDeleteButton = '[data-testid="crud-bulk-delete"]';
618+
export const ErrorDetailsJson = '[data-testid="error-details-json"]';
619+
export const ErrorDetailsBackButton =
620+
'[data-testid="error-details-back-button"]';
621+
export const ErrorDetailsCloseButton =
622+
'[data-testid="error-details-close-button"]';
618623

619624
// Insert Document modal
620625

621626
export const InsertDialog = '[data-testid="insert-document-modal"]';
622627
export const InsertDialogErrorMessage =
623628
'[data-testid="insert-document-banner"][data-variant="danger"]';
629+
export const InsertDialogErrorDetailsBtn =
630+
'button[data-testid="insert-document-error-details-button"]';
624631
export const InsertJSONEditor = '[data-testid="insert-document-json-editor"]';
625632
export const InsertConfirm =
626633
'[data-testid="insert-document-modal"] [data-testid="submit-button"]';

packages/compass-e2e-tests/tests/collection-documents-tab.test.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import {
1717
createNestedDocumentsCollection,
1818
createNumbersCollection,
1919
} from '../helpers/insert-data';
20-
import { context } from '../helpers/test-runner-context';
20+
import { context as testRunnerContext } from '../helpers/test-runner-context';
2121
import type { ChainablePromiseElement } from 'webdriverio';
22+
import { tryToInsertDocument } from '../helpers/commands/try-to-insert-document';
2223

2324
const { expect } = chai;
2425

@@ -553,7 +554,7 @@ FindIterable<Document> result = collection.find(filter);`);
553554
});
554555

555556
it('can copy a document from the contextual toolbar', async function () {
556-
if (context.disableClipboardUsage) {
557+
if (testRunnerContext.disableClipboardUsage) {
557558
this.skip();
558559
}
559560

@@ -685,4 +686,48 @@ FindIterable<Document> result = collection.find(filter);`);
685686
expect(numExpandedHadronElementsPostSwitch).to.equal(14);
686687
});
687688
});
689+
690+
context('with existing validation rule', function () {
691+
const REQUIRE_PHONE_VALIDATOR =
692+
'{ $jsonSchema: { bsonType: "object", required: [ "phone" ] } }';
693+
beforeEach(async function () {
694+
await browser.navigateToCollectionTab(
695+
DEFAULT_CONNECTION_NAME_1,
696+
'test',
697+
'numbers',
698+
'Validation'
699+
);
700+
await browser.clickVisible(Selectors.AddRuleButton);
701+
const element = browser.$(Selectors.ValidationEditor);
702+
await element.waitForDisplayed();
703+
await browser.setValidation(REQUIRE_PHONE_VALIDATOR);
704+
});
705+
706+
it('Shows error info when inserting', async function () {
707+
await browser.navigateToCollectionTab(
708+
DEFAULT_CONNECTION_NAME_1,
709+
'test',
710+
'numbers',
711+
'Documents'
712+
);
713+
await tryToInsertDocument(browser, '{}');
714+
715+
const errorElement = browser.$(Selectors.InsertDialogErrorMessage);
716+
await errorElement.waitForDisplayed();
717+
expect(await errorElement.getText()).to.include(
718+
'Document failed validation'
719+
);
720+
// enter details
721+
const errorDetailsBtn = browser.$(Selectors.InsertDialogErrorDetailsBtn);
722+
await errorElement.waitForDisplayed();
723+
await errorDetailsBtn.click();
724+
725+
const errorDetailsJson = browser.$(Selectors.ErrorDetailsJson);
726+
await errorDetailsJson.waitForDisplayed();
727+
728+
// exit details
729+
await browser.clickVisible(Selectors.ErrorDetailsBackButton);
730+
await errorElement.waitForDisplayed();
731+
});
732+
});
688733
});

packages/compass-e2e-tests/tests/connection.test.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
DEFAULT_CONNECTION_NAMES,
2525
isTestingWeb,
2626
} from '../helpers/test-runner-context';
27+
import { tryToInsertDocument } from '../helpers/commands/try-to-insert-document';
2728

2829
async function disconnect(browser: CompassBrowser) {
2930
try {
@@ -162,25 +163,8 @@ async function assertCannotInsertData(
162163
'Documents'
163164
);
164165

165-
// browse to the "Insert to Collection" modal
166-
await browser.clickVisible(Selectors.AddDataButton);
167-
const insertDocumentOption = browser.$(Selectors.InsertDocumentOption);
168-
await insertDocumentOption.waitForDisplayed();
169-
await browser.clickVisible(Selectors.InsertDocumentOption);
170-
171-
// wait for the modal to appear
172-
const insertDialog = browser.$(Selectors.InsertDialog);
173-
await insertDialog.waitForDisplayed();
174-
175166
// go with the default text which should just be a random new id and therefore valid
176-
177-
// confirm
178-
const insertConfirm = browser.$(Selectors.InsertConfirm);
179-
// this selector is very brittle, so just make sure it works
180-
expect(await insertConfirm.isDisplayed()).to.be.true;
181-
expect(await insertConfirm.getText()).to.equal('Insert');
182-
await insertConfirm.waitForEnabled();
183-
await browser.clickVisible(Selectors.InsertConfirm);
167+
await tryToInsertDocument(browser);
184168

185169
// make sure that there's an error and that the insert button is disabled
186170
const errorElement = browser.$(Selectors.InsertDialogErrorMessage);
@@ -190,6 +174,7 @@ async function assertCannotInsertData(
190174
);
191175

192176
// cancel and wait for the modal to go away
177+
const insertDialog = browser.$(Selectors.InsertDialog);
193178
await browser.clickVisible(Selectors.InsertCancel);
194179
await insertDialog.waitForDisplayed({ reverse: true });
195180
}
@@ -521,7 +506,7 @@ describe('Connection string', function () {
521506
);
522507
});
523508

524-
it('can connect with readAnyDatabase builtin role', async function () {
509+
it.only('can connect with readAnyDatabase builtin role', async function () {
525510
if (!hasAtlasEnvironmentVariables()) {
526511
return this.skip();
527512
}

0 commit comments

Comments
 (0)