Skip to content

Commit

Permalink
Add unit tests for changes and address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
akanduru committed Aug 31, 2022
1 parent 9c8a917 commit abd9d87
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
1 change: 0 additions & 1 deletion projects/schema-form/src/lib/form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export class FormComponent implements OnChanges, ControlValueAccessor {
// tslint:disable-next-line:no-output-on-prefix
@Output() onErrorsChange = new EventEmitter<{value: any}>();

// tslint:disable-next-line:no-output-on-prefix
@Output() modelReset = new EventEmitter<{value: any}>();

rootProperty: FormProperty = null;
Expand Down
4 changes: 2 additions & 2 deletions projects/schema-form/src/lib/model/arrayproperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class ArrayProperty extends PropertyGroup {

private addProperty(value) {
let itemSchema = this.schema.items;
if (Array.isArray(this.schema.items)) {
const itemSchemas = this.schema.items as object[];
if (Array.isArray(itemSchema)) {
const itemSchemas = itemSchema as object[];
if (itemSchemas.length > (<FormProperty[]>this.properties).length) {
itemSchema = itemSchema[(<FormProperty[]>this.properties).length];
} else if (this.schema.additionalItems) {
Expand Down
52 changes: 51 additions & 1 deletion projects/schema-form/src/lib/model/objectproperty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('ObjectProperty', () => {
};

let objProperty: ObjectProperty;
let value: any = null;


beforeEach(() => {
Expand All @@ -43,7 +44,8 @@ describe('ObjectProperty', () => {
THE_OBJECT_SCHEMA,
null,
'',
A_LOGGER
A_LOGGER,
value
);
});

Expand All @@ -57,4 +59,52 @@ describe('ObjectProperty', () => {
}
});

it('should create same properties as in schema with arbitrary parent path', () => {
value = {FOO: 1};
objProperty = new ObjectProperty(
A_FORM_PROPERTY_FACTORY,
A_SCHEMA_VALIDATOR_FACTORY,
A_VALIDATOR_REGISTRY,
A_EXPRESSION_COMPILER_FACTORY,
THE_OBJECT_SCHEMA,
null,
'/abc/def/*',
A_LOGGER,
value
);
for (const propertyId in THE_OBJECT_SCHEMA.properties) {
if (THE_OBJECT_SCHEMA.properties.hasOwnProperty(propertyId)) {
const property = objProperty.getProperty(propertyId);
expect(property).toBeDefined();
}
}
});

['extension', 'modifierExtension'].forEach((field) => {
it('Special handling for ' + field + ': should create same properties as in value', () => {
value = {FOO: 1};
objProperty = new ObjectProperty(
A_FORM_PROPERTY_FACTORY,
A_SCHEMA_VALIDATOR_FACTORY,
A_VALIDATOR_REGISTRY,
A_EXPRESSION_COMPILER_FACTORY,
THE_OBJECT_SCHEMA,
null,
'/abc/' + field + '/*',
A_LOGGER,
value
);
for (const propertyId in THE_OBJECT_SCHEMA.properties) {
if (THE_OBJECT_SCHEMA.properties.hasOwnProperty(propertyId)) {
const property = objProperty.getProperty(propertyId);
if (value.hasOwnProperty(propertyId)) {
expect(property).toBeDefined();
} else {
expect(property).toBeUndefined();
}
}
}
});
});

});

0 comments on commit abd9d87

Please sign in to comment.