Skip to content
71 changes: 71 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-e2e-tests/helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,8 @@ export const ValidationActionSelector =
'[data-testid="validation-action-selector"]';
export const ValidationLevelSelector =
'[data-testid="validation-level-selector"]';
export const GenerateValidationRulesButton =
'[data-testid="generate-rules-button"]';

// Find (Documents and Schema tabs)
export const queryBar = (tabName: string): string => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import type { Compass } from '../helpers/compass';
import * as Selectors from '../helpers/selectors';
import { createNumbersCollection } from '../helpers/insert-data';
import { expect } from 'chai';
import { isTestingDesktop } from '../helpers/test-runner-context';

const NO_PREVIEW_DOCUMENTS = 'No Preview Documents';
const PASSING_VALIDATOR = '{ $jsonSchema: {} }';
Expand Down Expand Up @@ -52,6 +54,45 @@ describe('Collection validation tab', function () {
await browser.setValidation(validation);
}

context('when the schema validation is empty', function () {
before(async function () {
if (isTestingDesktop()) {
await browser.setFeature('enableExportSchema', true);
}
});

it('provides users with a button to generate rules', async function () {
await browser.clickVisible(Selectors.GenerateValidationRulesButton);
const editor = browser.$(Selectors.ValidationEditor);
await editor.waitForDisplayed();

// rules are generated
const generatedRules = await browser.getCodemirrorEditorText(
Selectors.ValidationEditor
);
expect(JSON.parse(generatedRules)).to.deep.equal({
$jsonSchema: {
bsonType: 'object',
required: ['_id', 'i', 'j'],
properties: {
_id: {
bsonType: 'objectId',
},
i: {
bsonType: 'int',
},
j: {
bsonType: 'int',
},
},
},
});

// generated rules can be edited and saved
await browser.setValidation(PASSING_VALIDATOR);
});
});

context('when the schema validation is set or modified', function () {
it('provides users with a single button to load sample documents', async function () {
await addValidation(PASSING_VALIDATOR);
Expand Down
2 changes: 2 additions & 0 deletions packages/compass-schema-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@
"@mongodb-js/compass-editor": "^0.36.5",
"@mongodb-js/compass-field-store": "^9.25.5",
"@mongodb-js/compass-logging": "^1.6.5",
"@mongodb-js/compass-schema": "^6.51.5",
"@mongodb-js/compass-telemetry": "^1.4.5",
"@mongodb-js/compass-workspaces": "^0.31.5",
"bson": "^6.10.3",
"compass-preferences-model": "^2.33.5",
"hadron-app-registry": "^9.4.5",
"javascript-stringify": "^2.0.1",
"lodash": "^4.17.21",
"mongodb": "^6.14.1",
"mongodb-ns": "^2.4.2",
"mongodb-query-parser": "^4.3.0",
"react": "^17.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const { renderWithConnections } = createPluginTestHelpers(
describe('ValidationStates [Component]', function () {
let props: any;

const render = (props: any) => {
return renderWithConnections(<ValidationStates {...props} />);
const render = (props: any, options: any = {}) => {
return renderWithConnections(<ValidationStates {...props} />, options);
};

beforeEach(function () {
Expand Down Expand Up @@ -255,13 +255,18 @@ describe('ValidationStates [Component]', function () {
props.isZeroState = true;
props.isLoaded = true;
props.serverVersion = '3.2.0';

render(props);
});

it('renders the zero state', function () {
render(props);
expect(screen.getByTestId('empty-content')).to.exist;
});

it('when enableExportSchema is set, shows button for rules generation', function () {
render(props, { preferences: { enableExportSchema: true } });
const btn = screen.getByRole('button', { name: 'Generate rules' });
expect(btn).to.be.visible;
});
});

context('when it is not in the zero state and not loaded', function () {
Expand Down
Loading
Loading