fix(platform-server): fix get/set title in parse5 adapter (#14965)

This commit is contained in:
Jason Jean
2017-03-13 16:22:03 -04:00
committed by Chuck Jazdzewski
parent e7dab7e6c1
commit 018e5c979b
2 changed files with 40 additions and 3 deletions

View File

@ -11,7 +11,7 @@ import {ApplicationRef, CompilerFactory, Component, NgModule, NgModuleRef, NgZon
import {TestBed, async, inject} from '@angular/core/testing';
import {Http, HttpModule, Response, ResponseOptions, XHRBackend} from '@angular/http';
import {MockBackend, MockConnection} from '@angular/http/testing';
import {BrowserModule, DOCUMENT} from '@angular/platform-browser';
import {BrowserModule, DOCUMENT, Title} from '@angular/platform-browser';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {INITIAL_CONFIG, PlatformState, ServerModule, platformDynamicServer, renderModule, renderModuleFactory} from '@angular/platform-server';
import {Subscription} from 'rxjs/Subscription';
@ -43,6 +43,16 @@ class MyServerApp2 {
class ExampleModule2 {
}
@Component({selector: 'app', template: ``})
class TitleApp {
constructor(private title: Title) {}
ngOnInit() { this.title.setTitle('Test App Title'); }
}
@NgModule({declarations: [TitleApp], imports: [ServerModule], bootstrap: [TitleApp]})
class TitleAppModule {
}
@Component({selector: 'app', template: '{{text}}'})
class MyAsyncServerApp {
text = '';
@ -145,6 +155,21 @@ export function main() {
});
}));
it('adds title to the document using Title service', async(() => {
const platform = platformDynamicServer([{
provide: INITIAL_CONFIG,
useValue:
{document: '<html><head><title></title></head><body><app></app></body></html>'}
}]);
platform.bootstrapModule(TitleAppModule).then(ref => {
const state = ref.injector.get(PlatformState);
const doc = ref.injector.get(DOCUMENT);
const title = getDOM().querySelector(doc, 'title');
expect(getDOM().getText(title)).toBe('Test App Title');
expect(state.renderToString()).toContain('<title>Test App Title</title>');
});
}));
it('adds styles with ng-transition attribute', async(() => {
const platform = platformDynamicServer([{
provide: INITIAL_CONFIG,