refactor(core): remove testing-only style utils from DomAdapters (#32291)

PR Close #32291
This commit is contained in:
Kara Erickson
2019-08-23 12:32:00 -07:00
committed by Miško Hevery
parent 46caf88b2c
commit ede5786d1e
14 changed files with 63 additions and 75 deletions

View File

@ -13,6 +13,7 @@ import {TestBed, fakeAsync, flushMicrotasks} from '@angular/core/testing';
import {ɵDomRendererFactory2} from '@angular/platform-browser';
import {ANIMATION_MODULE_TYPE, BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {hasStyle} from '@angular/platform-browser/testing/src/browser_util';
import {ivyEnabled, modifiedInIvy} from '@angular/private/testing';
const DEFAULT_NAMESPACE_ID = 'id';
@ -1446,8 +1447,7 @@ const DEFAULT_COMPONENT_ID = '1';
const player = engine.players.pop();
player.finish();
expect(getDOM().hasStyle(cmp.element.nativeElement, 'background-color', 'green'))
.toBeTruthy();
expect(hasStyle(cmp.element.nativeElement, 'background-color', 'green')).toBeTruthy();
});
it('should retain state styles when the underlying DOM structure changes even if there are no insert/remove animations',
@ -2039,7 +2039,7 @@ const DEFAULT_COMPONENT_ID = '1';
player.finish();
flushMicrotasks();
expect(getDOM().hasStyle(element, 'color', 'red')).toBeTruthy();
expect(hasStyle(element, 'color', 'red')).toBeTruthy();
cmp.exp = '1';
cmp.color = 'blue';
@ -2047,7 +2047,7 @@ const DEFAULT_COMPONENT_ID = '1';
resetLog();
flushMicrotasks();
expect(getDOM().hasStyle(element, 'color', 'blue')).toBeTruthy();
expect(hasStyle(element, 'color', 'blue')).toBeTruthy();
cmp.exp = '1';
cmp.color = null;
@ -2055,7 +2055,7 @@ const DEFAULT_COMPONENT_ID = '1';
resetLog();
flushMicrotasks();
expect(getDOM().hasStyle(element, 'color', 'black')).toBeTruthy();
expect(hasStyle(element, 'color', 'black')).toBeTruthy();
}));
it('should substitute in values if the provided state match is an object with values', () => {
@ -2157,9 +2157,9 @@ const DEFAULT_COMPONENT_ID = '1';
p1.finish();
flushMicrotasks();
expect(getDOM().hasStyle(element, 'color', 'blue')).toBeTruthy();
expect(getDOM().hasStyle(element, 'fontSize', '50px')).toBeTruthy();
expect(getDOM().hasStyle(element, 'width', '888px')).toBeTruthy();
expect(hasStyle(element, 'color', 'blue')).toBeTruthy();
expect(hasStyle(element, 'fontSize', '50px')).toBeTruthy();
expect(hasStyle(element, 'width', '888px')).toBeTruthy();
}));
it('should only evaluate final state param substitutions from the expression and state values and not from the transition options ',
@ -2223,8 +2223,8 @@ const DEFAULT_COMPONENT_ID = '1';
p1.finish();
flushMicrotasks();
expect(getDOM().hasStyle(element, 'width', '100px')).toBeTruthy();
expect(getDOM().hasStyle(element, 'height', '100px')).toBeTruthy();
expect(hasStyle(element, 'width', '100px')).toBeTruthy();
expect(hasStyle(element, 'height', '100px')).toBeTruthy();
}));
it('should not flush animations twice when an inner component runs change detection', () => {

View File

@ -12,6 +12,7 @@ import {Component, DebugNode, Directive, ElementRef, EmbeddedViewRef, EventEmitt
import {ComponentFixture, TestBed, async} from '@angular/core/testing';
import {By} from '@angular/platform-browser/src/dom/debug/by';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {hasClass} from '@angular/platform-browser/testing/src/browser_util';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {ivyEnabled} from '@angular/private/testing';
@ -254,24 +255,24 @@ class TestCmptWithPropBindings {
// The root component has 3 elements in its view.
expect(childEls.length).toEqual(3);
expect(getDOM().hasClass(childEls[0].nativeElement, 'parent')).toBe(true);
expect(getDOM().hasClass(childEls[1].nativeElement, 'parent')).toBe(true);
expect(getDOM().hasClass(childEls[2].nativeElement, 'child-comp-class')).toBe(true);
expect(hasClass(childEls[0].nativeElement, 'parent')).toBe(true);
expect(hasClass(childEls[1].nativeElement, 'parent')).toBe(true);
expect(hasClass(childEls[2].nativeElement, 'child-comp-class')).toBe(true);
const nested = childEls[0].children;
expect(nested.length).toEqual(1);
expect(getDOM().hasClass(nested[0].nativeElement, 'parentnested')).toBe(true);
expect(hasClass(nested[0].nativeElement, 'parentnested')).toBe(true);
const childComponent = childEls[2];
const childCompChildren = childComponent.children;
expect(childCompChildren.length).toEqual(2);
expect(getDOM().hasClass(childCompChildren[0].nativeElement, 'child')).toBe(true);
expect(getDOM().hasClass(childCompChildren[1].nativeElement, 'child')).toBe(true);
expect(hasClass(childCompChildren[0].nativeElement, 'child')).toBe(true);
expect(hasClass(childCompChildren[1].nativeElement, 'child')).toBe(true);
const childNested = childCompChildren[0].children;
expect(childNested.length).toEqual(1);
expect(getDOM().hasClass(childNested[0].nativeElement, 'childnested')).toBe(true);
expect(hasClass(childNested[0].nativeElement, 'childnested')).toBe(true);
});
it('should list conditional component child elements', () => {
@ -282,8 +283,8 @@ class TestCmptWithPropBindings {
// The root component has 2 elements in its view.
expect(childEls.length).toEqual(2);
expect(getDOM().hasClass(childEls[0].nativeElement, 'parent')).toBe(true);
expect(getDOM().hasClass(childEls[1].nativeElement, 'cond-content-comp-class')).toBe(true);
expect(hasClass(childEls[0].nativeElement, 'parent')).toBe(true);
expect(hasClass(childEls[1].nativeElement, 'cond-content-comp-class')).toBe(true);
const conditionalContentComp = childEls[1];
@ -353,7 +354,7 @@ class TestCmptWithPropBindings {
const childTestEls = fixture.debugElement.queryAll(By.css('child-comp'));
expect(childTestEls.length).toBe(1);
expect(getDOM().hasClass(childTestEls[0].nativeElement, 'child-comp-class')).toBe(true);
expect(hasClass(childTestEls[0].nativeElement, 'child-comp-class')).toBe(true);
});
it('should query child elements by directive', () => {
@ -363,10 +364,10 @@ class TestCmptWithPropBindings {
const childTestEls = fixture.debugElement.queryAll(By.directive(MessageDir));
expect(childTestEls.length).toBe(4);
expect(getDOM().hasClass(childTestEls[0].nativeElement, 'parent')).toBe(true);
expect(getDOM().hasClass(childTestEls[1].nativeElement, 'parentnested')).toBe(true);
expect(getDOM().hasClass(childTestEls[2].nativeElement, 'child')).toBe(true);
expect(getDOM().hasClass(childTestEls[3].nativeElement, 'childnested')).toBe(true);
expect(hasClass(childTestEls[0].nativeElement, 'parent')).toBe(true);
expect(hasClass(childTestEls[1].nativeElement, 'parentnested')).toBe(true);
expect(hasClass(childTestEls[2].nativeElement, 'child')).toBe(true);
expect(hasClass(childTestEls[3].nativeElement, 'childnested')).toBe(true);
});
it('should query projected child elements by directive', () => {

View File

@ -139,8 +139,8 @@ const removeEventListener = '__zone_symbol__removeEventListener' as 'removeEvent
Services.checkAndUpdateView(view);
const el = rootNodes[0];
expect(getDOM().hasClass(el, 'c1')).toBeTruthy();
expect(getDOM().hasClass(el, 'c2')).toBeTruthy();
expect(el.classList.contains('c1')).toBeTruthy();
expect(el.classList.contains('c2')).toBeTruthy();
});
});
});