|
1 |
| -import {TestBed, ComponentFixture} from '@angular/core/testing'; |
| 1 | +import {TestBed, ComponentFixture, inject} from '@angular/core/testing'; |
2 | 2 | import {createGenericTestComponent} from '../util/tests';
|
3 | 3 |
|
4 | 4 | import {Component} from '@angular/core';
|
5 | 5 |
|
6 | 6 | import {NgbAccordionModule} from './accordion.module';
|
| 7 | +import {NgbAccordionConfig} from './accordion-config'; |
| 8 | +import {NgbAccordion} from './accordion'; |
7 | 9 |
|
8 | 10 | const createTestComponent = (html: string) =>
|
9 | 11 | createGenericTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
@@ -45,6 +47,13 @@ describe('ngb-accordion', () => {
|
45 | 47 | TestBed.overrideComponent(TestComponent, {set: {template: html}});
|
46 | 48 | });
|
47 | 49 |
|
| 50 | + it('should initialize inputs with default values', () => { |
| 51 | + const defaultConfig = new NgbAccordionConfig(); |
| 52 | + const accordionCmp = new NgbAccordion(defaultConfig); |
| 53 | + expect(accordionCmp.type).toBe(defaultConfig.type); |
| 54 | + expect(accordionCmp.closeOtherPanels).toBe(defaultConfig.closeOthers); |
| 55 | + }); |
| 56 | + |
48 | 57 | it('should have no open panels', () => {
|
49 | 58 | const fixture = TestBed.createComponent(TestComponent);
|
50 | 59 | fixture.detectChanges();
|
@@ -303,6 +312,47 @@ describe('ngb-accordion', () => {
|
303 | 312 | expect(el[1]).toHaveCssClass('card-danger');
|
304 | 313 | expect(el[2]).toHaveCssClass('card-warning');
|
305 | 314 | });
|
| 315 | + |
| 316 | + describe('Custom config', () => { |
| 317 | + let config: NgbAccordionConfig; |
| 318 | + |
| 319 | + beforeEach(() => { TestBed.configureTestingModule({imports: [NgbAccordionModule]}); }); |
| 320 | + |
| 321 | + beforeEach(inject([NgbAccordionConfig], (c: NgbAccordionConfig) => { |
| 322 | + config = c; |
| 323 | + config.closeOthers = true; |
| 324 | + config.type = 'success'; |
| 325 | + })); |
| 326 | + |
| 327 | + it('should initialize inputs with provided config', () => { |
| 328 | + const fixture = TestBed.createComponent(NgbAccordion); |
| 329 | + fixture.detectChanges(); |
| 330 | + |
| 331 | + let accordion = fixture.componentInstance; |
| 332 | + expect(accordion.closeOtherPanels).toBe(config.closeOthers); |
| 333 | + expect(accordion.type).toBe(config.type); |
| 334 | + }); |
| 335 | + }); |
| 336 | + |
| 337 | + describe('Custom config as provider', () => { |
| 338 | + let config = new NgbAccordionConfig(); |
| 339 | + config.closeOthers = true; |
| 340 | + config.type = 'success'; |
| 341 | + |
| 342 | + beforeEach(() => { |
| 343 | + TestBed.configureTestingModule( |
| 344 | + {imports: [NgbAccordionModule], providers: [{provide: NgbAccordionConfig, useValue: config}]}); |
| 345 | + }); |
| 346 | + |
| 347 | + it('should initialize inputs with provided config as provider', () => { |
| 348 | + const fixture = TestBed.createComponent(NgbAccordion); |
| 349 | + fixture.detectChanges(); |
| 350 | + |
| 351 | + let accordion = fixture.componentInstance; |
| 352 | + expect(accordion.closeOtherPanels).toBe(config.closeOthers); |
| 353 | + expect(accordion.type).toBe(config.type); |
| 354 | + }); |
| 355 | + }); |
306 | 356 | });
|
307 | 357 |
|
308 | 358 | @Component({selector: 'test-cmp', template: ''})
|
|
0 commit comments