Skip to content

Commit

Permalink
minor refinements (closes #206)
Browse files Browse the repository at this point in the history
  • Loading branch information
udos86 committed Dec 15, 2016
1 parent 479041f commit 391101a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion example/app/foundation/foundation-example.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {FOUNDATION_EXAMPLE_MODEL} from "./foundation-example.model";

moduleId: module.id,
selector: "dynamic-form-foundation-example",
styleUrls: ["../../../node_modules/foundation-sites/dist/foundation.min.css"],
styleUrls: ["../../../node_modules/foundation-sites/dist/css/foundation.css"],
templateUrl: "./foundation-example.component.html",
encapsulation: ViewEncapsulation.None
})
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/model/input/dynamic-input.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export interface DynamicInputModelConfig extends DynamicInputControlModelConfig<
accept?: string;
inputType?: string;
list?: Array<string>;
max?: number;
min?: number;
max?: number | string;
min?: number | string;
multiple?: boolean;
pattern?: string;
step?: number;
Expand Down
27 changes: 24 additions & 3 deletions modules/core/src/service/dynamic-form.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import {TestBed, inject} from "@angular/core/testing";
import {ReactiveFormsModule, FormGroup, FormControl, FormArray, NG_VALIDATORS} from "@angular/forms";
import {
ReactiveFormsModule,
FormGroup,
FormControl,
FormArray,
NG_VALIDATORS,
NG_ASYNC_VALIDATORS
} from "@angular/forms";
import {DynamicFormService} from "./dynamic-form.service";
import {DynamicCheckboxModel} from "../model/checkbox/dynamic-checkbox.model";
import {DynamicCheckboxGroupModel} from "../model/checkbox/dynamic-checkbox-group.model";
Expand All @@ -20,19 +27,25 @@ describe("DynamicFormService test suite", () => {
function testValidator() {

return {
testValidate: {
testValidator: {
valid: true
}
};
}

function testAsyncValidator() {

return new Promise<boolean>(resolve => setTimeout(() => resolve(true), 0));
}

beforeEach(() => {

TestBed.configureTestingModule({
imports: [ReactiveFormsModule],
providers: [
DynamicFormService,
{provide: NG_VALIDATORS, useValue: testValidator, multi: true}
{provide: NG_VALIDATORS, useValue: testValidator, multi: true},
{provide: NG_ASYNC_VALIDATORS, useValue: testAsyncValidator, multi: true}
]
});

Expand Down Expand Up @@ -274,6 +287,14 @@ describe("DynamicFormService test suite", () => {
expect(validators.length).toBe(Object.keys(config).length);
});

it("should resolve custom async validators from config correctly", () => {

let config = {required: null, maxLength: 7, testAsyncValidator: null},
validators = service.getValidatorFns(config);

expect(validators.length).toBe(Object.keys(config).length);
});

it("should throw when validator is not provided via NG_VALIDATORS", () => {

expect(() => service.getValidatorFn("test", null))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"rollup-plugin-uglify": "^1.0.1",
"run-sequence": "^1.2.2",
"systemjs-builder": "^0.15.34",
"tslint": "^4.0.2",
"tslint": "^4.1.0",
"typedoc": "^0.5.1",
"typescript": "^2.1.4",
"webpack": "^1.14.0"
Expand Down

0 comments on commit 391101a

Please sign in to comment.