Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit ec4c1ed

Browse files
teropawardbell
authored andcommitted
docs(upgrade): add E2E tests, update PhoneCat dependencies
closes #1070 Separates UpgradeAdapter reference guide examples from the PhoneCat tutorial examples and update dependencies for phonecat upgrade examples
1 parent 1ba1407 commit ec4c1ed

File tree

245 files changed

+843
-617
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

245 files changed

+843
-617
lines changed

public/docs/_examples/protractor.config.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exports.config = {
3232

3333
// doesn't seem to work.
3434
// resultJsonOutputFile: "foo.json",
35-
35+
3636
onPrepare: function() {
3737
//// SpecReporter
3838
//var SpecReporter = require('jasmine-spec-reporter');
@@ -60,6 +60,12 @@ exports.config = {
6060
global.describeIf = describeIf;
6161
global.itIf = itIf;
6262
global.sendKeys = sendKeys;
63+
64+
// Allow changing bootstrap mode to NG1 for upgrade tests
65+
global.setProtractorToNg1Mode = function() {
66+
browser.useAllAngular2AppRoots = false;
67+
browser.rootEl = 'body';
68+
};
6369
},
6470

6571
jasmineNodeOpts: {
@@ -187,4 +193,3 @@ function Reporter(options) {
187193
}
188194

189195
}
190-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
describe('Upgrade Tests', function () {
2+
3+
// Protractor doesn't support the UpgradeAdapter's asynchronous
4+
// bootstrap with Angular 1 at the moment. Get around it by
5+
// waiting for an element to get `ng-scope` class.
6+
function waitForNg1AsyncBootstrap() {
7+
browser.ignoreSynchronization = true;
8+
browser.driver.wait(function() {
9+
return element(by.css('.ng-scope')).isPresent();
10+
}, 5000);
11+
}
12+
13+
describe('NG1 Auto-bootstrap', function() {
14+
15+
beforeAll(function () {
16+
browser.get('/index-ng-app.html');
17+
setProtractorToNg1Mode();
18+
});
19+
20+
it('bootstraps as expected', function () {
21+
expect(element(by.css('#message')).getText()).toEqual('Hello world');
22+
});
23+
24+
});
25+
26+
describe('NG1 JavaScript Bootstrap', function() {
27+
28+
beforeAll(function () {
29+
browser.get('/index-bootstrap.html');
30+
setProtractorToNg1Mode();
31+
});
32+
33+
it('bootstraps as expected', function () {
34+
expect(element(by.css('#message')).getText()).toEqual('Hello world');
35+
});
36+
37+
});
38+
39+
describe('NG1-2 Hybrid Bootstrap', function() {
40+
41+
beforeAll(function () {
42+
browser.get('/index-1-2-hybrid-bootstrap.html');
43+
setProtractorToNg1Mode();
44+
});
45+
46+
it('bootstraps as expected', function () {
47+
expect(element(by.css('#message')).getText()).toEqual('Hello world');
48+
});
49+
50+
});
51+
52+
describe('NG1-2 Hybrid Bootstrap with Shared UpgradeAdapter', function() {
53+
54+
beforeAll(function () {
55+
browser.get('/index-1-2-hybrid-shared-adapter-bootstrap.html');
56+
setProtractorToNg1Mode();
57+
});
58+
59+
it('bootstraps as expected', function () {
60+
expect(element(by.css('#message')).getText()).toEqual('Hello world');
61+
});
62+
63+
});
64+
65+
describe('Upgraded static component', function() {
66+
67+
beforeAll(function () {
68+
browser.get('/index-upgrade-static.html');
69+
setProtractorToNg1Mode();
70+
waitForNg1AsyncBootstrap();
71+
});
72+
73+
it('renders', function () {
74+
expect(element(by.css('h2')).getText()).toEqual('Windstorm details!');
75+
});
76+
77+
});
78+
79+
80+
describe('Upgraded component with IO', function() {
81+
82+
beforeAll(function () {
83+
browser.get('/index-upgrade-io.html');
84+
setProtractorToNg1Mode();
85+
waitForNg1AsyncBootstrap();
86+
});
87+
88+
it('has inputs', function () {
89+
expect(element(by.css('h2')).getText()).toEqual('Windstorm details!');
90+
});
91+
92+
it('has outputs', function () {
93+
element(by.buttonText('Delete')).click();
94+
expect(element(by.css('h2')).getText()).toEqual('Ex-Windstorm details!');
95+
});
96+
97+
});
98+
99+
100+
describe('Downgraded static component', function() {
101+
102+
beforeAll(function () {
103+
browser.get('/index-downgrade-static.html');
104+
setProtractorToNg1Mode();
105+
waitForNg1AsyncBootstrap();
106+
});
107+
108+
it('renders', function () {
109+
expect(element(by.css('h2')).getText()).toEqual('Windstorm details!');
110+
});
111+
112+
});
113+
114+
describe('Downgraded component with IO', function() {
115+
116+
beforeAll(function () {
117+
browser.get('/index-downgrade-io.html');
118+
setProtractorToNg1Mode();
119+
waitForNg1AsyncBootstrap();
120+
});
121+
122+
it('has inputs', function () {
123+
expect(element.all(by.css('h2')).first().getText()).toEqual('Windstorm details!');
124+
});
125+
126+
it('has outputs', function () {
127+
element.all(by.buttonText('Delete')).first().click();
128+
expect(element.all(by.css('h2')).first().getText()).toEqual('Ex-Windstorm details!');
129+
});
130+
131+
it('supports ng-repeat', function () {
132+
expect(element.all(by.css('hero-detail')).count()).toBe(3);
133+
});
134+
135+
});
136+
137+
138+
describe('Downgraded component with content projection', function() {
139+
140+
beforeAll(function () {
141+
browser.get('/index-1-to-2-projection.html');
142+
setProtractorToNg1Mode();
143+
waitForNg1AsyncBootstrap();
144+
});
145+
146+
it('can be transcluded into', function () {
147+
expect(element(by.css('hero-detail')).getText()).toContain('Specific powers of controlling winds');
148+
});
149+
150+
});
151+
152+
153+
describe('Upgraded component with transclusion', function() {
154+
155+
beforeAll(function () {
156+
browser.get('/index-2-to-1-transclusion.html');
157+
setProtractorToNg1Mode();
158+
waitForNg1AsyncBootstrap();
159+
});
160+
161+
it('can be projected into', function () {
162+
expect(element(by.css('hero-detail')).getText()).toContain('Specific powers of controlling winds');
163+
});
164+
165+
});
166+
167+
168+
describe('Upgrading NG1 Providers', function() {
169+
170+
beforeAll(function () {
171+
browser.get('/index-1-to-2-providers.html');
172+
setProtractorToNg1Mode();
173+
waitForNg1AsyncBootstrap();
174+
});
175+
176+
it('works', function () {
177+
expect(element(by.css('h2')).getText()).toBe('1: Windstorm');
178+
});
179+
180+
});
181+
182+
183+
describe('Downgrading NG2 Providers', function() {
184+
185+
beforeAll(function () {
186+
browser.get('/index-2-to-1-providers.html');
187+
setProtractorToNg1Mode();
188+
waitForNg1AsyncBootstrap();
189+
});
190+
191+
it('works', function () {
192+
expect(element(by.css('h2')).getText()).toBe('1: Windstorm');
193+
});
194+
195+
});
196+
197+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/*.js

public/docs/_examples/upgrade/ts/adapter/app/js/1-2-hybrid-bootstrap/app.module.ts renamed to public/docs/_examples/upgrade-adapter/ts/app/1-2-hybrid-bootstrap/app.module.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {UpgradeAdapter} from 'angular2/upgrade';
66
// #enddocregion bootstrap
77

88
angular.module('heroApp', [])
9-
.run(() => console.log('running'));
9+
.controller('MainCtrl', function() {
10+
this.message = 'Hello world';
11+
});
1012

1113
// #docregion bootstrap
1214

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {upgradeAdapter} from './upgrade_adapter';
66
declare var angular:any;
77

88
angular.module('heroApp', [])
9-
.run(() => console.log('running'));
9+
.controller('MainCtrl', function() {
10+
this.message = 'Hello world';
11+
});
1012

1113
// #docregion bootstrap
1214

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
declare var angular:any;
2+
3+
angular.module('heroApp', [])
4+
.controller('MainCtrl', function() {
5+
this.message = 'Hello world';
6+
});
7+
8+
document.addEventListener('DOMContentLoaded', function() {
9+
// #docregion bootstrap
10+
angular.bootstrap(document.body, ['heroApp'], {strictDi: true});
11+
// #enddocregion bootstrap
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare var angular:any;
2+
3+
angular.module('heroApp', [])
4+
.controller('MainCtrl', function() {
5+
this.message = 'Hello world';
6+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {Hero} from '../Hero';
2+
3+
export class MainController {
4+
hero = new Hero(1, 'Windstorm', 'Specific powers of controlling winds');
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Heroes} from './heroes';
2+
3+
// #docregion
4+
export const heroDetailComponent = {
5+
template: `
6+
<h2>{{$ctrl.hero.id}}: {{$ctrl.hero.name}}</h2>
7+
`,
8+
controller: ['heroes', function(heroes:Heroes) {
9+
this.hero = heroes.get()[0];
10+
}]
11+
};

public/docs/_examples/upgrade/ts/adapter/app/js/2-to-1-transclusion/container.component.ts renamed to public/docs/_examples/upgrade-adapter/ts/app/2-to-1-transclusion/container.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ const HeroDetail = upgradeAdapter.upgradeNg1Component('heroDetail');
1616
directives: [HeroDetail]
1717
})
1818
export class ContainerComponent {
19-
hero = new Hero(1, 'Windstorm', 'a descr');
19+
hero = new Hero(1, 'Windstorm', 'Specific powers of controlling winds');
2020
}

public/docs/_examples/upgrade/ts/adapter/app/js/2-to-1-transclusion/hero-detail.component.ts renamed to public/docs/_examples/upgrade-adapter/ts/app/2-to-1-transclusion/hero-detail.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const heroDetailComponent = {
44
hero: '='
55
},
66
template: `
7-
<h2>{{hero.name}}</h2>
7+
<h2>{{$ctrl.hero.name}}</h2>
88
<div>
99
<ng-transclude></ng-transclude>
1010
</div>

public/docs/_examples/upgrade/ts/adapter/app/js/downgrade-io/main.controller.ts renamed to public/docs/_examples/upgrade-adapter/ts/app/downgrade-io/main.controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export class MainController {
77
new Hero(3, 'Spiderman')
88
]
99
onDelete(hero:Hero) {
10-
console.log('del', hero);
10+
hero.name = 'Ex-' + hero.name;
1111
}
1212
}

public/docs/_examples/upgrade/ts/adapter/app/js/upgrade-io/container.component.ts renamed to public/docs/_examples/upgrade-adapter/ts/app/upgrade-io/container.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const HeroDetail = upgradeAdapter.upgradeNg1Component('heroDetail');
1717
})
1818
export class ContainerComponent {
1919
hero = new Hero(1, 'Windstorm');
20-
heroDeleted(event) {
21-
console.log(event);
20+
heroDeleted(hero:Hero) {
21+
hero.name = 'Ex-' + hero.name;
2222
}
2323
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// #docregion
2+
export const heroDetail = {
3+
bindings: {
4+
hero: '=',
5+
deleted: '&'
6+
},
7+
template: `
8+
<h2>{{$ctrl.hero.name}} details!</h2>
9+
<div><label>id: </label>{{$ctrl.hero.id}}</div>
10+
<button ng-click="$ctrl.onDelete()">Delete</button>
11+
`,
12+
controller: function() {
13+
this.onDelete = () => {
14+
this.deleted(this.hero);
15+
};
16+
}
17+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1">
5+
<link rel="stylesheet" href="styles.css">
6+
7+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.js"></script>
8+
9+
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
10+
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
11+
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
12+
13+
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
14+
<script src="node_modules/systemjs/dist/system.src.js"></script>
15+
<script src="node_modules/rxjs/bundles/Rx.js"></script>
16+
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
17+
<script src="node_modules/angular2/bundles/upgrade.dev.js"></script>
18+
<script>
19+
System.config({
20+
packages: {
21+
app: {
22+
format: 'register',
23+
defaultExtension: 'js'
24+
}
25+
}
26+
});
27+
System.import('app/1-2-hybrid-bootstrap/app.module')
28+
.then(null, console.error.bind(console));
29+
</script>
30+
</head>
31+
<body>
32+
<div id="message" ng-controller="MainCtrl as mainCtrl">{{ mainCtrl.message }}</div>
33+
</body>
34+
</html>

0 commit comments

Comments
 (0)