2017-01-20 16:10:57 -05: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-02-01 14:32:27 -05:00
|
|
|
import {Injector, RenderComponentType, RootRenderer, Sanitizer, SecurityContext, ViewEncapsulation, WrappedValue, getDebugNode} from '@angular/core';
|
2017-02-03 18:20:50 -05:00
|
|
|
import {ArgumentType, DebugContext, NodeDef, NodeFlags, RootData, Services, ViewData, ViewDefinition, ViewFlags, ViewHandleEventFn, ViewUpdateFn, anchorDef, asTextData, elementDef, rootRenderNodes, textDef, viewDef} from '@angular/core/src/view/index';
|
2017-01-20 16:10:57 -05:00
|
|
|
import {inject} from '@angular/core/testing';
|
|
|
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, createRootView, isBrowser} from './helper';
|
2017-01-20 16:10:57 -05:00
|
|
|
|
|
|
|
export function main() {
|
2017-02-03 18:20:50 -05:00
|
|
|
describe(`View Text`, () => {
|
2017-01-19 13:25:03 -05:00
|
|
|
function compViewDef(
|
2017-02-09 17:59:57 -05:00
|
|
|
nodes: NodeDef[], updateDirectives?: ViewUpdateFn, updateRenderer?: ViewUpdateFn,
|
2017-02-20 15:15:03 -05:00
|
|
|
viewFlags: ViewFlags = ViewFlags.None): ViewDefinition {
|
|
|
|
return viewDef(viewFlags, nodes, updateDirectives, updateRenderer);
|
2017-01-20 16:10:57 -05:00
|
|
|
}
|
|
|
|
|
2017-01-26 20:07:37 -05:00
|
|
|
function createAndGetRootNodes(
|
|
|
|
viewDef: ViewDefinition, context?: any): {rootNodes: any[], view: ViewData} {
|
2017-02-03 18:20:50 -05:00
|
|
|
const view = createRootView(viewDef, context);
|
2017-01-20 16:10:57 -05:00
|
|
|
const rootNodes = rootRenderNodes(view);
|
|
|
|
return {rootNodes, view};
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('create', () => {
|
|
|
|
it('should create text nodes without parents', () => {
|
2017-01-31 11:51:42 -05:00
|
|
|
const rootNodes = createAndGetRootNodes(compViewDef([textDef(null, ['a'])])).rootNodes;
|
2017-01-20 16:10:57 -05:00
|
|
|
expect(rootNodes.length).toBe(1);
|
|
|
|
expect(getDOM().getText(rootNodes[0])).toBe('a');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create views with multiple root text nodes', () => {
|
2017-01-31 11:51:42 -05:00
|
|
|
const rootNodes = createAndGetRootNodes(compViewDef([
|
|
|
|
textDef(null, ['a']), textDef(null, ['b'])
|
|
|
|
])).rootNodes;
|
2017-01-20 16:10:57 -05:00
|
|
|
expect(rootNodes.length).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create text nodes with parents', () => {
|
|
|
|
const rootNodes = createAndGetRootNodes(compViewDef([
|
2017-01-31 11:51:42 -05:00
|
|
|
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
|
|
|
textDef(null, ['a']),
|
2017-01-20 16:10:57 -05:00
|
|
|
])).rootNodes;
|
|
|
|
expect(rootNodes.length).toBe(1);
|
|
|
|
const textNode = getDOM().firstChild(rootNodes[0]);
|
|
|
|
expect(getDOM().getText(textNode)).toBe('a');
|
|
|
|
});
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
it('should add debug information to the renderer', () => {
|
|
|
|
const someContext = new Object();
|
|
|
|
const {view, rootNodes} =
|
|
|
|
createAndGetRootNodes(compViewDef([textDef(null, ['a'])]), someContext);
|
|
|
|
expect(getDebugNode(rootNodes[0]).nativeNode).toBe(asTextData(view, 0).renderText);
|
|
|
|
});
|
2017-01-20 16:10:57 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('change text', () => {
|
2017-02-03 18:20:50 -05:00
|
|
|
ARG_TYPE_VALUES.forEach((inlineDynamic) => {
|
2017-02-27 12:14:18 -05:00
|
|
|
it(`should update via strategy ${inlineDynamic}`, () => {
|
2017-01-20 16:10:57 -05:00
|
|
|
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
|
|
|
[
|
2017-01-31 11:51:42 -05:00
|
|
|
textDef(null, ['0', '1', '2']),
|
2017-01-20 16:10:57 -05:00
|
|
|
],
|
2017-02-09 17:59:57 -05:00
|
|
|
null, (check, view) => {
|
2017-02-03 18:20:50 -05:00
|
|
|
checkNodeInlineOrDynamic(check, view, 0, inlineDynamic, ['a', 'b']);
|
2017-01-26 20:07:37 -05:00
|
|
|
}));
|
2017-01-20 16:10:57 -05:00
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
Services.checkAndUpdateView(view);
|
2017-01-20 16:10:57 -05:00
|
|
|
|
|
|
|
const node = rootNodes[0];
|
|
|
|
expect(getDOM().getText(rootNodes[0])).toBe('0a1b2');
|
|
|
|
});
|
2017-01-31 14:08:29 -05:00
|
|
|
|
2017-01-20 16:10:57 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|