refactor(core): remove testing-only DOM manipulation utils from DomAdapters (#32291)
PR Close #32291
This commit is contained in:

committed by
Miško Hevery

parent
ede5786d1e
commit
30dabdf8fc
@ -15,7 +15,7 @@ import {ComponentRef} from '@angular/core/src/linker/component_factory';
|
||||
import {getLocaleId} from '@angular/core/src/render3';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
import {dispatchEvent, getContent} from '@angular/platform-browser/testing/src/browser_util';
|
||||
import {createTemplate, dispatchEvent, getContent} from '@angular/platform-browser/testing/src/browser_util';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
import {onlyInIvy} from '@angular/private/testing';
|
||||
|
||||
@ -35,7 +35,7 @@ class SomeComponent {
|
||||
function createRootEl(selector = 'bootstrap-app') {
|
||||
const doc = TestBed.get(DOCUMENT);
|
||||
const rootEl = <HTMLElement>getDOM().firstChild(
|
||||
getContent(getDOM().createTemplate(`<${selector}></${selector}>`)));
|
||||
getContent(createTemplate(`<${selector}></${selector}>`)));
|
||||
const oldRoots = getDOM().querySelectorAll(doc, selector);
|
||||
for (let i = 0; i < oldRoots.length; i++) {
|
||||
getDOM().remove(oldRoots[i]);
|
||||
|
@ -17,37 +17,6 @@ import {el, isTextNode, stringifyElement} from '@angular/platform-browser/testin
|
||||
defaultDoc = getDOM().supportsDOMEvents() ? document : getDOM().createHtmlDocument();
|
||||
});
|
||||
|
||||
it('should not coalesque text nodes', () => {
|
||||
const el1 = el('<div>a</div>');
|
||||
const el2 = el('<div>b</div>');
|
||||
getDOM().appendChild(el2, getDOM().firstChild(el1));
|
||||
expect(getDOM().childNodes(el2).length).toBe(2);
|
||||
|
||||
const el2Clone = getDOM().clone(el2);
|
||||
expect(getDOM().childNodes(el2Clone).length).toBe(2);
|
||||
});
|
||||
|
||||
it('should clone correctly', () => {
|
||||
const el1 = el('<div x="y">a<span>b</span></div>');
|
||||
const clone = getDOM().clone(el1);
|
||||
|
||||
expect(clone).not.toBe(el1);
|
||||
getDOM().setAttribute(clone, 'test', '1');
|
||||
expect(stringifyElement(clone)).toEqual('<div test="1" x="y">a<span>b</span></div>');
|
||||
expect(getDOM().getAttribute(el1, 'test')).toBeFalsy();
|
||||
|
||||
const cNodes = getDOM().childNodes(clone);
|
||||
const firstChild = cNodes[0];
|
||||
const secondChild = cNodes[1];
|
||||
expect(getDOM().parentElement(firstChild)).toBe(clone);
|
||||
expect(getDOM().nextSibling(firstChild)).toBe(secondChild);
|
||||
expect(isTextNode(firstChild)).toBe(true);
|
||||
|
||||
expect(getDOM().parentElement(secondChild)).toBe(clone);
|
||||
expect(getDOM().nextSibling(secondChild)).toBeFalsy();
|
||||
expect(getDOM().isElementNode(secondChild)).toBe(true);
|
||||
});
|
||||
|
||||
it('should be able to create text nodes and use them with the other APIs', () => {
|
||||
const t = getDOM().createTextNode('hello');
|
||||
expect(isTextNode(t)).toBe(true);
|
||||
|
@ -1006,8 +1006,8 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
getDOM().dispatchEvent(fixture.debugElement.children[1].nativeElement, dispatchedEvent2);
|
||||
expect(getDOM().isPrevented(dispatchedEvent)).toBe(true);
|
||||
expect(getDOM().isPrevented(dispatchedEvent2)).toBe(false);
|
||||
expect(getDOM().getChecked(fixture.debugElement.children[0].nativeElement)).toBeFalsy();
|
||||
expect(getDOM().getChecked(fixture.debugElement.children[1].nativeElement)).toBeTruthy();
|
||||
expect(fixture.debugElement.children[0].nativeElement.checked).toBeFalsy();
|
||||
expect(fixture.debugElement.children[1].nativeElement.checked).toBeTruthy();
|
||||
});
|
||||
}
|
||||
|
||||
@ -2689,15 +2689,14 @@ class ComponentWithoutView {
|
||||
@Directive({selector: '[no-duplicate]'})
|
||||
class DuplicateDir {
|
||||
constructor(elRef: ElementRef) {
|
||||
getDOM().setText(elRef.nativeElement, getDOM().getText(elRef.nativeElement) + 'noduplicate');
|
||||
getDOM().setText(elRef.nativeElement, elRef.nativeElement.textContent + 'noduplicate');
|
||||
}
|
||||
}
|
||||
|
||||
@Directive({selector: '[no-duplicate]'})
|
||||
class OtherDuplicateDir {
|
||||
constructor(elRef: ElementRef) {
|
||||
getDOM().setText(
|
||||
elRef.nativeElement, getDOM().getText(elRef.nativeElement) + 'othernoduplicate');
|
||||
getDOM().setText(elRef.nativeElement, elRef.nativeElement.textContent + 'othernoduplicate');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, compViewDef, createAndGetRoot
|
||||
it('should create text nodes without parents', () => {
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([textDef(0, null, ['a'])])).rootNodes;
|
||||
expect(rootNodes.length).toBe(1);
|
||||
expect(getDOM().getText(rootNodes[0])).toBe('a');
|
||||
expect(rootNodes[0].textContent).toBe('a');
|
||||
});
|
||||
|
||||
it('should create views with multiple root text nodes', () => {
|
||||
@ -36,8 +36,8 @@ import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, compViewDef, createAndGetRoot
|
||||
textDef(1, null, ['a']),
|
||||
])).rootNodes;
|
||||
expect(rootNodes.length).toBe(1);
|
||||
const textNode = getDOM().firstChild(rootNodes[0]);
|
||||
expect(getDOM().getText(textNode)).toBe('a');
|
||||
const textNode = getDOM().firstChild(rootNodes[0]) as Element;
|
||||
expect(textNode.textContent).toBe('a');
|
||||
});
|
||||
|
||||
it('should add debug information to the renderer', () => {
|
||||
@ -61,7 +61,7 @@ import {ARG_TYPE_VALUES, checkNodeInlineOrDynamic, compViewDef, createAndGetRoot
|
||||
|
||||
Services.checkAndUpdateView(view);
|
||||
|
||||
expect(getDOM().getText(rootNodes[0])).toBe('0a1b2');
|
||||
expect(rootNodes[0].textContent).toBe('0a1b2');
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user