Skip to content

Commit 24d5efd

Browse files
committed
test: add e2e test
1 parent 0191839 commit 24d5efd

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

packages/compass-aggregations/src/components/pipeline-results-workspace/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const PipelineResultsWorkspace: React.FunctionComponent<
166166
<Button
167167
size="xsmall"
168168
onClick={onRetry}
169-
data-testid="pipeline-results-error-details-button"
169+
data-testid="pipeline-results-error-retry-button"
170170
className={errorDetailsBtnStyles}
171171
>
172172
RETRY

packages/compass-e2e-tests/helpers/commands/set-validation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ export async function setValidation(
6868
collection,
6969
'Validation'
7070
);
71-
await browser.clickVisible(Selectors.AddRuleButton);
71+
const startButton = browser.$(Selectors.AddRuleButton);
72+
if (await startButton.isExisting()) {
73+
await browser.clickVisible(startButton);
74+
}
7275
const element = browser.$(Selectors.ValidationEditor);
7376
await element.waitForDisplayed();
7477
await browser.setValidationWithinValidationTab(validator);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,8 @@ export const SavePipelineSaveAsAction =
852852
export const AggregationAutoPreviewToggle =
853853
'[data-testid="pipeline-toolbar-preview-toggle"]';
854854
export const AggregationErrorBanner = '[data-testid="pipeline-results-error"]';
855+
export const AggregationErrorDetailsBtn =
856+
'[data-testid="pipeline-results-error"] [data-testid="pipeline-results-error-details-button"]';
855857

856858
export const RunPipelineButton = `[data-testid="pipeline-toolbar-run-button"]`;
857859
export const EditPipelineButton = `[data-testid="pipeline-toolbar-edit-button"]`;

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

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,84 @@ describe('Collection aggregations tab', function () {
615615
);
616616
});
617617

618+
context('with existing validation rule', function () {
619+
const REQUIRE_PHONE_VALIDATOR =
620+
'{ $jsonSchema: { bsonType: "object", required: [ "phone" ] } }';
621+
const VALIDATED_OUT_COLLECTION = 'nestedDocs';
622+
beforeEach(async function () {
623+
await browser.setValidation({
624+
connectionName: DEFAULT_CONNECTION_NAME_1,
625+
database: 'test',
626+
collection: VALIDATED_OUT_COLLECTION,
627+
validator: REQUIRE_PHONE_VALIDATOR,
628+
});
629+
await browser.navigateToCollectionTab(
630+
DEFAULT_CONNECTION_NAME_1,
631+
'test',
632+
'numbers',
633+
'Aggregations'
634+
);
635+
await addStage(browser, 1);
636+
});
637+
638+
afterEach(async function () {
639+
await browser.setValidation({
640+
connectionName: DEFAULT_CONNECTION_NAME_1,
641+
database: 'test',
642+
collection: VALIDATED_OUT_COLLECTION,
643+
validator: '{}',
644+
});
645+
});
646+
647+
it('Shows error info when inserting', async function () {
648+
await browser.selectStageOperator(0, '$out');
649+
await browser.setCodemirrorEditorValue(
650+
Selectors.stageEditor(0),
651+
`'${VALIDATED_OUT_COLLECTION}'`
652+
);
653+
654+
await waitForAnyText(browser, browser.$(Selectors.stageContent(0)));
655+
656+
// run the $out stage
657+
await browser.clickVisible(Selectors.RunPipelineButton);
658+
659+
// confirm the write operation
660+
const writeOperationConfirmationModal = browser.$(
661+
Selectors.AggregationWriteOperationConfirmationModal
662+
);
663+
await writeOperationConfirmationModal.waitForDisplayed();
664+
665+
const description = await browser
666+
.$(Selectors.AggregationWriteOperationConfirmationModalDescription)
667+
.getText();
668+
669+
expect(description).to.contain(`test.${VALIDATED_OUT_COLLECTION}`);
670+
671+
await browser.clickVisible(
672+
Selectors.AggregationWriteOperationConfirmButton
673+
);
674+
675+
await writeOperationConfirmationModal.waitForDisplayed({ reverse: true });
676+
677+
const errorElement = browser.$(Selectors.AggregationErrorBanner);
678+
await errorElement.waitForDisplayed();
679+
expect(await errorElement.getText()).to.include(
680+
'Document failed validation'
681+
);
682+
// enter details
683+
const errorDetailsBtn = browser.$(Selectors.AggregationErrorDetailsBtn);
684+
await errorElement.waitForDisplayed();
685+
await errorDetailsBtn.click();
686+
687+
const errorDetailsJson = browser.$(Selectors.ErrorDetailsJson);
688+
await errorDetailsJson.waitForDisplayed();
689+
690+
// exit details
691+
await browser.clickVisible(Selectors.confirmationModalConfirmButton());
692+
await errorElement.waitForDisplayed();
693+
});
694+
});
695+
618696
it('cancels pipeline with $out as the last stage', async function () {
619697
await browser.selectStageOperator(0, '$out');
620698
await browser.setCodemirrorEditorValue(

0 commit comments

Comments
 (0)