diff --git a/lib/core/collapsable/accordion-group.component.html b/lib/core/collapsable/accordion-group.component.html
index 650e223fe6..63a3efce6e 100644
--- a/lib/core/collapsable/accordion-group.component.html
+++ b/lib/core/collapsable/accordion-group.component.html
@@ -1,7 +1,7 @@
-
@@ -19,8 +19,8 @@
-
-
-
+
+
+
-
\ No newline at end of file
+
diff --git a/lib/core/collapsable/accordion-group.component.spec.ts b/lib/core/collapsable/accordion-group.component.spec.ts
index d6c149d030..4f21ad1ec2 100644
--- a/lib/core/collapsable/accordion-group.component.spec.ts
+++ b/lib/core/collapsable/accordion-group.component.spec.ts
@@ -19,6 +19,10 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AccordionGroupComponent } from './accordion-group.component';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
+import { Component, ViewChild } from '@angular/core';
+import { CoreModule } from '../core.module';
+import { NoopAnimationsModule } from '@angular/platform-browser/animations';
+import { By } from '@angular/platform-browser';
describe('AccordionGroupComponent', () => {
@@ -115,4 +119,106 @@ describe('AccordionGroupComponent', () => {
header.click();
}));
+ it('should display icon if is present', (done) => {
+ component.headingIcon = 'assignment';
+ fixture.detectChanges();
+ fixture.whenStable().then(() => {
+ fixture.detectChanges();
+ expect(component.hasHeadingIcon()).toBe(true);
+ let headerText = element.querySelector('.adf-panel-heading-icon');
+ expect(headerText).toBeDefined();
+ done();
+ });
+ });
+});
+
+@Component({
+ template: `
+
+ My List
+
+ `
+})
+class CustomAccordionGroupComponent extends AccordionGroupComponent {
+ isOpen: boolean;
+ isSelected: boolean;
+ headingIcon: string;
+
+ @ViewChild('accordion')
+ accordion: AccordionGroupComponent;
+}
+
+describe('Custom AccordionGroup', () => {
+ let fixture: ComponentFixture;
+ let component: CustomAccordionGroupComponent;
+
+ setupTestBed({
+ imports: [
+ NoopAnimationsModule,
+ CoreModule.forRoot()
+ ],
+ declarations: [
+ CustomAccordionGroupComponent
+ ]
+ });
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(CustomAccordionGroupComponent);
+ component = fixture.componentInstance;
+ });
+
+ afterEach(() => {
+ fixture.destroy();
+ });
+
+ it('should render the title', () => {
+ component.isOpen = true;
+ component.isSelected = true;
+ fixture.detectChanges();
+ let title: any = fixture.debugElement.queryAll(By.css('.adf-panel-heading-text'));
+ expect(title.length).toBe(1);
+ expect(title[0].nativeElement.innerText).toBe('My Header');
+ });
+
+ it('should render a tab with icon', () => {
+ component.headingIcon = 'assignment';
+ fixture.detectChanges();
+ let tab: any = fixture.debugElement.queryAll(By.css('.material-icons'));
+ expect(tab[0].nativeElement.innerText).toBe('assignment');
+ });
+
+ it('should expand the panel if has content and is selected', (done) => {
+ spyOn(component.accordion, 'expandPanel').and.callThrough();
+ component.isOpen = false;
+ component.isSelected = true;
+ fixture.detectChanges();
+ fixture.whenStable().then(() => {
+ fixture.detectChanges();
+ expect(component.accordion.expansionPanel.expanded).toBe(false);
+ const selectElement = fixture.debugElement.nativeElement.querySelector('#adf-expansion-panel-id');
+ selectElement.click();
+ expect(component.accordion.expandPanel).toHaveBeenCalled();
+ expect(component.accordion.expansionPanel.expanded).toBe(true);
+ done();
+ });
+ });
+
+ it('should close the expanded panel if has content and is selected', (done) => {
+ spyOn(component.accordion, 'expandPanel').and.callThrough();
+ component.isOpen = true;
+ component.isSelected = true;
+ fixture.detectChanges();
+ fixture.whenStable().then(() => {
+ fixture.detectChanges();
+ expect(component.accordion.expansionPanel.expanded).toBe(true);
+ const selectElement = fixture.debugElement.nativeElement.querySelector('#adf-expansion-panel-id');
+ selectElement.click();
+ expect(component.accordion.expandPanel).toHaveBeenCalled();
+ expect(component.accordion.expansionPanel.expanded).toBe(false);
+ done();
+ });
+ });
});
diff --git a/lib/core/collapsable/accordion-group.component.ts b/lib/core/collapsable/accordion-group.component.ts
index 9a8b919d11..ee523de7a4 100644
--- a/lib/core/collapsable/accordion-group.component.ts
+++ b/lib/core/collapsable/accordion-group.component.ts
@@ -78,19 +78,19 @@ export class AccordionGroupComponent implements AfterViewInit {
constructor() { }
ngAfterViewInit() {
- this.hasContent = this.contentWrapper.nativeElement && this.contentWrapper.nativeElement.children.length > 0;
+ this.hasContent = this.contentWrapper ? this.contentWrapper.nativeElement && this.contentWrapper.nativeElement.children.length > 0 : false;
}
hasHeadingIcon() {
- return this.headingIcon ? true : false;
+ return !!this.headingIcon;
}
onHeaderClick(): void {
this.headingClick.emit(this.heading);
}
- isExpandable(event: any) {
- if (!this.hasContent || !this.isOpen) {
+ isExpandable() {
+ if (this.hasContent && this.isSelected) {
this.expandPanel();
}
}