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
|
|
|
|
*/
|
|
|
|
|
2019-08-22 22:16:25 -04:00
|
|
|
import {ɵgetDOM as getDOM} from '@angular/common';
|
2017-09-22 17:29:16 -04:00
|
|
|
import {getDebugNode} from '@angular/core';
|
|
|
|
import {NodeFlags, Services, asTextData, elementDef, textDef} from '@angular/core/src/view/index';
|
2017-01-20 16:10:57 -05:00
|
|
|
|
2017-09-22 17:29:16 -04:00
|
|
|
import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, compViewDef, createAndGetRootNodes} from './helper';
|
2017-01-20 16:10:57 -05:00
|
|
|
|
2017-12-15 19:28:41 -05:00
|
|
|
{
|
2017-02-03 18:20:50 -05:00
|
|
|
describe(`View Text`, () => {
|
2017-01-20 16:10:57 -05:00
|
|
|
|
|
|
|
describe('create', () => {
|
|
|
|
it('should create text nodes without parents', () => {
|
2017-09-22 17:29:16 -04:00
|
|
|
const rootNodes = createAndGetRootNodes(compViewDef([textDef(0, null, ['a'])])).rootNodes;
|
2017-01-20 16:10:57 -05:00
|
|
|
expect(rootNodes.length).toBe(1);
|
2019-08-23 16:28:33 -04:00
|
|
|
expect(rootNodes[0].textContent).toBe('a');
|
2017-01-20 16:10:57 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should create views with multiple root text nodes', () => {
|
2017-01-31 11:51:42 -05:00
|
|
|
const rootNodes = createAndGetRootNodes(compViewDef([
|
2017-09-22 17:29:16 -04:00
|
|
|
textDef(0, null, ['a']),
|
|
|
|
textDef(1, null, ['b']),
|
2017-01-31 11:51:42 -05:00
|
|
|
])).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-09-22 17:29:16 -04:00
|
|
|
elementDef(0, NodeFlags.None, null, null, 1, 'div'),
|
|
|
|
textDef(1, null, ['a']),
|
2017-01-20 16:10:57 -05:00
|
|
|
])).rootNodes;
|
|
|
|
expect(rootNodes.length).toBe(1);
|
2019-08-24 11:01:24 -04:00
|
|
|
const textNode = rootNodes[0].firstChild;
|
2019-08-23 16:28:33 -04:00
|
|
|
expect(textNode.textContent).toBe('a');
|
2017-01-20 16:10:57 -05:00
|
|
|
});
|
|
|
|
|
2017-02-03 18:20:50 -05:00
|
|
|
it('should add debug information to the renderer', () => {
|
|
|
|
const someContext = new Object();
|
|
|
|
const {view, rootNodes} =
|
2017-09-22 17:29:16 -04:00
|
|
|
createAndGetRootNodes(compViewDef([textDef(0, null, ['a'])]), someContext);
|
2017-03-29 12:34:45 -04:00
|
|
|
expect(getDebugNode(rootNodes[0]) !.nativeNode).toBe(asTextData(view, 0).renderText);
|
2017-02-03 18:20:50 -05:00
|
|
|
});
|
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-09-22 17:29:16 -04:00
|
|
|
textDef(0, null, ['0', '1', '2']),
|
2017-01-20 16:10:57 -05:00
|
|
|
],
|
2017-03-29 12:34:45 -04: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
|
|
|
|
2019-08-23 16:28:33 -04:00
|
|
|
expect(rootNodes[0].textContent).toBe('0a1b2');
|
2017-01-20 16:10:57 -05:00
|
|
|
});
|
2017-01-31 14:08:29 -05:00
|
|
|
|
2017-01-20 16:10:57 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|