Skip to content

Commit f78c18f

Browse files
author
Maxime Lafarie
authored
Merge pull request #2 from maximelafarie/feature/add-travis-ci-build
Add travis CI build, fix tests
2 parents b42eb13 + 57e479b commit f78c18f

File tree

9 files changed

+80
-18
lines changed

9 files changed

+80
-18
lines changed

.travis.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
sudo: required
2+
dist: trusty
3+
addons:
4+
apt:
5+
update: true
6+
sources:
7+
- google-chrome
8+
packages:
9+
- google-chrome-stable
10+
language: node_js
11+
node_js:
12+
- stable
13+
before_install:
14+
- echo "$TRAVIS_BRANCH"
15+
- echo "$TRAVIS_PULL_REQUEST"
16+
- export DISPLAY=:99.0
17+
- sh -e /etc/init.d/xvfb start
18+
- export CHROME_BIN=chromium-browser
19+
install:
20+
- npm install
21+
script:
22+
- npm run lint
23+
- npm run test
24+
- if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == false ]; then npm run ghpages; fi
25+
deploy:
26+
provider: pages
27+
skip_cleanup: true
28+
local_dir: dist
29+
github_token: $PUSH_TOKEN
30+
on:
31+
branch: master

karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = function (config) {
2626
logLevel: config.LOG_INFO,
2727
autoWatch: true,
2828
browsers: ['Chrome'],
29-
singleRun: false,
30-
restartOnFileChange: true
29+
singleRun: true,
30+
restartOnFileChange: false
3131
});
3232
};

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
2-
"name": "ngx-smart-form",
3-
"version": "0.0.0",
2+
"name": "angular-dynamic-forms",
3+
"description": "Create on-the-fly forms with Angular",
4+
"version": "1.0.0",
5+
"author": "Maxime LAFARIE <maxime.lafarie@gmail.com>",
46
"scripts": {
57
"ng": "ng",
68
"start": "ng serve",
79
"build": "ng build",
810
"test": "ng test",
911
"lint": "ng lint",
10-
"e2e": "ng e2e"
12+
"e2e": "ng e2e",
13+
"ghpages": "npm i && ng build --prod --aot --no-progress --base-href '/angular-dynamic-forms/'"
1114
},
1215
"private": true,
1316
"dependencies": {

src/app/_components/common/dynamic-form-question/dynamic-form-question.component.spec.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { DynamicFormQuestionComponent } from './dynamic-form-question.component';
4+
import { DynamicFormQuestionModule } from './dynamic-form-question.module';
5+
import { FormGroup, FormControl } from '@angular/forms';
46

57
describe('DynamicFormQuestionComponent', () => {
68
let component: DynamicFormQuestionComponent;
79
let fixture: ComponentFixture<DynamicFormQuestionComponent>;
810

911
beforeEach(async(() => {
1012
TestBed.configureTestingModule({
11-
declarations: [ DynamicFormQuestionComponent ]
13+
imports: [DynamicFormQuestionModule]
1214
})
13-
.compileComponents();
15+
.compileComponents();
1416
}));
1517

1618
beforeEach(() => {
1719
fixture = TestBed.createComponent(DynamicFormQuestionComponent);
1820
component = fixture.componentInstance;
21+
22+
// Mock form
23+
component.form = new FormGroup({
24+
firstName: new FormControl()
25+
});
26+
27+
// Mock question
28+
component.question = {
29+
value: 'Bombasto',
30+
key: 'firstName',
31+
label: 'First name',
32+
required: true,
33+
order: 1,
34+
controlType: 'textbox',
35+
placeholder: '',
36+
iterable: false
37+
};
38+
1939
fixture.detectChanges();
2040
});
2141

src/app/_components/common/dynamic-form-question/dynamic-form-question.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@ export class DynamicFormQuestionComponent implements OnInit {
3434
return this.form.get(this.question.key) as FormArray;
3535
}
3636

37+
public get questionIsIterable(): boolean {
38+
return !!this.question && this.question.iterable;
39+
}
40+
3741
public questionControl(index?: number): AbstractControl {
38-
return this.question.iterable ? this.asFormArray(this.form.get(this.question.key)).controls[index] : this.form.get(this.question.key);
42+
return this.questionIsIterable ? this.asFormArray(this.form.get(this.question.key)).controls[index] : this.form.get(this.question.key);
3943
}
4044

4145
public questionId(index?: number): string {
42-
return this.question.iterable ? `${this.question.key}-${index}` : this.question.key;
46+
return this.questionIsIterable ? `${this.question.key}-${index}` : this.question.key;
4347
}
4448

4549
public questionLabel(index?: number): string {
46-
return this.question.iterable ? `${this.question.label}${index + 1}` : this.question.label;
50+
return this.questionIsIterable ? `${this.question.label}${index + 1}` : this.question.label;
4751
}
4852
}

src/app/_components/common/dynamic-form/dynamic-form.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { DynamicFormComponent } from './dynamic-form.component';
4+
import { DynamicFormModule } from './dynamic-form.module';
45

56
describe('DynamicFormComponent', () => {
67
let component: DynamicFormComponent;
78
let fixture: ComponentFixture<DynamicFormComponent>;
89

910
beforeEach(async(() => {
1011
TestBed.configureTestingModule({
11-
declarations: [ DynamicFormComponent ]
12+
imports: [ DynamicFormModule ]
1213
})
1314
.compileComponents();
1415
}));

src/app/_services/question-control.service.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { TestBed } from '@angular/core/testing';
33
import { QuestionControlService } from './question-control.service';
44

55
describe('QuestionControlService', () => {
6-
beforeEach(() => TestBed.configureTestingModule({}));
6+
beforeEach(() => TestBed.configureTestingModule({
7+
providers: [QuestionControlService]
8+
}));
79

810
it('should be created', () => {
911
const service: QuestionControlService = TestBed.get(QuestionControlService);

src/app/_services/question.service.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { TestBed } from '@angular/core/testing';
33
import { QuestionService } from './question.service';
44

55
describe('QuestionService', () => {
6-
beforeEach(() => TestBed.configureTestingModule({}));
6+
beforeEach(() => TestBed.configureTestingModule({
7+
providers: [QuestionService]
8+
}));
79

810
it('should be created', () => {
911
const service: QuestionService = TestBed.get(QuestionService);

src/app/app.component.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { TestBed, async } from '@angular/core/testing';
22
import { RouterTestingModule } from '@angular/router/testing';
33
import { AppComponent } from './app.component';
4+
import { AppModule } from './app.module';
45

56
describe('AppComponent', () => {
67
beforeEach(async(() => {
78
TestBed.configureTestingModule({
89
imports: [
9-
RouterTestingModule
10-
],
11-
declarations: [
12-
AppComponent
13-
],
10+
RouterTestingModule,
11+
AppModule
12+
]
1413
}).compileComponents();
1514
}));
1615

0 commit comments

Comments
 (0)