diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b93e296 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +sudo: required +dist: trusty +addons: + apt: + update: true + sources: + - google-chrome + packages: + - google-chrome-stable +language: node_js +node_js: + - stable +before_install: + - echo "$TRAVIS_BRANCH" + - echo "$TRAVIS_PULL_REQUEST" + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start + - export CHROME_BIN=chromium-browser +install: + - npm install +script: + - npm run lint + - npm run test + - if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == false ]; then npm run ghpages; fi +deploy: + provider: pages + skip_cleanup: true + local_dir: dist + github_token: $PUSH_TOKEN + on: + branch: master diff --git a/karma.conf.js b/karma.conf.js index d6816d7..610a1d6 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -26,7 +26,7 @@ module.exports = function (config) { logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], - singleRun: false, - restartOnFileChange: true + singleRun: true, + restartOnFileChange: false }); }; diff --git a/package.json b/package.json index 5087f32..8d15451 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,16 @@ { - "name": "ngx-smart-form", - "version": "0.0.0", + "name": "angular-dynamic-forms", + "description": "Create on-the-fly forms with Angular", + "version": "1.0.0", + "author": "Maxime LAFARIE ", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", - "e2e": "ng e2e" + "e2e": "ng e2e", + "ghpages": "npm i && ng build --prod --aot --no-progress --base-href '/angular-dynamic-forms/'" }, "private": true, "dependencies": { diff --git a/src/app/_components/common/dynamic-form-question/dynamic-form-question.component.spec.ts b/src/app/_components/common/dynamic-form-question/dynamic-form-question.component.spec.ts index 4aa001c..88b4286 100644 --- a/src/app/_components/common/dynamic-form-question/dynamic-form-question.component.spec.ts +++ b/src/app/_components/common/dynamic-form-question/dynamic-form-question.component.spec.ts @@ -1,6 +1,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { DynamicFormQuestionComponent } from './dynamic-form-question.component'; +import { DynamicFormQuestionModule } from './dynamic-form-question.module'; +import { FormGroup, FormControl } from '@angular/forms'; describe('DynamicFormQuestionComponent', () => { let component: DynamicFormQuestionComponent; @@ -8,14 +10,32 @@ describe('DynamicFormQuestionComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ DynamicFormQuestionComponent ] + imports: [DynamicFormQuestionModule] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(DynamicFormQuestionComponent); component = fixture.componentInstance; + + // Mock form + component.form = new FormGroup({ + firstName: new FormControl() + }); + + // Mock question + component.question = { + value: 'Bombasto', + key: 'firstName', + label: 'First name', + required: true, + order: 1, + controlType: 'textbox', + placeholder: '', + iterable: false + }; + fixture.detectChanges(); }); diff --git a/src/app/_components/common/dynamic-form-question/dynamic-form-question.component.ts b/src/app/_components/common/dynamic-form-question/dynamic-form-question.component.ts index 676e97e..bf8fbda 100644 --- a/src/app/_components/common/dynamic-form-question/dynamic-form-question.component.ts +++ b/src/app/_components/common/dynamic-form-question/dynamic-form-question.component.ts @@ -34,15 +34,19 @@ export class DynamicFormQuestionComponent implements OnInit { return this.form.get(this.question.key) as FormArray; } + public get questionIsIterable(): boolean { + return !!this.question && this.question.iterable; + } + public questionControl(index?: number): AbstractControl { - return this.question.iterable ? this.asFormArray(this.form.get(this.question.key)).controls[index] : this.form.get(this.question.key); + return this.questionIsIterable ? this.asFormArray(this.form.get(this.question.key)).controls[index] : this.form.get(this.question.key); } public questionId(index?: number): string { - return this.question.iterable ? `${this.question.key}-${index}` : this.question.key; + return this.questionIsIterable ? `${this.question.key}-${index}` : this.question.key; } public questionLabel(index?: number): string { - return this.question.iterable ? `${this.question.label} n°${index + 1}` : this.question.label; + return this.questionIsIterable ? `${this.question.label} n°${index + 1}` : this.question.label; } } diff --git a/src/app/_components/common/dynamic-form/dynamic-form.component.spec.ts b/src/app/_components/common/dynamic-form/dynamic-form.component.spec.ts index 1d3b4a4..b79fed6 100644 --- a/src/app/_components/common/dynamic-form/dynamic-form.component.spec.ts +++ b/src/app/_components/common/dynamic-form/dynamic-form.component.spec.ts @@ -1,6 +1,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { DynamicFormComponent } from './dynamic-form.component'; +import { DynamicFormModule } from './dynamic-form.module'; describe('DynamicFormComponent', () => { let component: DynamicFormComponent; @@ -8,7 +9,7 @@ describe('DynamicFormComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ DynamicFormComponent ] + imports: [ DynamicFormModule ] }) .compileComponents(); })); diff --git a/src/app/_services/question-control.service.spec.ts b/src/app/_services/question-control.service.spec.ts index 8edfb9b..c1cfaef 100644 --- a/src/app/_services/question-control.service.spec.ts +++ b/src/app/_services/question-control.service.spec.ts @@ -3,7 +3,9 @@ import { TestBed } from '@angular/core/testing'; import { QuestionControlService } from './question-control.service'; describe('QuestionControlService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + beforeEach(() => TestBed.configureTestingModule({ + providers: [QuestionControlService] + })); it('should be created', () => { const service: QuestionControlService = TestBed.get(QuestionControlService); diff --git a/src/app/_services/question.service.spec.ts b/src/app/_services/question.service.spec.ts index bfa0ca5..87e00aa 100644 --- a/src/app/_services/question.service.spec.ts +++ b/src/app/_services/question.service.spec.ts @@ -3,7 +3,9 @@ import { TestBed } from '@angular/core/testing'; import { QuestionService } from './question.service'; describe('QuestionService', () => { - beforeEach(() => TestBed.configureTestingModule({})); + beforeEach(() => TestBed.configureTestingModule({ + providers: [QuestionService] + })); it('should be created', () => { const service: QuestionService = TestBed.get(QuestionService); diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index caa6302..e19700d 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,16 +1,15 @@ import { TestBed, async } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { AppComponent } from './app.component'; +import { AppModule } from './app.module'; describe('AppComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ - RouterTestingModule - ], - declarations: [ - AppComponent - ], + RouterTestingModule, + AppModule + ] }).compileComponents(); }));