ipsos-components
Version:
Material Design components for Angular
68 lines (60 loc) • 2.17 kB
text/typescript
import {async, TestBed} from '@angular/core/testing';
import {Component, ViewChild} from '@angular/core';
import {By} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {CdkAccordionModule, CdkAccordionItem} from './public-api';
describe('CdkAccordion', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
BrowserAnimationsModule,
CdkAccordionModule
],
declarations: [
SetOfItems
],
});
TestBed.compileComponents();
}));
it('should ensure only one item is expanded at a time', () => {
const fixture = TestBed.createComponent(SetOfItems);
const [firstPanel, secondPanel] = fixture.debugElement
.queryAll(By.directive(CdkAccordionItem))
.map(el => {
return el.injector.get(CdkAccordionItem) as CdkAccordionItem;
});
firstPanel.open();
fixture.detectChanges();
expect(firstPanel.expanded).toBeTruthy();
expect(secondPanel.expanded).toBeFalsy();
secondPanel.open();
fixture.detectChanges();
expect(firstPanel.expanded).toBeFalsy();
expect(secondPanel.expanded).toBeTruthy();
});
it('should allow multiple items to be expanded simultaneously', () => {
const fixture = TestBed.createComponent(SetOfItems);
const [firstPanel, secondPanel] = fixture.debugElement
.queryAll(By.directive(CdkAccordionItem))
.map(el => {
return el.injector.get(CdkAccordionItem) as CdkAccordionItem;
});
fixture.componentInstance.multi = true;
fixture.detectChanges();
firstPanel.expanded = true;
secondPanel.expanded = true;
fixture.detectChanges();
expect(firstPanel.expanded).toBeTruthy();
expect(secondPanel.expanded).toBeTruthy();
});
});
class SetOfItems {
item1;
item2;
multi: boolean = false;
}