Skip to content

Commit d4de8ed

Browse files
committed
add tests
1 parent d1cae8c commit d4de8ed

File tree

5 files changed

+156
-8
lines changed

5 files changed

+156
-8
lines changed

packages/compass-components/src/components/document-list/document-edit-actions-footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ const EditActionsFooter: React.FunctionComponent<{
328328
className={button}
329329
size="xsmall"
330330
onClick={() => onOpenErrorDetails?.(error.details!)}
331-
data-testid="insert-document-error-details-button"
331+
data-testid="edit-actions-footer-error-details-button"
332332
>
333333
VIEW ERROR DETAILS
334334
</Button>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ const Document = (props: DocumentProps) => {
4343
}
4444

4545
if (editable) {
46-
console.log('PROP IS HERE', props.openErrorDetailsDialog);
4746
return <EditableDocument {...props} doc={doc} />;
4847
}
4948

packages/compass-crud/src/stores/crud-store.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -705,11 +705,6 @@ class CrudStoreImpl
705705
const nbsp = '\u00a0';
706706
error.message += ` (Updating fields whose names contain dots or start with $ require MongoDB${nbsp}5.0 or above.)`;
707707
}
708-
console.log(
709-
'updateDocument error',
710-
error,
711-
(error as MongoServerError).errInfo
712-
);
713708
doc.onUpdateError(error as Error);
714709
} else if (d) {
715710
doc.onUpdateSuccess(d);
@@ -808,7 +803,6 @@ class CrudStoreImpl
808803
'replace'
809804
);
810805
if (error) {
811-
console.log('replaceDocument error', error);
812806
doc.onUpdateError(error as Error);
813807
} else {
814808
doc.onUpdateSuccess(d);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ export const DocumentListFetchingStopButton =
593593
'[data-testid="documents-content"] [data-testid="fetching-documents"] button';
594594
export const DocumentListError = '[data-testid="document-list-error-summary"]';
595595
export const AddDataButton = '[data-testid="crud-add-data-show-actions"]';
596+
export const EditDocumentButton = '[data-testid="edit-document-button"]';
596597
export const InsertDocumentOption =
597598
'[data-testid="crud-add-data-insert-document-action"]';
598599
export const ImportFileOption =
@@ -608,6 +609,8 @@ export const CloneDocumentButton = '[data-testid="clone-document-button"]';
608609
export const DeleteDocumentButton = '[data-testid="remove-document-button"]';
609610
export const DocumentFooter = '[data-testid="document-footer"]';
610611
export const DocumentFooterMessage = '[data-testid="document-footer-message"]';
612+
export const DocumentFooterErrorDetailsButton =
613+
'[data-testid="edit-actions-footer-error-details-button"]';
611614
export const UpdateDocumentButton = `${DocumentFooter} [data-testid="update-button"]`;
612615
export const ConfirmDeleteDocumentButton = `${DocumentFooter} [data-testid="delete-button"]`;
613616
export const JSONDocumentCard = '[data-testid="editable-json"]';

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

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import { context as testRunnerContext } from '../helpers/test-runner-context';
2121
import type { ChainablePromiseElement } from 'webdriverio';
2222
import { tryToInsertDocument } from '../helpers/commands/try-to-insert-document';
23+
import { isClickable } from 'webdriverio/build/commands/element';
2324

2425
const { expect } = chai;
2526

@@ -729,5 +730,156 @@ FindIterable<Document> result = collection.find(filter);`);
729730
await browser.clickVisible(Selectors.ErrorDetailsBackButton);
730731
await errorElement.waitForDisplayed();
731732
});
733+
734+
describe('Editing', function () {
735+
beforeEach(async function () {
736+
await browser.navigateWithinCurrentCollectionTabs('Documents');
737+
await tryToInsertDocument(browser, `{ "phone": 12345 }`);
738+
await browser.runFindOperation('Documents', '{ "phone": 12345 }');
739+
});
740+
741+
it.only('shows error info when editing via list view', async function () {
742+
const document = browser.$(Selectors.DocumentListEntry);
743+
await document.waitForDisplayed();
744+
745+
// enter edit mode
746+
await browser.hover(Selectors.DocumentListEntry);
747+
await browser.clickVisible(Selectors.EditDocumentButton);
748+
749+
// delete the required field
750+
await browser.hover(`${Selectors.HadronDocumentElement}:last-child`);
751+
const deleteBtn = browser.$(
752+
`${Selectors.HadronDocumentElement}:last-child ${Selectors.HadronDocumentRemoveElement}`
753+
);
754+
console.log({
755+
isDisplayed: await deleteBtn.isDisplayed(),
756+
isClickable: await deleteBtn.isClickable(),
757+
isEnabled: await deleteBtn.isEnabled(),
758+
});
759+
760+
await deleteBtn.waitForDisplayed();
761+
console.log('I am displayed');
762+
await deleteBtn.waitForClickable();
763+
console.log('I am clickable');
764+
await deleteBtn.click();
765+
766+
// confirm update
767+
const footer = document.$(Selectors.DocumentFooterMessage);
768+
expect(await footer.getText()).to.equal('Document modified.');
769+
770+
const button = document.$(Selectors.UpdateDocumentButton);
771+
await button.click();
772+
773+
const errorMessage = browser.$(Selectors.DocumentFooterMessage);
774+
await errorMessage.waitForDisplayed();
775+
expect(await errorMessage.getText()).to.include(
776+
'Document failed validation'
777+
);
778+
779+
// enter details
780+
const errorDetailsBtn = browser.$(
781+
Selectors.DocumentFooterErrorDetailsButton
782+
);
783+
await errorDetailsBtn.waitForDisplayed();
784+
console.log({ errorDetailsBtn });
785+
await errorDetailsBtn.click();
786+
787+
const errorDetailsJson = browser.$(Selectors.ErrorDetailsJson);
788+
await errorDetailsJson.waitForDisplayed();
789+
790+
// exit details
791+
await browser.clickVisible(Selectors.ErrorDetailsCloseButton);
792+
await errorDetailsJson.waitForDisplayed({ reverse: true });
793+
});
794+
795+
it('shows error info when editing via json view', async function () {
796+
await browser.clickVisible(Selectors.SelectJSONView);
797+
798+
const document = browser.$(Selectors.DocumentJSONEntry);
799+
await document.waitForDisplayed();
800+
801+
await waitForJSON(browser, document);
802+
803+
// enter edit mode
804+
await browser.hover(Selectors.JSONDocumentCard);
805+
await browser.clickVisible(Selectors.JSONEditDocumentButton);
806+
807+
// remove the required field
808+
await browser.setCodemirrorEditorValue(
809+
Selectors.DocumentJSONEntry,
810+
`{}`
811+
);
812+
813+
// confirm update
814+
const footer = document.$(Selectors.DocumentFooterMessage);
815+
expect(await footer.getText()).to.equal('Document modified.');
816+
817+
const button = document.$(Selectors.UpdateDocumentButton);
818+
await button.click();
819+
820+
const errorMessage = browser.$(Selectors.DocumentFooterMessage);
821+
await errorMessage.waitForDisplayed();
822+
expect(await errorMessage.getText()).to.include(
823+
'Document failed validation'
824+
);
825+
826+
// enter details
827+
const errorDetailsBtn = browser.$(
828+
Selectors.DocumentFooterErrorDetailsButton
829+
);
830+
await errorDetailsBtn.waitForDisplayed();
831+
await errorDetailsBtn.click();
832+
833+
const errorDetailsJson = browser.$(Selectors.ErrorDetailsJson);
834+
await errorDetailsJson.waitForDisplayed();
835+
836+
// exit details
837+
await browser.clickVisible(Selectors.ErrorDetailsCloseButton);
838+
await errorDetailsJson.waitForDisplayed({ reverse: true });
839+
});
840+
841+
it('shows error info when editing via table view', async function () {
842+
await browser.clickVisible(Selectors.SelectTableView);
843+
844+
const document = browser.$('.ag-center-cols-clipper .ag-row-first');
845+
await document.waitForDisplayed();
846+
847+
// enter edit mode
848+
const value = document.$('[col-id="phone"] .element-value');
849+
await value.doubleClick();
850+
851+
// remove the required field
852+
await browser.clickVisible(
853+
'[data-testid="table-view-cell-editor-remove-field-button"]'
854+
);
855+
856+
// confirm update
857+
const footer = browser.$(Selectors.DocumentFooterMessage);
858+
expect(await footer.getText()).to.equal('Document modified.');
859+
860+
const button = browser.$(Selectors.UpdateDocumentButton);
861+
await button.click();
862+
863+
const errorMessage = browser.$(Selectors.DocumentFooterMessage);
864+
await errorMessage.waitForDisplayed();
865+
expect(await errorMessage.getText()).to.include(
866+
'Document failed validation'
867+
);
868+
869+
// enter details
870+
const errorDetailsBtn = browser.$(
871+
Selectors.DocumentFooterErrorDetailsButton
872+
);
873+
await errorDetailsBtn.waitForDisplayed();
874+
await errorDetailsBtn.click();
875+
876+
const errorDetailsJson = browser.$(Selectors.ErrorDetailsJson);
877+
await errorDetailsJson.waitForDisplayed();
878+
879+
// exit details
880+
await browser.clickVisible(Selectors.ErrorDetailsCloseButton);
881+
await errorDetailsJson.waitForDisplayed({ reverse: true });
882+
});
883+
});
732884
});
733885
});

0 commit comments

Comments
 (0)