-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schema-validation): add confirmation modal when applying rules, …
…add explicit editing state COMPASS-8861 (#6766)
- Loading branch information
Showing
13 changed files
with
232 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 70 additions & 64 deletions
134
packages/compass-schema-validation/src/components/validation-editor.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,94 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@mongodb-js/testing-library-compass'; | ||
import { render, screen, userEvent } from '@mongodb-js/testing-library-compass'; | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import { ValidationEditor } from './validation-editor'; | ||
|
||
function renderValidationEditor( | ||
props: Partial<React.ComponentProps<typeof ValidationEditor>> | ||
) { | ||
const validation = { | ||
validator: '', | ||
validationAction: 'warn', | ||
validationLevel: 'moderate', | ||
isChanged: false, | ||
syntaxError: null, | ||
error: null, | ||
} as const; | ||
|
||
return render( | ||
<ValidationEditor | ||
namespace="test.test" | ||
validatorChanged={() => {}} | ||
validationActionChanged={() => {}} | ||
validationLevelChanged={() => {}} | ||
cancelValidation={() => {}} | ||
saveValidation={() => {}} | ||
clearSampleDocuments={() => {}} | ||
serverVersion="8.0.5" | ||
onClickEnableEditRules={() => {}} | ||
validation={validation} | ||
isEditable | ||
isEditingEnabled | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
describe('ValidationEditor [Component]', function () { | ||
context('when it is an editable mode', function () { | ||
const setValidatorChangedSpy = sinon.spy(); | ||
const setValidationActionChangedSpy = sinon.spy(); | ||
const setValidationLevelChangedSpy = sinon.spy(); | ||
const setCancelValidationSpy = sinon.spy(); | ||
const saveValidationSpy = sinon.spy(); | ||
const clearSampleDocumentsSpy = sinon.spy(); | ||
const serverVersion = '3.6.0'; | ||
const validation = { | ||
validator: '', | ||
validationAction: 'warn', | ||
validationLevel: 'moderate', | ||
isChanged: false, | ||
syntaxError: null, | ||
error: null, | ||
} as const; | ||
const isEditable = true; | ||
context( | ||
'when it is an editable mode but editing is not yet enabled', | ||
function () { | ||
let onClickEnableEditRulesSpy: sinon.SinonSpy; | ||
beforeEach(function () { | ||
onClickEnableEditRulesSpy = sinon.spy(); | ||
renderValidationEditor({ | ||
onClickEnableEditRules: onClickEnableEditRulesSpy, | ||
isEditingEnabled: false, | ||
isEditable: true, | ||
}); | ||
}); | ||
|
||
it('does not allow to edit the editor', function () { | ||
expect(screen.getByTestId('validation-editor')).to.exist; | ||
expect(screen.getByRole('textbox').ariaReadOnly).to.eq('true'); | ||
expect(screen.getByTestId('enable-edit-validation-button')).to.be | ||
.visible; | ||
expect(onClickEnableEditRulesSpy).to.not.have.been.called; | ||
userEvent.click(screen.getByTestId('enable-edit-validation-button')); | ||
expect(onClickEnableEditRulesSpy).to.have.been.calledOnce; | ||
}); | ||
} | ||
); | ||
|
||
context('when it is an editable mode and editing is enabled', function () { | ||
beforeEach(function () { | ||
render( | ||
<ValidationEditor | ||
namespace="test.test" | ||
validatorChanged={setValidatorChangedSpy} | ||
validationActionChanged={setValidationActionChangedSpy} | ||
validationLevelChanged={setValidationLevelChangedSpy} | ||
cancelValidation={setCancelValidationSpy} | ||
saveValidation={saveValidationSpy} | ||
clearSampleDocuments={clearSampleDocumentsSpy} | ||
serverVersion={serverVersion} | ||
validation={validation} | ||
isEditable={isEditable} | ||
/> | ||
); | ||
renderValidationEditor({ | ||
isEditable: true, | ||
isEditingEnabled: true, | ||
}); | ||
}); | ||
|
||
it('allows to edit the editor', function () { | ||
expect(screen.getByTestId('validation-editor')).to.exist; | ||
expect(screen.getByRole('textbox').ariaReadOnly).to.eq(null); | ||
expect( | ||
screen.queryByTestId('enable-edit-validation-button') | ||
).to.not.exist; | ||
}); | ||
}); | ||
|
||
context('when it is a not editable mode', function () { | ||
const setValidatorChangedSpy = sinon.spy(); | ||
const setValidationActionChangedSpy = sinon.spy(); | ||
const setValidationLevelChangedSpy = sinon.spy(); | ||
const setCancelValidationSpy = sinon.spy(); | ||
const saveValidationSpy = sinon.spy(); | ||
const clearSampleDocumentsSpy = sinon.spy(); | ||
const serverVersion = '3.6.0'; | ||
const validation = { | ||
validator: '', | ||
validationAction: 'warn', | ||
validationLevel: 'moderate', | ||
isChanged: false, | ||
syntaxError: null, | ||
error: null, | ||
} as const; | ||
const isEditable = false; | ||
|
||
beforeEach(function () { | ||
render( | ||
<ValidationEditor | ||
namespace="test.test" | ||
validatorChanged={setValidatorChangedSpy} | ||
validationActionChanged={setValidationActionChangedSpy} | ||
validationLevelChanged={setValidationLevelChangedSpy} | ||
cancelValidation={setCancelValidationSpy} | ||
saveValidation={saveValidationSpy} | ||
clearSampleDocuments={clearSampleDocumentsSpy} | ||
serverVersion={serverVersion} | ||
validation={validation} | ||
isEditable={isEditable} | ||
/> | ||
); | ||
renderValidationEditor({ | ||
isEditable: false, | ||
}); | ||
}); | ||
|
||
it('sets editor into readonly mode', function () { | ||
expect(screen.getByRole('textbox').ariaReadOnly).to.eq('true'); | ||
expect( | ||
screen.queryByTestId('enable-edit-validation-button') | ||
).to.not.exist; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.