2017-01-20 13:10:57 -08: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-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {ErrorHandler, SecurityContext, getDebugNode} from '@angular/core';
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-27 13:19:00 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {getDebugContext} from '@angular/core/src/errors';
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {BindingFlags, NodeFlags, Services, ViewData, ViewDefinition, asElementData, elementDef} from '@angular/core/src/view/index';
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-28 11:50:45 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {TestBed} from '@angular/core/testing';
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import {ARG_TYPE_VALUES, callMostRecentEventListenerHandler, checkNodeInlineOrDynamic, compViewDef, createAndGetRootNodes, isBrowser, recordNodeToRemove} from './helper';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-31 15:52:51 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-13 15:36:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								/**
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * We map addEventListener to the Zones internal name. This is because we want to be fast
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 * and bypass the zone bookkeeping. We know that we can do the bookkeeping faster.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								 */
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-24 14:54:08 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const addEventListener = '__zone_symbol__addEventListener' as 'addEventListener';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const removeEventListener = '__zone_symbol__removeEventListener' as 'removeEventListener';
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-13 15:36:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-12-15 16:28:41 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  describe(`View Elements`, () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe('create', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it('should create elements without parents', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-23 16:59:20 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const rootNodes = createAndGetRootNodes(compViewDef([
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                            elementDef(0, NodeFlags.None, null, null, 0, 'span')
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-23 16:59:20 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                          ])).rootNodes;
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(rootNodes.length).toBe(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(getDOM().nodeName(rootNodes[0]).toLowerCase()).toBe('span');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it('should create views with multiple root elements', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-23 16:59:20 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const rootNodes = createAndGetRootNodes(compViewDef([
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                            elementDef(0, NodeFlags.None, null, null, 0, 'span'),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            elementDef(1, NodeFlags.None, null, null, 0, 'span'),
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-23 16:59:20 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                          ])).rootNodes;
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(rootNodes.length).toBe(2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it('should create elements with parents', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootNodes = createAndGetRootNodes(compViewDef([
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                            elementDef(0, NodeFlags.None, null, null, 1, 'div'),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                            elementDef(1, NodeFlags.None, null, null, 0, 'span'),
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                          ])).rootNodes;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(rootNodes.length).toBe(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const spanEl = getDOM().childNodes(rootNodes[0])[0];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(getDOM().nodeName(spanEl).toLowerCase()).toBe('span');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it('should set fixed attributes', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const rootNodes = createAndGetRootNodes(compViewDef([
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                            elementDef(0, NodeFlags.None, null, null, 0, 'div', [['title', 'a']]),
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                          ])).rootNodes;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(rootNodes.length).toBe(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        expect(getDOM().getAttribute(rootNodes[0], 'title')).toBe('a');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      it('should add debug information to the renderer', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const someContext = new Object();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const {view, rootNodes} = createAndGetRootNodes(
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            compViewDef([elementDef(0, NodeFlags.None, null, null, 0, 'div')]), someContext);
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(getDebugNode(rootNodes[0]) !.nativeNode).toBe(asElementData(view, 0).renderElement);
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe('change properties', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      ARG_TYPE_VALUES.forEach((inlineDynamic) => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-27 09:14:18 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it(`should update via strategy ${inlineDynamic}`, () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const {view, rootNodes} = createAndGetRootNodes(compViewDef(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                elementDef(
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    0, NodeFlags.None, null, null, 0, 'input', null,
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    [
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-17 09:23:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      [BindingFlags.TypeProperty, 'title', SecurityContext.NONE],
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      [BindingFlags.TypeProperty, 'value', SecurityContext.NONE],
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    ]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              ],
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              null, (check, view) => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                checkNodeInlineOrDynamic(check, view, 0, inlineDynamic, ['v1', 'v2']);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-26 17:07:37 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              }));
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          Services.checkAndUpdateView(view);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const el = rootNodes[0];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(getDOM().getProperty(el, 'title')).toBe('v1');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(getDOM().getProperty(el, 'value')).toBe('v2');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe('change attributes', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      ARG_TYPE_VALUES.forEach((inlineDynamic) => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-27 09:14:18 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it(`should update via strategy ${inlineDynamic}`, () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const {view, rootNodes} = createAndGetRootNodes(compViewDef(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                elementDef(
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    0, NodeFlags.None, null, null, 0, 'div', null,
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    [
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-17 09:23:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      [BindingFlags.TypeElementAttribute, 'a1', SecurityContext.NONE],
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      [BindingFlags.TypeElementAttribute, 'a2', SecurityContext.NONE],
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    ]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              ],
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              null, (check, view) => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                checkNodeInlineOrDynamic(check, view, 0, inlineDynamic, ['v1', 'v2']);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-26 17:07:37 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              }));
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          Services.checkAndUpdateView(view);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const el = rootNodes[0];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(getDOM().getAttribute(el, 'a1')).toBe('v1');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(getDOM().getAttribute(el, 'a2')).toBe('v2');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe('change classes', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      ARG_TYPE_VALUES.forEach((inlineDynamic) => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-27 09:14:18 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it(`should update via strategy ${inlineDynamic}`, () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const {view, rootNodes} = createAndGetRootNodes(compViewDef(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                elementDef(
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    0, NodeFlags.None, null, null, 0, 'div', null,
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-17 09:23:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    [
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      [BindingFlags.TypeElementClass, 'c1', null],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                      [BindingFlags.TypeElementClass, 'c2', null],
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-17 09:23:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    ]),
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              ],
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              (check, view) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                checkNodeInlineOrDynamic(check, view, 0, inlineDynamic, [true, true]);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-26 17:07:37 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              }));
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          Services.checkAndUpdateView(view);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const el = rootNodes[0];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(getDOM().hasClass(el, 'c1')).toBeTruthy();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(getDOM().hasClass(el, 'c2')).toBeTruthy();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    describe('change styles', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      ARG_TYPE_VALUES.forEach((inlineDynamic) => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-27 09:14:18 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it(`should update via strategy ${inlineDynamic}`, () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const {view, rootNodes} = createAndGetRootNodes(compViewDef(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                elementDef(
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                    0, NodeFlags.None, null, null, 0, 'div', null,
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    [
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-17 09:23:28 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      [BindingFlags.TypeElementStyle, 'width', 'px'],
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                      [BindingFlags.TypeElementStyle, 'color', null],
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    ]),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              ],
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              null, (check, view) => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                checkNodeInlineOrDynamic(check, view, 0, inlineDynamic, [10, 'red']);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-26 17:07:37 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              }));
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          Services.checkAndUpdateView(view);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const el = rootNodes[0];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(getDOM().getStyle(el, 'width')).toBe('10px');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(getDOM().getStyle(el, 'color')).toBe('red');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-31 14:52:01 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if (isBrowser()) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      describe('listen to DOM events', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        function createAndAttachAndGetRootNodes(viewDef: ViewDefinition):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            {rootNodes: any[], view: ViewData} {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const result = createAndGetRootNodes(viewDef);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          // Note: We need to append the node to the document.body, otherwise `click` events
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          // won't work in IE.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          result.rootNodes.forEach((node) => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            document.body.appendChild(node);
							 | 
						
					
						
							
								
									
										
										
										
											2017-05-16 13:29:38 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            recordNodeToRemove(node);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          return result;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        it('should listen to DOM events', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const handleEventSpy = jasmine.createSpy('handleEvent');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const removeListenerSpy =
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-13 15:36:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              spyOn(HTMLElement.prototype, removeEventListener).and.callThrough();
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-20 12:15:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          const {view, rootNodes} = createAndAttachAndGetRootNodes(compViewDef([elementDef(
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              0, NodeFlags.None, null, null, 0, 'button', null, null, [[null !, 'click']],
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-21 13:56:56 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              handleEventSpy)]));
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          rootNodes[0].click();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventSpy).toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          let handleEventArgs = handleEventSpy.calls.mostRecent().args;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventArgs[0]).toBe(view);
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-20 12:15:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventArgs[1]).toBe('click');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventArgs[2]).toBeTruthy();
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          Services.destroyView(view);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(removeListenerSpy).toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        it('should listen to window events', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const handleEventSpy = jasmine.createSpy('handleEvent');
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-13 15:36:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          const addListenerSpy = spyOn(window, addEventListener);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const removeListenerSpy = spyOn(window, removeEventListener);
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-20 12:15:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          const {view, rootNodes} = createAndAttachAndGetRootNodes(compViewDef([elementDef(
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              0, NodeFlags.None, null, null, 0, 'button', null, null, [['window', 'windowClick']],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              handleEventSpy)]));
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(addListenerSpy).toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(addListenerSpy.calls.mostRecent().args[0]).toBe('windowClick');
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-31 15:52:51 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          callMostRecentEventListenerHandler(addListenerSpy, {name: 'windowClick'});
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventSpy).toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const handleEventArgs = handleEventSpy.calls.mostRecent().args;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventArgs[0]).toBe(view);
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-20 12:15:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventArgs[1]).toBe('window:windowClick');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventArgs[2]).toBeTruthy();
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          Services.destroyView(view);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(removeListenerSpy).toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        it('should listen to document events', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const handleEventSpy = jasmine.createSpy('handleEvent');
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-13 15:36:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          const addListenerSpy = spyOn(document, addEventListener);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const removeListenerSpy = spyOn(document, removeEventListener);
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-20 12:15:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          const {view, rootNodes} = createAndAttachAndGetRootNodes(compViewDef([elementDef(
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              0, NodeFlags.None, null, null, 0, 'button', null, null,
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              [['document', 'documentClick']], handleEventSpy)]));
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(addListenerSpy).toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(addListenerSpy.calls.mostRecent().args[0]).toBe('documentClick');
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-31 15:52:51 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          callMostRecentEventListenerHandler(addListenerSpy, {name: 'windowClick'});
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventSpy).toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          const handleEventArgs = handleEventSpy.calls.mostRecent().args;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventArgs[0]).toBe(view);
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-20 12:15:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventArgs[1]).toBe('document:documentClick');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(handleEventArgs[2]).toBeTruthy();
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-03 15:20:50 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          Services.destroyView(view);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(removeListenerSpy).toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        it('should preventDefault only if the handler returns false', () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          let eventHandlerResult: any;
							 | 
						
					
						
							
								
									
										
										
										
											2017-03-29 09:34:45 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          let preventDefaultSpy: jasmine.Spy = undefined !;
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-20 12:15:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          const {view, rootNodes} = createAndAttachAndGetRootNodes(compViewDef([elementDef(
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              0, NodeFlags.None, null, null, 0, 'button', null, null, [[null !, 'click']],
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-20 12:15:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              (view, eventName, event) => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                preventDefaultSpy = spyOn(event, 'preventDefault').and.callThrough();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return eventHandlerResult;
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-20 12:15:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              })]));
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          eventHandlerResult = undefined;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          rootNodes[0].click();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(preventDefaultSpy).not.toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          eventHandlerResult = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          rootNodes[0].click();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(preventDefaultSpy).not.toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          eventHandlerResult = 'someString';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          rootNodes[0].click();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(preventDefaultSpy).not.toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          eventHandlerResult = false;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          rootNodes[0].click();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(preventDefaultSpy).toHaveBeenCalled();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-26 17:07:37 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        it('should report debug info on event errors', () => {
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-28 11:50:45 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          const handleErrorSpy = spyOn(TestBed.get(ErrorHandler), 'handleError');
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-13 15:36:11 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          const addListenerSpy = spyOn(HTMLElement.prototype, addEventListener).and.callThrough();
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-21 13:56:56 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          const {view, rootNodes} = createAndAttachAndGetRootNodes(compViewDef([elementDef(
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-22 14:29:16 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              0, NodeFlags.None, null, null, 0, 'button', null, null, [[null !, 'click']],
							 | 
						
					
						
							
								
									
										
										
										
											2017-02-21 13:56:56 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              () => { throw new Error('Test'); })]));
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-26 17:07:37 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-31 15:52:51 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          callMostRecentEventListenerHandler(addListenerSpy, 'SomeEvent');
							 | 
						
					
						
							
								
									
										
										
										
											2017-04-28 11:50:45 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          const err = handleErrorSpy.calls.mostRecent().args[0];
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-26 17:07:37 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          expect(err).toBeTruthy();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(err.message).toBe('Test');
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-27 13:19:00 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          const debugCtx = getDebugContext(err);
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-26 17:07:37 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								          expect(debugCtx.view).toBe(view);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								          expect(debugCtx.nodeIndex).toBe(0);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-19 10:25:03 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2017-01-20 13:10:57 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |