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