Skip to content

Commit 2535416

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Add back icon check for expansion panel.
1 parent 760817a commit 2535416

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

projects/igniteui-angular/src/lib/expansion-panel/expansion-panel.spec.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { Component, ViewChild } from '@angular/core';
2+
import { Component, DebugElement, ViewChild } from '@angular/core';
33
import { TestBed, ComponentFixture, tick, fakeAsync, waitForAsync } from '@angular/core/testing';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
55
import { IgxExpansionPanelComponent } from './expansion-panel.component';
@@ -296,13 +296,17 @@ describe('igxExpansionPanel', () => {
296296
panel: IgxExpansionPanelComponent,
297297
panelContainer: any,
298298
panelHeader: HTMLElement,
299-
button: HTMLElement,
299+
button: DebugElement,
300300
timesCollapsed = 0,
301301
timesExpanded = 0) => {
302302
expect(panel.collapsed).toEqual(collapsed);
303303
const ariaExpanded = collapsed ? 'false' : 'true';
304304
expect(panelHeader.querySelector('div [role = \'button\']').getAttribute('aria-expanded')).toMatch(ariaExpanded);
305305
expect(panelHeader.classList.contains(CSS_CLASS_HEADER_EXPANDED)).toEqual(!collapsed);
306+
if (button.children.length > 1) {
307+
const iconName = collapsed ? 'expand_more' : 'expand_less';
308+
expect(button.componentInstance.iconName).toMatch(iconName);
309+
}
306310
if (collapsed) {
307311
expect(panelContainer.lastElementChild.nodeName).toEqual('IGX-EXPANSION-PANEL-HEADER');
308312
} else {
@@ -322,7 +326,7 @@ describe('igxExpansionPanel', () => {
322326
const header = fixture.componentInstance.header;
323327
const panelContainer = fixture.nativeElement.querySelector('.' + CSS_CLASS_EXPANSION_PANEL);
324328
const panelHeader = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_HEADER) as HTMLElement;
325-
const button = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_ICON) as HTMLElement;
329+
const button = fixture.debugElement.query(By.css('.' + CSS_CLASS_PANEL_ICON)) as DebugElement;
326330

327331
let timesCollapsed = 0;
328332
let timesExpanded = 0;
@@ -383,7 +387,7 @@ describe('igxExpansionPanel', () => {
383387
const header = fixture.componentInstance.header;
384388
const panelContainer = fixture.nativeElement.querySelector('.' + CSS_CLASS_EXPANSION_PANEL);
385389
const panelHeader = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_HEADER) as HTMLElement;
386-
let button = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_ICON) as HTMLElement;
390+
let button = fixture.debugElement.query(By.css('.' + CSS_CLASS_PANEL_ICON)) as DebugElement;
387391

388392
let timesCollapsed = 0;
389393
let timesExpanded = 0;
@@ -392,23 +396,23 @@ describe('igxExpansionPanel', () => {
392396
spyOn(header.interaction, 'emit');
393397
verifyPanelExpansionState(true, panel, panelContainer, panelHeader, button, timesCollapsed, timesExpanded);
394398

395-
button.click();
399+
button.nativeElement.click()
396400
tick();
397401
fixture.detectChanges();
398402
tick();
399403
timesExpanded++;
400404
verifyPanelExpansionState(false, panel, panelContainer, panelHeader, button, timesCollapsed, timesExpanded);
401405
expect(header.interaction.emit).toHaveBeenCalledTimes(1);
402406

403-
button.click();
407+
button.nativeElement.click()
404408
tick();
405409
fixture.detectChanges();
406410
tick();
407411
timesCollapsed++;
408412
verifyPanelExpansionState(true, panel, panelContainer, panelHeader, button, timesCollapsed, timesExpanded);
409413
expect(header.interaction.emit).toHaveBeenCalledTimes(2);
410414

411-
button.click();
415+
button.nativeElement.click()
412416
tick();
413417
fixture.detectChanges();
414418
tick();
@@ -422,24 +426,24 @@ describe('igxExpansionPanel', () => {
422426
fixture.detectChanges();
423427
tick();
424428

425-
button = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_ICON) as HTMLElement;
426-
button.click();
429+
button = fixture.debugElement.query(By.css('.' + CSS_CLASS_PANEL_ICON)) as DebugElement;
430+
button.nativeElement.click()
427431
tick();
428432
fixture.detectChanges();
429433
tick();
430434
timesCollapsed++;
431435
verifyPanelExpansionState(true, panel, panelContainer, panelHeader, button, timesCollapsed, timesExpanded);
432436
expect(header.interaction.emit).toHaveBeenCalledTimes(4);
433437

434-
button.click();
438+
button.nativeElement.click()
435439
tick();
436440
fixture.detectChanges();
437441
tick();
438442
timesExpanded++;
439443
verifyPanelExpansionState(false, panel, panelContainer, panelHeader, button, timesCollapsed, timesExpanded);
440444
expect(header.interaction.emit).toHaveBeenCalledTimes(5);
441445

442-
button.click();
446+
button.nativeElement.click()
443447
tick();
444448
fixture.detectChanges();
445449
tick();
@@ -453,7 +457,7 @@ describe('igxExpansionPanel', () => {
453457
const panel = fixture.componentInstance.expansionPanel;
454458
const panelContainer = fixture.nativeElement.querySelector('.' + CSS_CLASS_EXPANSION_PANEL);
455459
const panelHeader = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_HEADER) as HTMLElement;
456-
const button = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_ICON) as HTMLElement;
460+
const button = fixture.debugElement.query(By.css('.' + CSS_CLASS_PANEL_ICON)) as DebugElement;
457461
spyOn(panel.contentCollapsed, 'emit').and.callThrough();
458462
spyOn(panel.contentExpanded, 'emit').and.callThrough();
459463
verifyPanelExpansionState(true, panel, panelContainer, panelHeader, button);
@@ -482,7 +486,7 @@ describe('igxExpansionPanel', () => {
482486
const panel = fixture.componentInstance.expansionPanel;
483487
const panelContainer = fixture.nativeElement.querySelector('.' + CSS_CLASS_EXPANSION_PANEL);
484488
const panelHeader = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_HEADER) as HTMLElement;
485-
const button = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_ICON) as HTMLElement;
489+
const button = fixture.debugElement.query(By.css('.' + CSS_CLASS_PANEL_ICON)) as DebugElement;
486490

487491
let timesCollapsed = 0;
488492
let timesExpanded = 0;
@@ -524,7 +528,7 @@ describe('igxExpansionPanel', () => {
524528
const panel = fixture.componentInstance.expansionPanel;
525529
const panelContainer = fixture.nativeElement.querySelector('.' + CSS_CLASS_EXPANSION_PANEL);
526530
const panelHeader = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_HEADER) as HTMLElement;
527-
const button = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_ICON) as HTMLElement;
531+
const button = fixture.debugElement.query(By.css('.' + CSS_CLASS_PANEL_ICON)) as DebugElement;
528532

529533
let timesCollapsed = 0;
530534
let timesExpanded = 0;
@@ -571,7 +575,7 @@ describe('igxExpansionPanel', () => {
571575
const header = fixture.componentInstance.header;
572576
const panelContainer = fixture.nativeElement.querySelector('.' + CSS_CLASS_EXPANSION_PANEL);
573577
const panelHeader = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_HEADER) as HTMLElement;
574-
const button = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_ICON) as HTMLElement;
578+
const button = fixture.debugElement.query(By.css('.' + CSS_CLASS_PANEL_ICON)) as DebugElement;
575579

576580
let timesCollapsed = 0;
577581
let timesExpanded = 0;
@@ -684,7 +688,7 @@ describe('igxExpansionPanel', () => {
684688
const header = fixture.componentInstance.header;
685689
const panelContainer = fixture.nativeElement.querySelector('.' + CSS_CLASS_EXPANSION_PANEL);
686690
const panelHeader = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_HEADER) as HTMLElement;
687-
const button = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_ICON) as HTMLElement;
691+
const button = fixture.debugElement.query(By.css('.' + CSS_CLASS_PANEL_ICON)) as DebugElement;
688692

689693
let timesCollapsed = 0;
690694
let timesExpanded = 0;
@@ -708,7 +712,7 @@ describe('igxExpansionPanel', () => {
708712
verifyPanelExpansionState(true, panel, panelContainer, panelHeader, button, timesCollapsed, timesExpanded);
709713
expect(header.interaction.emit).toHaveBeenCalledTimes(1);
710714

711-
button.click();
715+
button.nativeElement.click()
712716
tick();
713717
fixture.detectChanges();
714718
tick();
@@ -759,7 +763,7 @@ describe('igxExpansionPanel', () => {
759763
const header = fixture.componentInstance.header;
760764
const panelContainer = fixture.nativeElement.querySelector('.' + CSS_CLASS_EXPANSION_PANEL);
761765
const panelHeader = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_HEADER) as HTMLElement;
762-
const button = fixture.nativeElement.querySelector('.' + CSS_CLASS_PANEL_ICON) as HTMLElement;
766+
const button = fixture.debugElement.query(By.css('.' + CSS_CLASS_PANEL_ICON)) as DebugElement;
763767
const headerButton = panelHeader.querySelector('div [role = \'button\']');
764768

765769
let timesCollapsed = 0;
@@ -788,7 +792,7 @@ describe('igxExpansionPanel', () => {
788792
verifyPanelExpansionState(false, panel, panelContainer, panelHeader, button, timesCollapsed, timesExpanded);
789793
expect(header.interaction.emit).toHaveBeenCalledTimes(0);
790794

791-
button.click();
795+
button.nativeElement.click()
792796
tick();
793797
fixture.detectChanges();
794798
tick();
@@ -817,7 +821,7 @@ describe('igxExpansionPanel', () => {
817821
verifyPanelExpansionState(true, panel, panelContainer, panelHeader, button, timesCollapsed, timesExpanded);
818822
expect(header.interaction.emit).toHaveBeenCalledTimes(0);
819823

820-
button.click();
824+
button.nativeElement.click()
821825
tick();
822826
fixture.detectChanges();
823827
tick();

0 commit comments

Comments
 (0)