Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function (config) {
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
singleRun: true,
restartOnFileChange: false
});
};
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <maxime.lafarie@gmail.com>",
"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": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
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;
let fixture: ComponentFixture<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();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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;
let fixture: ComponentFixture<DynamicFormComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DynamicFormComponent ]
imports: [ DynamicFormModule ]
})
.compileComponents();
}));
Expand Down
4 changes: 3 additions & 1 deletion src/app/_services/question-control.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/app/_services/question.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
}));

Expand Down