2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-09-14 16:21:23 -04:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {TestBed} from '@angular/core/testing';
|
|
|
|
import {BrowserModule, Title} from '@angular/platform-browser';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
2017-03-02 15:12:46 -05:00
|
|
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
2015-03-09 12:39:18 -04:00
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2015-03-09 12:39:18 -04:00
|
|
|
describe('title service', () => {
|
2017-08-08 05:17:40 -04:00
|
|
|
let doc: Document;
|
|
|
|
let initialTitle: string;
|
|
|
|
let titleService: Title;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
doc = getDOM().createHtmlDocument();
|
|
|
|
initialTitle = getDOM().getTitle(doc);
|
|
|
|
titleService = new Title(doc);
|
|
|
|
});
|
2015-03-09 12:39:18 -04:00
|
|
|
|
2017-02-14 19:14:40 -05:00
|
|
|
afterEach(() => { getDOM().setTitle(doc, initialTitle); });
|
2015-03-09 12:39:18 -04:00
|
|
|
|
2015-05-27 16:48:24 -04:00
|
|
|
it('should allow reading initial title',
|
|
|
|
() => { expect(titleService.getTitle()).toEqual(initialTitle); });
|
2015-03-09 12:39:18 -04:00
|
|
|
|
|
|
|
it('should set a title on the injected document', () => {
|
|
|
|
titleService.setTitle('test title');
|
2017-02-14 19:14:40 -05:00
|
|
|
expect(getDOM().getTitle(doc)).toEqual('test title');
|
2015-03-09 12:39:18 -04:00
|
|
|
expect(titleService.getTitle()).toEqual('test title');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should reset title to empty string if title not provided', () => {
|
2017-03-24 12:59:41 -04:00
|
|
|
titleService.setTitle(null !);
|
2017-02-14 19:14:40 -05:00
|
|
|
expect(getDOM().getTitle(doc)).toEqual('');
|
2015-03-09 12:39:18 -04:00
|
|
|
});
|
2016-09-14 16:21:23 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('integration test', () => {
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
class DependsOnTitle {
|
|
|
|
constructor(public title: Title) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
TestBed.configureTestingModule({
|
|
|
|
imports: [BrowserModule],
|
|
|
|
providers: [DependsOnTitle],
|
|
|
|
});
|
|
|
|
});
|
2015-03-09 12:39:18 -04:00
|
|
|
|
2016-09-14 16:21:23 -04:00
|
|
|
it('should inject Title service when using BrowserModule',
|
|
|
|
() => { expect(TestBed.get(DependsOnTitle).title).toBeAnInstanceOf(Title); });
|
2015-03-09 12:39:18 -04:00
|
|
|
});
|
|
|
|
}
|