update upgrade-phonecat-2-hybrid
This commit is contained in:
parent
b342d24ef3
commit
1af3570910
|
@ -32,17 +32,4 @@ export function setProtractorToNg1Mode(): void {
|
||||||
export function setProtractorToHybridMode() {
|
export function setProtractorToHybridMode() {
|
||||||
setProtractorToNg1Mode();
|
setProtractorToNg1Mode();
|
||||||
browser.ng12Hybrid = true;
|
browser.ng12Hybrid = true;
|
||||||
// remove once waitForNg1AsyncBootstrap() is removed as well
|
|
||||||
browser.ignoreSynchronization = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO remove once all update adapter tests are moved to setProtractorToHybridMode
|
|
||||||
// Protractor doesn't support the UpgradeAdapter's asynchronous
|
|
||||||
// bootstrap with Angular 1 at the moment. Get around it by
|
|
||||||
// waiting for an element to get `ng-scope` class.
|
|
||||||
export function waitForNg1AsyncBootstrap() {
|
|
||||||
browser.ignoreSynchronization = true;
|
|
||||||
browser.driver.wait(function() {
|
|
||||||
return element(by.css('.ng-scope')).isPresent();
|
|
||||||
}, 5000);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
'use strict'; // necessary for es6 output in node
|
'use strict'; // necessary for es6 output in node
|
||||||
|
|
||||||
import { browser, element, by } from 'protractor';
|
import { browser, element, by } from 'protractor';
|
||||||
import { setProtractorToNg1Mode, waitForNg1AsyncBootstrap } from '../protractor-helpers';
|
import { setProtractorToHybridMode } from '../protractor-helpers';
|
||||||
|
|
||||||
// Angular E2E Testing Guide:
|
// Angular E2E Testing Guide:
|
||||||
// https://docs.angularjs.org/guide/e2e-testing
|
// https://docs.angularjs.org/guide/e2e-testing
|
||||||
|
|
||||||
describe('PhoneCat Application', function() {
|
describe('PhoneCat Application', function() {
|
||||||
|
|
||||||
|
beforeAll(function () {
|
||||||
|
setProtractorToHybridMode();
|
||||||
|
});
|
||||||
|
|
||||||
it('should redirect `index.html` to `index.html#!/phones', function() {
|
it('should redirect `index.html` to `index.html#!/phones', function() {
|
||||||
browser.get('index.html');
|
browser.get('index.html');
|
||||||
setProtractorToNg1Mode();
|
|
||||||
waitForNg1AsyncBootstrap();
|
|
||||||
expect(browser.getLocationAbsUrl()).toBe('/phones');
|
expect(browser.getLocationAbsUrl()).toBe('/phones');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,8 +21,6 @@ describe('PhoneCat Application', function() {
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
browser.get('index.html#!/phones');
|
browser.get('index.html#!/phones');
|
||||||
setProtractorToNg1Mode();
|
|
||||||
waitForNg1AsyncBootstrap();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should filter the phone list as a user types into the search box', function() {
|
it('should filter the phone list as a user types into the search box', function() {
|
||||||
|
@ -64,12 +64,12 @@ describe('PhoneCat Application', function() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
fit('should render phone specific links', function() {
|
it('should render phone specific links', function() {
|
||||||
let query = element(by.css('input'));
|
let query = element(by.css('input'));
|
||||||
query.sendKeys('nexus');
|
query.sendKeys('nexus');
|
||||||
|
|
||||||
element.all(by.css('.phones li a')).first().click();
|
element.all(by.css('.phones li a')).first().click();
|
||||||
waitForNg1AsyncBootstrap(); // Not sure why this is needed but it is. The route change works fine.
|
browser.sleep(200); // Not sure why this is needed but it is. The route change works fine.
|
||||||
expect(browser.getLocationAbsUrl()).toBe('/phones/nexus-s');
|
expect(browser.getLocationAbsUrl()).toBe('/phones/nexus-s');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -79,8 +79,6 @@ describe('PhoneCat Application', function() {
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
browser.get('index.html#!/phones/nexus-s');
|
browser.get('index.html#!/phones/nexus-s');
|
||||||
setProtractorToNg1Mode();
|
|
||||||
waitForNg1AsyncBootstrap();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display the `nexus-s` page', function() {
|
it('should display the `nexus-s` page', function() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// #docplaster
|
// #docplaster
|
||||||
// #docregion bare
|
// #docregion bare
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
|
import { UpgradeModule } from '@angular/upgrade/static';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
// #enddocregion bare
|
// #enddocregion bare
|
||||||
// #docregion httpmodule
|
// #docregion httpmodule
|
||||||
|
@ -27,6 +28,7 @@ import { PhoneDetailComponent } from './phone-detail/phone-detail.component';
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
UpgradeModule,
|
||||||
// #enddocregion bare
|
// #enddocregion bare
|
||||||
HttpModule,
|
HttpModule,
|
||||||
// #enddocregion httpmodule, phone
|
// #enddocregion httpmodule, phone
|
||||||
|
@ -42,10 +44,27 @@ import { PhoneDetailComponent } from './phone-detail/phone-detail.component';
|
||||||
CheckmarkPipe
|
CheckmarkPipe
|
||||||
// #docregion phonelist, phonedetail
|
// #docregion phonelist, phonedetail
|
||||||
],
|
],
|
||||||
|
entryComponents: [
|
||||||
|
PhoneListComponent,
|
||||||
|
// #enddocregion phonelist
|
||||||
|
PhoneDetailComponent
|
||||||
|
// #enddocregion phonedetail
|
||||||
|
],
|
||||||
// #docregion phone
|
// #docregion phone
|
||||||
providers: [ Phone ]
|
providers: [
|
||||||
|
Phone,
|
||||||
|
// #docregion routeparams
|
||||||
|
{
|
||||||
|
provide: '$routeParams',
|
||||||
|
useFactory: (i: any) => i.get('$routeParams'),
|
||||||
|
deps: ['$injector']
|
||||||
|
}
|
||||||
|
// #enddocregion routeparams
|
||||||
|
]
|
||||||
// #docregion bare, httpmodule, phonelist
|
// #docregion bare, httpmodule, phonelist
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {
|
||||||
|
ngDoBootstrap() {}
|
||||||
|
}
|
||||||
// #enddocregion httpmodule, phone, phonelist, phonedetail, checkmarkpipe
|
// #enddocregion httpmodule, phone, phonelist, phonedetail, checkmarkpipe
|
||||||
// #enddocregion bare
|
// #enddocregion bare
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// #docregion import-adapter
|
// #docregion import-adapter
|
||||||
import { UpgradeAdapter } from '@angular/upgrade';
|
|
||||||
declare var angular: any;
|
declare var angular: any;
|
||||||
|
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||||
|
import { UpgradeModule, downgradeComponent, downgradeInjectable } from '@angular/upgrade/static';
|
||||||
|
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
// #enddocregion import-adapter
|
// #enddocregion import-adapter
|
||||||
|
@ -17,24 +18,24 @@ import { PhoneDetailComponent } from './phone-detail/phone-detail.component';
|
||||||
|
|
||||||
// #enddocregion phone-detail
|
// #enddocregion phone-detail
|
||||||
// #docregion init-adapter
|
// #docregion init-adapter
|
||||||
let upgradeAdapter = new UpgradeAdapter(AppModule);
|
// let upgradeAdapter = new UpgradeAdapter(AppModule);
|
||||||
// #enddocregion init-adapter
|
// #enddocregion init-adapter
|
||||||
|
|
||||||
// #docregion routeparams
|
// #docregion routeparams
|
||||||
upgradeAdapter.upgradeNg1Provider('$routeParams');
|
// upgradeAdapter.upgradeNg1Provider('$routeParams');
|
||||||
// #enddocregion routeparams
|
// #enddocregion routeparams
|
||||||
|
|
||||||
// #docregion phone-service
|
// #docregion phone-service
|
||||||
|
|
||||||
angular.module('core.phone')
|
angular.module('core.phone')
|
||||||
.factory('phone', upgradeAdapter.downgradeNg2Provider(Phone));
|
.factory('phone', downgradeInjectable(Phone));
|
||||||
// #enddocregion phone-service
|
// #enddocregion phone-service
|
||||||
// #docregion phone-list
|
// #docregion phone-list
|
||||||
|
|
||||||
angular.module('phoneList')
|
angular.module('phoneList')
|
||||||
.directive(
|
.directive(
|
||||||
'phoneList',
|
'phoneList',
|
||||||
upgradeAdapter.downgradeNg2Component(PhoneListComponent) as angular.IDirectiveFactory
|
downgradeComponent({component: PhoneListComponent}) as angular.IDirectiveFactory
|
||||||
);
|
);
|
||||||
// #enddocregion phone-list
|
// #enddocregion phone-list
|
||||||
// #docregion phone-detail
|
// #docregion phone-detail
|
||||||
|
@ -42,10 +43,14 @@ angular.module('phoneList')
|
||||||
angular.module('phoneDetail')
|
angular.module('phoneDetail')
|
||||||
.directive(
|
.directive(
|
||||||
'phoneDetail',
|
'phoneDetail',
|
||||||
upgradeAdapter.downgradeNg2Component(PhoneDetailComponent) as angular.IDirectiveFactory
|
downgradeComponent({component: PhoneDetailComponent}) as angular.IDirectiveFactory
|
||||||
);
|
);
|
||||||
// #enddocregion phone-detail
|
// #enddocregion phone-detail
|
||||||
|
|
||||||
// #docregion bootstrap
|
// #docregion bootstrap
|
||||||
upgradeAdapter.bootstrap(document.documentElement, ['phonecatApp']);
|
// upgradeAdapter.bootstrap(document.documentElement, ['phonecatApp']);
|
||||||
|
platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
|
||||||
|
let upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
|
||||||
|
upgrade.bootstrap(document.body, ['phonecatApp'], {strictDi: true});
|
||||||
|
});
|
||||||
// #enddocregion bootstrap
|
// #enddocregion bootstrap
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
<script src="/node_modules/systemjs/dist/system.src.js"></script>
|
<script src="/node_modules/systemjs/dist/system.src.js"></script>
|
||||||
<!-- #enddocregion ng2 -->
|
<!-- #enddocregion ng2 -->
|
||||||
<script src="/systemjs.config.1.js"></script>
|
<script src="/systemjs.config.1.js"></script>
|
||||||
|
<script src="/systemjs.config.extras.js"></script>
|
||||||
<!-- #docregion ng2
|
<!-- #docregion ng2
|
||||||
<script src="/systemjs.config.js"></script>
|
<script src="/systemjs.config.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
// #docregion
|
||||||
|
/** App specific SystemJS configuration */
|
||||||
|
System.config({
|
||||||
|
map: {
|
||||||
|
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue