Fix resource deployment validations (#15963)

* Fix resource deployment validations

* comment out unused for now

* Fix tests
This commit is contained in:
Charles Gagnon
2021-07-01 11:49:14 -07:00
committed by GitHub
parent 5bc5816a25
commit b1a9d6baa1
3 changed files with 24 additions and 39 deletions

View File

@@ -12,10 +12,9 @@ import { InputValueType } from '../../../ui/modelViewUtils';
import { createValidation, GreaterThanOrEqualsValidation, IntegerValidation, LessThanOrEqualsValidation, RegexValidation, validateInputBoxComponent, Validation, ValidationType } from '../../../ui/validation/validations';
const inputBox = <azdata.InputBoxComponent>{
updateProperty(key: string, value: any) { }
validationErrorMessage: ''
};
let inputBoxStub: sinon.SinonStub;
const validationMessage = 'The field value is not valid';
const testValidations = [
{
type: ValidationType.IsInteger,
@@ -42,7 +41,6 @@ let onValidityChangedEmitter: vscode.EventEmitter<boolean>;
describe('Validation', () => {
beforeEach('validation setup', () => {
sinon.restore(); //cleanup all previously defined sinon mocks
inputBoxStub = sinon.stub(inputBox, 'updateProperty').resolves();
onValidityChangedEmitter = new vscode.EventEmitter<boolean>(); // recreate for every test so that any previous subscriptions on the event are cleared out.
});
describe('createValidation and validate input Box', () => {
@@ -50,7 +48,6 @@ describe('Validation', () => {
it(`validationType: ${testObj.type}`, async () => {
const validation = createValidation(
testObj,
async (isValid) => (isValid) ? inputBox.updateProperty('validationErrorMessage', undefined) : inputBox.updateProperty('validationErrorMessage', validationMessage),
async () => undefined,
async (_varName: string) => undefined,
(_variableName) => onValidityChangedEmitter.event,
@@ -62,9 +59,7 @@ describe('Validation', () => {
case ValidationType.LessThanOrEqualsTo: should(validation).be.instanceOf(LessThanOrEqualsValidation); break;
case ValidationType.GreaterThanOrEqualsTo: should(validation).be.instanceOf(GreaterThanOrEqualsValidation); break;
}
should(await validateInputBoxComponent(inputBox, [validation])).be.true(); // undefined and '' values are valid so validation should return true. This allows for fields that are not required
should(inputBoxStub.calledOnce).be.true();
should(inputBoxStub.getCall(0).args[1]).be.undefined();
should(await validateInputBoxComponent(inputBox, [validation])).be.true(`Call to validate should be true`); // undefined and '' values are valid so validation should return true. This allows for fields that are not required
});
});
});
@@ -87,7 +82,6 @@ describe('Validation', () => {
const validationDescription = `value: ${displayTestValue} was not an integer`;
const validation = new IntegerValidation(
{ type: ValidationType.IsInteger, description: validationDescription },
async (isValid) => (isValid) ? inputBox.updateProperty('validationErrorMessage', undefined) : inputBox.updateProperty('validationErrorMessage', validationMessage),
async () => testObj.value
);
await testValidation(validation, testObj, validationDescription);
@@ -114,7 +108,6 @@ describe('Validation', () => {
const validationDescription = `value:${displayTestValue} did not match the regex:/${testRegex}/`;
const validation = new RegexValidation(
{ type: ValidationType.IsInteger, description: validationDescription, regex: testRegex },
async (isValid) => (isValid) ? inputBox.updateProperty('validationErrorMessage', undefined) : inputBox.updateProperty('validationErrorMessage', validationMessage),
async () => testOb.value
);
await testValidation(validation, testOb, validationDescription);
@@ -173,7 +166,6 @@ describe('Validation', () => {
const validationDescription = `${displayTestValue} did not test as <= ${displayTargetValue}`;
const validation = new LessThanOrEqualsValidation(
{ type: ValidationType.IsInteger, description: validationDescription, target: targetVariableName },
async (isValid) => (isValid) ? inputBox.updateProperty('validationErrorMessage', undefined) : inputBox.updateProperty('validationErrorMessage', validationMessage),
async () => testObj.value,
async (_variableName: string) => testObj.targetValue,
(_variableName) => onValidityChangedEmitter.event,
@@ -228,7 +220,6 @@ describe('Validation', () => {
const validationDescription = `${displayTestValue} did not test as >= ${displayTargetValue}`;
const validation = new GreaterThanOrEqualsValidation(
{ type: ValidationType.IsInteger, description: validationDescription, target: targetVariableName },
async (isValid) => (isValid) ? inputBox.updateProperty('validationErrorMessage', undefined) : inputBox.updateProperty('validationErrorMessage', validationMessage),
async () => testObj.value,
async (_variableName: string) => testObj.targetValue,
(_variableName) => onValidityChangedEmitter.event,