Skip to content

Commit c142636

Browse files
authored
Merge pull request #23 from recurship/rc5-tests-fixes
rc5 upgrade - tests fixes and update typings
2 parents 381579e + 44b341a commit c142636

25 files changed

+324
-380
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A small playground using Angular2 RC1 which demonstrates a way to structure an a
44

55
## Functionality
66

7-
- [x] **RC5 ready!** [Tests still need fixing :(]
7+
- [x] **RC5 ready!**
88
- [x] Dynamic rendering and customising for form fields
99
- [x] Support for Text, Select, Radio and Checkboxes
1010
- [x] Large form broken over multiple components

angular-cli-build.js

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ module.exports = function(defaults) {
1616
'reflect-metadata/**/*.+(ts|js|js.map)',
1717
'rxjs/**/*.+(js|js.map)',
1818
'@angular/**/*.+(js|js.map)',
19-
'angular2-ie9-shims/*.js',
2019
'ng2-bootstrap/**/*.*',
2120
'moment/**/*.js'
2221
]

config/karma.conf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = function (config) {
77
frameworks: ['jasmine'],
88
plugins: [
99
require('karma-jasmine'),
10-
require('karma-chrome-launcher')
10+
require('karma-phantomjs-launcher')
1111
],
1212
customLaunchers: {
1313
// chrome setup for travis CI using chromium
@@ -39,7 +39,7 @@ module.exports = function (config) {
3939
colors: true,
4040
logLevel: config.LOG_INFO,
4141
autoWatch: true,
42-
browsers: ['Chrome'],
42+
browsers: ['PhantomJS'],
4343
singleRun: false
4444
});
4545
};

e2e/app.e2e-spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { AppPage } from './app.po';
2+
3+
describe('angular2-multicomponent-form App Tests: ', function() {
4+
let page: AppPage;
5+
6+
beforeEach(() => {
7+
page = new AppPage();
8+
});
9+
10+
it('should display message saying \'Angular2 Multi Component Dynamic Form demo\'', () => {
11+
page.navigateTo();
12+
expect(page.getParagraphText()).toEqual('Angular2 Multi Component Dynamic Form demo');
13+
});
14+
});

e2e/app.e2e.ts

-14
This file was deleted.

e2e/app.po.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
export class Angular2MulticomponentFormPage {
2-
3-
navigateTo(route: string = '/') {
4-
return browser.get(route);
1+
export class AppPage {
2+
waitTime: number = 3000;
3+
4+
navigateTo(route: string = '/#/') {
5+
browser.get(route);
6+
this.waitForPageToLoad();
7+
return;
58
}
69

710
getParagraphText() {
8-
return element(by.css('angular2-multicomponent-form-app h3')).getText();
11+
return element(by.css('app-root h3')).getText();
12+
}
13+
14+
waitForPageToLoad() {
15+
browser.wait(() => {
16+
return element(by.css('app-root')).getText().then((text) => {
17+
return text !== 'Loading...';
18+
});
19+
}, this.waitTime);
920
}
1021

1122
}

e2e/app.step.po.ts

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
export class AppStepFormPage {
2-
step: string;
3-
waitTime: number = 3000;
1+
import { AppPage } from './app.po';
42

3+
export class AppStepPage extends AppPage {
4+
step: string;
5+
56
constructor(step: string) {
7+
super();
68
this.step = step;
79
}
810

11+
/**
12+
* OVERRIDE FUNCTIONS
13+
*/
14+
915
navigateTo() {
10-
return browser.get('/' + this.step);
16+
super.navigateTo('/#/' + this.step);
1117
}
1218

19+
getParagraphText() {
20+
return element(by.css('app-' + this.step + ' p')).getText();
21+
}
22+
23+
/**
24+
* NEW FUNCTIONS
25+
*/
26+
1327
waitForField(field: string, text: string) {
1428
browser.wait(() => {
1529
return this.getErrorTextForField(field).then((errTxt) => {
@@ -34,17 +48,13 @@ export class AppStepFormPage {
3448
return this.hasClass('p#sidebar-'+ this.step + '-status', 'text-success');
3549
}
3650

37-
// form
51+
// Form
3852

3953
resetFields(fields: Array<string>) {
4054
fields.forEach((fieldname) => {
4155
this.getInputField(fieldname).clear();
4256
});
4357
}
44-
45-
getParagraphText() {
46-
return element(by.css('app-' + this.step + ' p')).getText();
47-
}
4858

4959
getErrorForField(fieldId: string) {
5060
return element(by.css('#' + fieldId + '_error_block em.text-danger'));
@@ -83,7 +93,7 @@ export class AppStepFormPage {
8393

8494
}
8595

86-
/* Tooltip */
96+
// Tooltip
8797

8898
clickOnField(fieldId: string) {
8999
this.getInputField(fieldId).click();

e2e/app.step1.e2e.ts renamed to e2e/app.step1.e2e-spec.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import { AppStepFormPage } from './app.step.po';
1+
import { AppStepPage } from './app.step.po';
22

33
describe('angular2-multicomponent-form App Step1 Tests: ', function() {
4-
let page: AppStepFormPage;
4+
let page: AppStepPage;
55

66
beforeEach(() => {
7-
page = new AppStepFormPage('step1');
7+
page = new AppStepPage('step1');
88
page.navigateTo();
99
// page.resetFields(['input_name', 'input_age_user']);
1010
});
1111

12+
/*
1213
it('should display message saying `This is step1.`', (done) => {
1314
expect(page.getParagraphText()).toEqual('This is step1.');
1415
done();
1516
});
17+
*/
1618

1719
it('should change input Area by changing input Region', (done) => {
1820
// default values set
@@ -45,17 +47,17 @@ describe('angular2-multicomponent-form App Step1 Tests: ', function() {
4547

4648
// step1 form validation tests!
4749

48-
it('should display error message `Required..` on input field `input_name` when empty', (done) => {
50+
it('should display error message `Required.` on input field `input_name` when empty', (done) => {
4951
page.clearInputField('input_name');
50-
expect(page.getErrorTextForField('input_name')).toEqual('Required..');
52+
expect(page.getErrorTextForField('input_name')).toEqual('Required.');
5153
expect(page.checkIfFieldHasError('input_name')).toBeTruthy();
5254
done();
5355
});
5456

55-
it('should perform validation on field as input value changes', (done) => {
57+
it('should perform validation on field \'input_name\'as input value changes', (done) => {
5658
page.setInputFieldValue('input_name', 'test');
5759
expect(page.checkIfFieldHasError('input_name')).toBeTruthy();
58-
expect(page.getErrorTextForField('input_name')).toEqual('Minimum length should be 5');
60+
expect(page.getErrorTextForField('input_name')).toEqual('Name should be atleast 5 characters.');
5961
done();
6062
});
6163

e2e/app.step2.e2e.ts renamed to e2e/app.step2.e2e-spec.ts

+7-23
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import { AppStepFormPage } from './app.step.po';
1+
import { AppStepPage } from './app.step.po';
22

33
describe('angular2-multicomponent-form App Step2 Tests: ', function() {
4-
let page: AppStepFormPage;
4+
let page: AppStepPage;
55

66
beforeEach(() => {
7-
page = new AppStepFormPage('step2');
7+
page = new AppStepPage('step2');
88
page.navigateTo();
99
// page.resetFields(['input_dependants', 'input_number_of_children', 'input_savings']);
1010
});
1111

12+
/*
1213
it('should display message saying `This is step2.`', (done) => {
1314
expect(page.getParagraphText()).toEqual('This is step2.');
1415
done();
1516
});
17+
*/
1618

1719
it('should create and show fields in step2 depend on field value in step1 i.e., `input_number_of_children` field.', (done) => {
1820
page.clickOnField('step1-button'); // step1
@@ -22,32 +24,14 @@ describe('angular2-multicomponent-form App Step2 Tests: ', function() {
2224
done();
2325
});
2426

25-
// Tooltip tests
26-
27-
it('should have/display tooltip with text `Enter number of dependants` when click/hover on field `input_dependants`', (done) => {
28-
page.clickOnField('input_dependants');
29-
expect(page.getFieldTooltip('input_dependants').isPresent()).toBeTruthy();
30-
expect(page.getFieldTooltipText('input_dependants')).toEqual('Enter number of dependants');
31-
done();
32-
});
33-
34-
// step2 form validation tests!
35-
36-
it('should display error message `Required..` on input field `input_savings` when empty', (done) => {
37-
page.clearInputField('input_savings');
38-
expect(page.getErrorTextForField('input_savings')).toEqual('Required..');
39-
expect(page.checkIfFieldHasError('input_savings')).toBeTruthy();
40-
done();
41-
});
42-
43-
it('should perform validation on field as input value changes', (done) => {
27+
it('should display error message \'The savings needs to be a number greater than zero.\' on input field `input_savings` when 0', (done) => {
4428
page.setInputFieldValue('input_savings', '0');
4529
expect(page.checkIfFieldHasError('input_savings')).toBeTruthy();
4630
expect(page.getErrorTextForField('input_savings')).toEqual('The savings needs to be a number greater than zero.');
4731
done();
4832
});
4933

50-
it('should not display error message on `input_savings` field if validation passes.', (done) => {
34+
it('should not display error message on `input_savings` field if value greater than 0', (done) => {
5135
page.setInputFieldValue('input_savings', '50');
5236
expect(page.checkIfFieldHasError('input_savings')).toBeFalsy();
5337
done();

e2e/typings.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/// <reference path="../typings/main.d.ts" />
1+
/// <reference path="../typings/index.d.ts" />

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
"@angular/platform-browser": "2.0.0-rc.5",
2222
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
2323
"@angular/router": "3.0.0-rc.1",
24-
24+
2525
"systemjs": "0.19.27",
2626
"core-js": "^2.4.0",
2727
"reflect-metadata": "^0.1.3",
2828
"rxjs": "5.0.0-beta.6",
2929
"zone.js": "^0.6.12",
30-
3130
"es6-shim": "0.35.1",
32-
"angular2-ie9-shims": "0.0.1",
31+
3332
"moment": "^2.13.0",
3433
"ng2-bootstrap": "^1.0.24"
3534
},
@@ -40,12 +39,13 @@
4039
"jasmine-core": "2.4.1",
4140
"jasmine-spec-reporter": "2.5.0",
4241
"karma": "0.13.22",
43-
"karma-chrome-launcher": "0.2.3",
42+
"karma-phantomjs-launcher": "^1.0.0",
43+
"phantomjs-prebuilt": "^2.1.7",
4444
"karma-jasmine": "0.3.8",
4545
"protractor": "3.3.0",
4646
"ts-node": "0.5.5",
4747
"tslint": "3.11.0",
4848
"typescript": "1.8.10",
49-
"typings": "0.8.1"
49+
"typings": "^1.3.2"
5050
}
5151
}
+17-41
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,25 @@
1-
/*
2-
import {
3-
beforeEach,
4-
beforeEachProviders,
5-
describe,
6-
expect,
7-
it,
8-
inject,
9-
} from '@angular/core/testing';
10-
import { ComponentFixture, TestComponentBuilder } from '@angular/compiler/testing';
11-
import { Component } from '@angular/core';
12-
import { By } from '@angular/platform-browser';
13-
import { Step1Component } from './step1.component';
14-
import { FormManager } from '../shared/form-manager';
15-
import { FormFieldService } from '../shared/form-field/';
1+
/* tslint:disable:no-unused-variable */
162

17-
describe('Component: Step1', () => {
18-
let builder: TestComponentBuilder;
3+
import { addProviders, async, inject } from '@angular/core/testing';
4+
import { FormBuilder } from '@angular/forms';
195

20-
beforeEachProviders(() => [Step1Component, FormManager, FormFieldService]);
21-
beforeEach(inject([TestComponentBuilder], function (tcb: TestComponentBuilder) {
22-
builder = tcb;
23-
}));
6+
import { Step1Component } from './step1.component';
7+
import { FormManager, FormFieldService } from '../shared';
8+
9+
describe('Component: Step1: ', () => {
10+
11+
beforeEach(() => {
12+
addProviders([
13+
Step1Component,
14+
FormBuilder,
15+
FormManager,
16+
FormFieldService
17+
]);
18+
});
2419

2520
it('should inject the component', inject([Step1Component],
2621
(component: Step1Component) => {
2722
expect(component).toBeTruthy();
2823
}));
2924

30-
it('should create the component', inject([], () => {
31-
return builder.createAsync(Step1ComponentTestController)
32-
.then((fixture: ComponentFixture<any>) => {
33-
let query = fixture.debugElement.query(By.directive(Step1Component));
34-
expect(query).toBeTruthy();
35-
expect(query.componentInstance).toBeTruthy();
36-
});
37-
}));
38-
});
39-
40-
@Component({
41-
selector: 'test',
42-
template: `
43-
<app-step1></app-step1>
44-
`,
45-
directives: [Step1Component]
46-
})
47-
class Step1ComponentTestController {
48-
}
49-
*/
25+
});

0 commit comments

Comments
 (0)