Skip to content

Commit e657b86

Browse files
authored
Merge pull request #6770 from IgniteUI/PMiteva/test-ivy-P3-9.0.x
Fix failing tests with Ivy - P3 - 9.0
2 parents 42e24d1 + dabf09b commit e657b86

File tree

3 files changed

+65
-29
lines changed

3 files changed

+65
-29
lines changed

projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,14 @@ describe('IgxAutocomplete', () => {
366366
const verifyDropdownItems = function() {
367367
expect(dropdownListScrollElement.children.length).toEqual(filteredTowns.length);
368368
for (let itemIndex = 0; itemIndex < filteredTowns.length; itemIndex++) {
369-
expect(dropdownListScrollElement.children[itemIndex].nativeElement.textContent.trim()).
369+
const itemElement = dropdownListScrollElement.children[itemIndex].nativeElement;
370+
expect(itemElement.textContent.trim()).
370371
toEqual(filteredTowns[itemIndex]);
371372
const isFocused = itemIndex === 0 ? true : false;
372-
expect(dropdownListScrollElement.children[itemIndex].classes[CSS_CLASS_DROP_DOWN_ITEM_FOCUSED]).toEqual(isFocused);
373+
const hasFocusedClass =
374+
itemElement.classList.contains(CSS_CLASS_DROP_DOWN_ITEM_FOCUSED);
375+
isFocused ? expect(hasFocusedClass).toBeTruthy() :
376+
expect(hasFocusedClass).toBeFalsy();
373377
expect(dropDown.items[itemIndex].focused).toEqual(isFocused);
374378
}
375379
};

projects/igniteui-angular/src/lib/services/overlay/overlay.spec.ts

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function getOverlayWrapperLocation(
147147
} else if (positionSettings.verticalStartPoint === VerticalAlignment.Middle) {
148148
location.y = Math.max(0, targetRect.top + targetRect.height / 2 - flipOffset);
149149
} else {
150-
location.y = Math.max(0, targetRect.top - flipOffset);
150+
location.y = Math.max(0, targetRect.top - flipOffset);
151151
}
152152
}
153153
} else if (location.y + wrapperRect.height > screenRect.bottom && !elastic) {
@@ -163,7 +163,23 @@ function getOverlayWrapperLocation(
163163
return location;
164164
}
165165

166+
/**
167+
* Formats a string according to the given formatters
168+
* @param inputString String to be formatted
169+
* @param formatters Each formatter should include regex expressions and replacements to be applied on the inputString
170+
*/
171+
function formatString(inputString: string, formatters: any[]) {
172+
formatters.forEach(function (formatter) {
173+
inputString = inputString.replace(formatter.pattern, formatter.replacement);
174+
});
175+
return inputString;
176+
}
177+
166178
describe('igxOverlay', () => {
179+
const formatters = [
180+
{pattern: /:\s/g, replacement: ':'},
181+
{pattern: /red;/, replacement: 'red'}
182+
];
167183
beforeEach(async(() => {
168184
UIInteractions.clearOverlay();
169185
}));
@@ -856,10 +872,10 @@ describe('igxOverlay', () => {
856872
spyOn(Util, 'getViewportRect').and.returnValue(viewPortRect);
857873
spyOn(Util, 'getTargetRect').and.returnValue(targetRect);
858874

859-
const element = jasmine.createSpyObj('HTMLElement', ['getBoundingClientRect'] );
875+
const element = jasmine.createSpyObj('HTMLElement', ['getBoundingClientRect']);
860876
spyOn(element, 'getBoundingClientRect').and.returnValue(elementRect);
861-
element.classList = { add: () => {} };
862-
element.style = { width: '', height: ''};
877+
element.classList = { add: () => { } };
878+
element.style = { width: '', height: '' };
863879
elastic.position(element, null, null, true);
864880

865881
expect(element.style.width).toBe('200px');
@@ -1678,8 +1694,9 @@ describe('igxOverlay', () => {
16781694
const wrappers = document.getElementsByClassName(CLASS_OVERLAY_CONTENT);
16791695
const wrapperContent = wrappers[wrappers.length - 1].lastElementChild; // wrapped in NG-COMPONENT
16801696
expect(wrapperContent.children.length).toEqual(1);
1681-
expect(wrapperContent.lastElementChild.getAttribute('style'))
1682-
.toEqual('width:100px; height: 100px; background-color: red');
1697+
let overlayStyle = wrapperContent.lastElementChild.getAttribute('style');
1698+
overlayStyle = formatString(overlayStyle, formatters);
1699+
expect(overlayStyle).toEqual('width:100px; height:100px; background-color:red');
16831700
}));
16841701

16851702
it('Should show the component inside of the viewport if it would normally be outside of bounds, BOTTOM + RIGHT.', fakeAsync(() => {
@@ -1702,8 +1719,10 @@ describe('igxOverlay', () => {
17021719
fix.detectChanges();
17031720
const wrappers = document.getElementsByClassName(CLASS_OVERLAY_CONTENT);
17041721
const wrapperContent = wrappers[wrappers.length - 1] as HTMLElement; // wrapped in NG-COMPONENT
1705-
const expectedStyle = 'width:100px; height: 100px; background-color: red';
1706-
expect(wrapperContent.lastElementChild.lastElementChild.getAttribute('style')).toEqual(expectedStyle);
1722+
const expectedStyle = 'width:100px; height:100px; background-color:red';
1723+
let overlayStyle = wrapperContent.lastElementChild.lastElementChild.getAttribute('style');
1724+
overlayStyle = formatString(overlayStyle, formatters);
1725+
expect(overlayStyle).toEqual(expectedStyle);
17071726
const buttonLeft = buttonElement.offsetLeft;
17081727
const buttonTop = buttonElement.offsetTop;
17091728
const expectedLeft = buttonLeft - wrapperContent.lastElementChild.lastElementChild.clientWidth;
@@ -2131,8 +2150,9 @@ describe('igxOverlay', () => {
21312150
const wrappers = document.getElementsByClassName(CLASS_OVERLAY_CONTENT);
21322151
const wrapperContent = wrappers[wrappers.length - 1].lastElementChild; // wrapped in NG-COMPONENT
21332152
expect(wrapperContent.children.length).toEqual(1);
2134-
expect(wrapperContent.lastElementChild.getAttribute('style'))
2135-
.toEqual('width:100px; height: 100px; background-color: red');
2153+
let overlayStyle = wrapperContent.lastElementChild.getAttribute('style');
2154+
overlayStyle = formatString(overlayStyle, formatters);
2155+
expect(overlayStyle).toEqual('width:100px; height:100px; background-color:red');
21362156
}));
21372157

21382158
it('Should show the component inside of the viewport if it would normally be outside of bounds, BOTTOM + RIGHT.', fakeAsync(() => {
@@ -2910,8 +2930,10 @@ describe('igxOverlay', () => {
29102930
fix.detectChanges();
29112931
const wrappers = document.getElementsByClassName(CLASS_OVERLAY_CONTENT);
29122932
const wrapperContent = wrappers[wrappers.length - 1] as HTMLElement;
2913-
const expectedStyle = 'width:100px; height: 100px; background-color: red';
2914-
expect(wrapperContent.lastElementChild.lastElementChild.getAttribute('style')).toEqual(expectedStyle);
2933+
const expectedStyle = 'width:100px; height:100px; background-color:red';
2934+
let overlayStyle = wrapperContent.lastElementChild.lastElementChild.getAttribute('style');
2935+
overlayStyle = formatString(overlayStyle, formatters);
2936+
expect(overlayStyle).toEqual(expectedStyle);
29152937
const buttonLeft = buttonElement.offsetLeft;
29162938
const buttonTop = buttonElement.offsetTop;
29172939
const expectedLeft = buttonLeft + buttonElement.clientWidth; // To the right of the button
@@ -2960,8 +2982,10 @@ describe('igxOverlay', () => {
29602982
fix.detectChanges();
29612983
const wrappers = document.getElementsByClassName(CLASS_OVERLAY_CONTENT);
29622984
const wrapperContent = wrappers[wrappers.length - 1] as HTMLElement;
2963-
const expectedStyle = 'width:100px; height: 100px; background-color: red';
2964-
expect(wrapperContent.lastElementChild.lastElementChild.getAttribute('style')).toEqual(expectedStyle);
2985+
const expectedStyle = 'width:100px; height:100px; background-color:red';
2986+
let overlayStyle = wrapperContent.lastElementChild.lastElementChild.getAttribute('style');
2987+
overlayStyle = formatString(overlayStyle, formatters);
2988+
expect(overlayStyle).toEqual(expectedStyle);
29652989
const buttonLeft = buttonElement.offsetLeft;
29662990
const buttonTop = buttonElement.offsetTop;
29672991
const expectedRight = buttonLeft; // To the left of the button
@@ -3009,8 +3033,10 @@ describe('igxOverlay', () => {
30093033
fix.detectChanges();
30103034
const wrappers = document.getElementsByClassName(CLASS_OVERLAY_CONTENT);
30113035
const contentElement = wrappers[wrappers.length - 1] as HTMLElement; // wrapper in NG-COMPONENT
3012-
const expectedStyle = 'width:100px; height: 100px; background-color: red';
3013-
expect(contentElement.lastElementChild.lastElementChild.getAttribute('style')).toEqual(expectedStyle);
3036+
const expectedStyle = 'width:100px; height:100px; background-color:red';
3037+
let overlayStyle = contentElement.lastElementChild.lastElementChild.getAttribute('style');
3038+
overlayStyle = formatString(overlayStyle, formatters);
3039+
expect(overlayStyle).toEqual(expectedStyle);
30143040
const expectedRight = buttonElement.offsetLeft;
30153041
const expectedTop = buttonElement.offsetTop + buttonElement.clientHeight;
30163042
const contentElementRect = contentElement.getBoundingClientRect();
@@ -3058,8 +3084,10 @@ describe('igxOverlay', () => {
30583084
fix.detectChanges();
30593085
const wrappers = document.getElementsByClassName(CLASS_OVERLAY_CONTENT);
30603086
const wrapperContent = wrappers[wrappers.length - 1] as HTMLElement;
3061-
const expectedStyle = 'width:100px; height: 100px; background-color: red';
3062-
expect(wrapperContent.lastElementChild.lastElementChild.getAttribute('style')).toEqual(expectedStyle);
3087+
const expectedStyle = 'width:100px; height:100px; background-color:red';
3088+
let overlayStyle = wrapperContent.lastElementChild.lastElementChild.getAttribute('style');
3089+
overlayStyle = formatString(overlayStyle, formatters);
3090+
expect(overlayStyle).toEqual(expectedStyle);
30633091
const buttonLeft = buttonElement.offsetLeft;
30643092
const buttonTop = buttonElement.offsetTop;
30653093
const expectedLeft = buttonLeft + buttonElement.clientWidth; // To the right of the button

projects/igniteui-angular/src/lib/time-picker/time-picker.component.spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,8 +1419,10 @@ describe('IgxTimePicker', () => {
14191419
UIInteractions.simulateWheelEvent(AMPMColumn.nativeElement, 0, -10);
14201420
fixture.detectChanges();
14211421

1422-
expect(AMPMColumn.children[0].nativeElement.innerText).toBe('AM');
1423-
expect(AMPMColumn.children[1].nativeElement.innerText).toBe('PM');
1422+
const AMIndicator = AMPMColumn.children.find(item => item.nativeElement.innerText === 'AM');
1423+
const PMIndicator = AMPMColumn.children.find(item => item.nativeElement.innerText === 'PM');
1424+
expect(AMIndicator).not.toBeUndefined();
1425+
expect(PMIndicator).not.toBeUndefined();
14241426

14251427
// expect input value to be changed
14261428
expect(input.nativeElement.value).toBe('04:50 AM');
@@ -1999,26 +2001,28 @@ describe('IgxTimePicker', () => {
19992001
// Bug #6025 Date picker does not disable in reactive form
20002002
it('Should disable when form is disabled', fakeAsync(() => {
20012003
fixture.detectChanges();
2004+
const mockClickEvent = new Event('click');
20022005
const formGroup: FormGroup = fixture.componentInstance.reactiveForm;
2003-
const timeIcon = fixture.debugElement.query(By.css('.igx-icon'));
2006+
let timeIcon = fixture.debugElement.query(By.css('.igx-icon'));
20042007

2005-
timeIcon.nativeElement.click();
2006-
tick();
2008+
timeIcon.triggerEventHandler('click', mockClickEvent);
20072009
fixture.detectChanges();
2008-
const timeDropDown = fixture.debugElement.query(By.css('.igx-time-picker--dropdown'));
2010+
let timeDropDown = fixture.debugElement.query(By.css('.igx-time-picker--dropdown'));
20092011
expect(timeDropDown.properties.hidden).toBeFalsy();
20102012

20112013
timePicker.close();
2014+
tick();
20122015
fixture.detectChanges();
20132016

20142017
formGroup.disable();
20152018
tick();
20162019
fixture.detectChanges();
2020+
timeIcon = fixture.debugElement.query(By.css('.igx-icon'));
20172021

2018-
timeIcon.nativeElement.click();
2019-
tick();
2022+
timeIcon.triggerEventHandler('click', mockClickEvent);
20202023
fixture.detectChanges();
2021-
expect(timeDropDown.properties).toEqual({});
2024+
timeDropDown = fixture.debugElement.query(By.css('.igx-time-picker--dropdown'));
2025+
expect(timeDropDown.classes['igx-toggle--hidden']).toEqual(true);
20222026
}));
20232027
});
20242028
});

0 commit comments

Comments
 (0)