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
|
|
|
|
*/
|
|
|
|
|
2019-08-22 22:16:25 -04:00
|
|
|
import {ɵgetDOM as getDOM} from '@angular/common';
|
2017-03-02 15:12:46 -05:00
|
|
|
import {beforeEach, describe, it} from '@angular/core/testing/src/testing_internal';
|
2016-04-28 20:50:03 -04:00
|
|
|
import {DomSharedStylesHost} from '@angular/platform-browser/src/dom/shared_styles_host';
|
2017-03-02 15:12:46 -05:00
|
|
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
2015-07-24 18:28:44 -04:00
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2015-07-24 18:28:44 -04:00
|
|
|
describe('DomSharedStylesHost', () => {
|
2017-01-02 05:20:32 -05:00
|
|
|
let doc: Document;
|
2016-11-12 08:08:58 -05:00
|
|
|
let ssh: DomSharedStylesHost;
|
|
|
|
let someHost: Element;
|
2015-07-24 18:28:44 -04:00
|
|
|
beforeEach(() => {
|
2016-04-28 20:50:03 -04:00
|
|
|
doc = getDOM().createHtmlDocument();
|
2015-07-24 18:28:44 -04:00
|
|
|
doc.title = '';
|
|
|
|
ssh = new DomSharedStylesHost(doc);
|
2016-04-28 20:50:03 -04:00
|
|
|
someHost = getDOM().createElement('div');
|
2015-07-24 18:28:44 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should add existing styles to new hosts', () => {
|
|
|
|
ssh.addStyles(['a {};']);
|
|
|
|
ssh.addHost(someHost);
|
2019-08-22 17:14:36 -04:00
|
|
|
expect(someHost.innerHTML).toEqual('<style>a {};</style>');
|
2015-07-24 18:28:44 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should add new styles to hosts', () => {
|
|
|
|
ssh.addHost(someHost);
|
|
|
|
ssh.addStyles(['a {};']);
|
2019-08-22 17:14:36 -04:00
|
|
|
expect(someHost.innerHTML).toEqual('<style>a {};</style>');
|
2015-07-24 18:28:44 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should add styles only once to hosts', () => {
|
|
|
|
ssh.addStyles(['a {};']);
|
|
|
|
ssh.addHost(someHost);
|
|
|
|
ssh.addStyles(['a {};']);
|
2019-08-22 17:14:36 -04:00
|
|
|
expect(someHost.innerHTML).toEqual('<style>a {};</style>');
|
2015-07-24 18:28:44 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should use the document head as default host', () => {
|
|
|
|
ssh.addStyles(['a {};', 'b {};']);
|
|
|
|
expect(doc.head).toHaveText('a {};b {};');
|
|
|
|
});
|
2017-01-02 07:42:05 -05:00
|
|
|
|
|
|
|
it('should remove style nodes on destroy', () => {
|
|
|
|
ssh.addStyles(['a {};']);
|
|
|
|
ssh.addHost(someHost);
|
2019-08-22 17:14:36 -04:00
|
|
|
expect(someHost.innerHTML).toEqual('<style>a {};</style>');
|
2017-01-02 07:42:05 -05:00
|
|
|
|
|
|
|
ssh.ngOnDestroy();
|
2019-08-22 17:14:36 -04:00
|
|
|
expect(someHost.innerHTML).toEqual('');
|
2017-01-02 07:42:05 -05:00
|
|
|
});
|
2015-07-24 18:28:44 -04:00
|
|
|
});
|
2015-10-02 12:30:36 -04:00
|
|
|
}
|