Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 1dd6e33

Browse files
committed
chore(test): angular2 testapp
1 parent ff3dff7 commit 1dd6e33

30 files changed

+92357
-5
lines changed

Diff for: scripts/test.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var passingTests = [
3131
'node lib/cli.js spec/getCapabilitiesConf.js',
3232
'node lib/cli.js spec/controlLockConf.js',
3333
'node lib/cli.js spec/customFramework.js',
34+
'node lib/cli.js spec/angular2Conf.js',
3435
'node scripts/interactive_tests/interactive_test.js',
3536
'node scripts/interactive_tests/with_base_url.js',
3637
// Unit tests

Diff for: scripts/test_on_travis.sh

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ if [ $JOB = "smoke" ]; then
55
node bin/protractor spec/ciSmokeConf.js
66
elif [ $JOB = "full" ]; then
77
node bin/protractor spec/ciFullConf.js
8+
if [ $? = "0" ]; then
9+
node bin/protractor spec/ciNg2Conf.js
10+
fi
811
elif [ $JOB = "bstack" ]; then
912
node bin/protractor spec/ciBStackConf.js
1013
else

Diff for: spec/angular2Conf.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ var env = require('./environment.js');
1010
// See https://github.com/angular/angular/blob/master/DEVELOPER.md for
1111
// setup instructions.
1212
//
13-
// TODO: when Angular2 is beta, include a test application in the
14-
// Protractor repository.
1513
exports.config = {
1614
seleniumAddress: env.seleniumAddress,
1715

@@ -23,7 +21,7 @@ exports.config = {
2321

2422
capabilities: env.capabilities,
2523

26-
baseUrl: 'http://localhost:8000',
24+
baseUrl: 'http://localhost:8081',
2725

2826
// Special option for Angular2, to test against all Angular2 applications
2927
// on the page. This means that Protractor will wait for every app to be

Diff for: spec/ciNg2Conf.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
exports.config = require('./angular2Conf.js').config;
2+
3+
exports.config.sauceUser = process.env.SAUCE_USERNAME;
4+
exports.config.sauceKey = process.env.SAUCE_ACCESS_KEY;
5+
exports.config.seleniumAddress = undefined;
6+
7+
// TODO: add in firefox when issue #2784 is fixed
8+
exports.config.multiCapabilities = [{
9+
'browserName': 'chrome',
10+
'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER,
11+
'build': process.env.TRAVIS_BUILD_NUMBER,
12+
'name': 'Protractor suite tests',
13+
'version': '46',
14+
'selenium-version': '2.48.2',
15+
'chromedriver-version': '2.19',
16+
'platform': 'OS X 10.9'
17+
}];
18+
exports.config.capabilities = undefined;

Diff for: spec/ng2/async_spec.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe('async angular2 application', function() {
2-
var URL = 'examples/src/async/index.html';
2+
var URL = '/ng2/#/async';
33

44
beforeEach(function() {
55
browser.get(URL);
@@ -44,7 +44,7 @@ describe('async angular2 application', function() {
4444
});
4545

4646
it('should wait for a series of asynchronous actions', function() {
47-
var timeout = $('#multiDelayedIncrements');
47+
var timeout = $('#chainedDelayedIncrements');
4848

4949
// At this point, the async action is still pending, so the count should
5050
// still be 0.
@@ -54,4 +54,27 @@ describe('async angular2 application', function() {
5454

5555
expect(timeout.$('.val').getText()).toEqual('10');
5656
});
57+
58+
it('should wait for a series of periodic increments', function() {
59+
var timeout = $('#periodicIncrement');
60+
61+
// Waits for the val to count to 1 and 2.
62+
var EC = protractor.ExpectedConditions;
63+
timeout.$('.action').click();
64+
browser.wait(EC.textToBePresentInElement(timeout.$('.val'), '1'), 3000);
65+
timeout.$('.cancel').click();
66+
67+
var text = timeout.$('.val').getText();
68+
browser.driver.sleep(3000);
69+
expect(timeout.$('.val').getText()).toEqual(text);
70+
71+
timeout.$('.action').click();
72+
browser.wait(EC.textToBePresentInElement(timeout.$('.val'), '3'), 6000);
73+
timeout.$('.cancel').click();
74+
75+
text = timeout.$('.val').getText();
76+
browser.driver.sleep(3000);
77+
expect(timeout.$('.val').getText()).toEqual(text);
78+
79+
});
5780
});

Diff for: testapp/ng2/app/app-router.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="container">
2+
<h1 class="title">Test App for Angular 2</h1>
3+
<nav class="nav">
4+
<a [routerLink]="['Home']">home</a>
5+
<a [routerLink]="['Async']">async</a>
6+
</nav>
7+
<router-outlet></router-outlet>
8+
</div>

Diff for: testapp/ng2/app/app.router.js

+49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: testapp/ng2/app/app.router.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: testapp/ng2/app/app.router.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {Component} from 'angular2/core';
2+
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';
3+
4+
import {HomeComponent} from './home/home.component';
5+
import {AsyncComponent} from './async/async.component';
6+
7+
@Component({
8+
selector: 'my-app',
9+
templateUrl: 'app/app-router.html',
10+
directives: [ROUTER_DIRECTIVES]
11+
})
12+
@RouteConfig([
13+
{path:'/', name: 'Home', component: HomeComponent},
14+
{path:'/async', name: 'Async', component: AsyncComponent},
15+
])
16+
export class AppRouter {
17+
}

Diff for: testapp/ng2/app/async/async-component.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<div id='increment'>
2+
<span class='val'>{{val1}}</span>
3+
<button class='action' (click)="increment()">Increment</button>
4+
</div>
5+
<div id='delayedIncrement'>
6+
<span class='val'>{{val2}}</span>
7+
<button class='action' (click)="delayedIncrement()">Delayed Increment</button>
8+
<button class='cancel' *ngIf="timeoutId != null"
9+
(click)="cancelDelayedIncrement()">Cancel</button>
10+
</div>
11+
<div id='chainedDelayedIncrements'>
12+
<span class='val'>{{val3}}</span>
13+
<button class='action'
14+
(click)="chainedDelayedIncrements(10)">10 Delayed Increments</button>
15+
<button class='cancel' *ngIf="chainedTimeoutId != null"
16+
(click)="cancelChainedDelayedIncrements()">Cancel</button>
17+
</div>
18+
<div id='periodicIncrement'>
19+
<span class='val'>{{val4}}</span>
20+
<button class='action'
21+
(click)="periodicIncrement()">Periodic Increment</button>
22+
<button class='cancel' *ngIf="intervalId != null"
23+
(click)="cancelPeriodicIncrement()">Cancel</button>
24+
</div>

Diff for: testapp/ng2/app/async/async.component.js

+102
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: testapp/ng2/app/async/async.component.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: testapp/ng2/app/async/async.component.ts

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {bootstrap} from 'angular2/bootstrap';
2+
import {Component} from 'angular2/core';
3+
import {NgIf} from 'angular2/common';
4+
import {TimerWrapper} from 'angular2/src/facade/async';
5+
6+
@Component({
7+
templateUrl: 'app/async/async-component.html',
8+
directives: [NgIf]
9+
})
10+
export class AsyncComponent {
11+
val1: number = 0;
12+
val2: number = 0;
13+
val3: number = 0;
14+
val4: number = 0;
15+
timeoutId = null;
16+
chainedTimeoutId = null;
17+
intervalId = null;
18+
19+
increment(): void { this.val1++; };
20+
21+
delayedIncrement(): void {
22+
this.cancelDelayedIncrement();
23+
this.timeoutId = TimerWrapper.setTimeout(() => {
24+
this.val2++;
25+
this.timeoutId = null;
26+
}, 2000);
27+
};
28+
29+
chainedDelayedIncrements(i: number): void {
30+
this.cancelChainedDelayedIncrements();
31+
32+
var self = this;
33+
function helper(_i) {
34+
if (_i <= 0) {
35+
self.chainedTimeoutId = null;
36+
return;
37+
}
38+
39+
self.chainedTimeoutId = TimerWrapper.setTimeout(() => {
40+
self.val3++;
41+
helper(_i - 1);
42+
}, 500);
43+
}
44+
helper(i);
45+
};
46+
47+
periodicIncrement(): void {
48+
this.cancelPeriodicIncrement();
49+
this.intervalId = TimerWrapper.setInterval(() => { this.val4++; }, 2000)
50+
};
51+
52+
cancelDelayedIncrement(): void {
53+
if (this.timeoutId != null) {
54+
TimerWrapper.clearTimeout(this.timeoutId);
55+
this.timeoutId = null;
56+
}
57+
};
58+
59+
cancelChainedDelayedIncrements(): void {
60+
if (this.chainedTimeoutId != null) {
61+
TimerWrapper.clearTimeout(this.chainedTimeoutId);
62+
this.chainedTimeoutId = null;
63+
}
64+
};
65+
66+
cancelPeriodicIncrement(): void {
67+
if (this.intervalId != null) {
68+
TimerWrapper.clearInterval(this.intervalId);
69+
this.intervalId = null;
70+
}
71+
};
72+
}

0 commit comments

Comments
 (0)