/
tabset.spec.ts
593 lines (472 loc) · 22.2 KB
/
tabset.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
import {TestBed, ComponentFixture, inject} from '@angular/core/testing';
import {createGenericTestComponent} from '../test/common';
import {Component} from '@angular/core';
import {NgbTabsetModule} from './tabset.module';
import {NgbTabsetConfig} from './tabset-config';
import {NgbTabset} from './tabset';
const createTestComponent = (html: string) =>
createGenericTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
function getTabTitles(nativeEl: HTMLElement) {
return nativeEl.querySelectorAll('.nav-link');
}
function getTabContent(nativeEl: HTMLElement) {
return nativeEl.querySelectorAll('.tab-content .tab-pane');
}
function expectTabs(nativeEl: HTMLElement, active: boolean[], disabled?: boolean[]) {
const tabTitles = getTabTitles(nativeEl);
const tabContent = getTabContent(nativeEl);
const anyTabsActive = active.reduce((prev, curr) => prev || curr, false);
expect(tabTitles.length).toBe(active.length);
expect(tabContent.length).toBe(anyTabsActive ? 1 : 0); // only 1 tab content in DOM at a time
if (disabled) {
expect(disabled.length).toBe(active.length);
} else {
disabled = new Array(active.length); // tabs are not disabled by default
}
for (let i = 0; i < active.length; i++) {
if (active[i]) {
expect(tabTitles[i]).toHaveCssClass('active');
} else {
expect(tabTitles[i]).not.toHaveCssClass('active');
}
if (disabled[i]) {
expect(tabTitles[i]).toHaveCssClass('disabled');
expect(tabTitles[i].getAttribute('aria-disabled')).toBe('true');
expect(tabTitles[i].getAttribute('tabindex')).toBe('-1');
} else {
expect(tabTitles[i]).not.toHaveCssClass('disabled');
expect(tabTitles[i].getAttribute('aria-disabled')).toBe('false');
expect(tabTitles[i].getAttribute('tabindex')).toBeNull();
}
}
}
function getButton(nativeEl: HTMLElement) {
return nativeEl.querySelectorAll('button');
}
describe('ngb-tabset', () => {
beforeEach(() => { TestBed.configureTestingModule({declarations: [TestComponent], imports: [NgbTabsetModule]}); });
it('should initialize inputs with default values', () => {
const defaultConfig = new NgbTabsetConfig();
const tabset = new NgbTabset(new NgbTabsetConfig());
expect(tabset.type).toBe(defaultConfig.type);
});
it('should render tabs and select first tab as active by default', () => {
const fixture = createTestComponent(`
<ngb-tabset>
<ngb-tab title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
const tabTitles = getTabTitles(fixture.nativeElement);
const tabContent = getTabContent(fixture.nativeElement);
expect(tabTitles[0].textContent).toMatch(/foo/);
expect(tabTitles[1].textContent).toMatch(/bar/);
expect(tabContent.length).toBe(1);
expect(tabContent[0].textContent).toMatch(/Foo/);
expectTabs(fixture.nativeElement, [true, false]);
});
it('should have aria attributes', () => {
const fixture = createTestComponent(`
<ngb-tabset>
<ngb-tab title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
const compiled: HTMLElement = fixture.nativeElement;
const tabTitles = getTabTitles(compiled);
const tabContent = getTabContent(compiled);
expect(tabTitles[0].getAttribute('role')).toBe('tab');
expect(tabTitles[0].getAttribute('aria-selected')).toBe('true');
expect(tabTitles[0].getAttribute('aria-controls')).toBe(tabContent[0].getAttribute('id'));
expect(tabContent[0].getAttribute('role')).toBe('tabpanel');
expect(tabContent[0].getAttribute('aria-labelledby')).toBe(tabTitles[0].id);
expect(tabTitles[1].getAttribute('role')).toBe('tab');
expect(tabTitles[1].getAttribute('aria-selected')).toBe('false');
expect(tabTitles[1].getAttribute('aria-controls')).toBeNull();
});
it('should remove aria-controls when tab content is not in DOM', () => {
const fixture = createTestComponent(`
<ngb-tabset [destroyOnHide]="true">
<ngb-tab title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
const compiled: HTMLElement = fixture.nativeElement;
const tabTitles = getTabTitles(compiled);
const tabContent = getTabContent(compiled);
expect(tabTitles[0].getAttribute('aria-controls')).toBe(tabContent[0].getAttribute('id'));
expect(tabTitles[0].getAttribute('aria-selected')).toBe('true');
expect(tabTitles[1].getAttribute('aria-controls')).toBeNull();
expect(tabContent[1]).toBeUndefined();
});
it('should have aria-controls and aria-selected when tab content is hidden', () => {
const fixture = createTestComponent(`
<ngb-tabset [destroyOnHide]="false">
<ngb-tab title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
const compiled: HTMLElement = fixture.nativeElement;
const tabTitles = getTabTitles(compiled);
const tabContent = getTabContent(compiled);
expect(tabTitles[0].getAttribute('aria-controls')).toBe(tabContent[0].id);
expect(tabTitles[0].getAttribute('aria-selected')).toBe('true');
expect(tabTitles[1].getAttribute('aria-controls')).toBe(tabContent[1].id);
expect(tabTitles[1].getAttribute('aria-selected')).toBe('false');
});
it('should allow mix of text and HTML in tab titles', () => {
const fixture = createTestComponent(`
<ngb-tabset>
<ngb-tab title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab>
<ng-template ngbTabTitle><b>bar</b></ng-template>
<ng-template ngbTabContent>Bar</ng-template>
</ngb-tab>
<ngb-tab title="baz">
<ng-template ngbTabTitle>baz</ng-template>
<ng-template ngbTabContent>Baz</ng-template>
</ngb-tab>
</ngb-tabset>
`);
const tabTitles = getTabTitles(fixture.nativeElement);
expect(tabTitles[0].textContent).toMatch(/foo/);
expect(tabTitles[1].innerHTML).toMatch(/<b>bar<\/b>/);
expect(tabTitles[2].textContent).toMatch(/bazbaz/);
});
it('should not pick up titles from nested tabsets', () => {
const testHtml = `
<ngb-tabset>
<ngb-tab title="parent">
<ng-template ngbTabContent>
<ngb-tabset>
<ngb-tab>
<ng-template ngbTabTitle>child</ng-template>
<ng-template ngbTabContent></ng-template>
</ngb-tab>
</ngb-tabset>
</ng-template>
</ngb-tab>
</ngb-tabset>
`;
const fixture = createTestComponent(testHtml);
// additional change detection is required to reproduce the problem in the test environment
fixture.detectChanges();
const titles = getTabTitles(fixture.nativeElement);
const parentTitle = titles[0].textContent.trim();
const childTitle = titles[1].textContent.trim();
expect(parentTitle).toContain('parent');
expect(parentTitle).not.toContain('child');
expect(childTitle).toContain('child');
expect(childTitle).not.toContain('parent');
});
it('should not crash for empty tabsets', () => {
const fixture = createTestComponent(`<ngb-tabset activeId="2"></ngb-tabset>`);
expectTabs(fixture.nativeElement, []);
});
it('should not crash for tabsets with empty tab content', () => {
const fixture = createTestComponent(`<ngb-tabset><ngb-tab></ngb-tab></ngb-tabset>`);
expectTabs(fixture.nativeElement, [true]);
});
it('should mark the requested tab as active', () => {
const fixture = createTestComponent(`
<ngb-tabset activeId="2">
<ngb-tab title="foo" id="1"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab title="bar" id="2"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expectTabs(fixture.nativeElement, [false, true]);
});
it('should auto-correct requested active tab id', () => {
const fixture = createTestComponent(`
<ngb-tabset activeId="doesntExist">
<ngb-tab title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expectTabs(fixture.nativeElement, [true, false]);
});
it('should auto-correct requested active tab id for undefined ids', () => {
const fixture = createTestComponent(`
<ngb-tabset [activeId]="activeTabId">
<ngb-tab title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expectTabs(fixture.nativeElement, [true, false]);
});
it('should change active tab on tab title click', () => {
const fixture = createTestComponent(`
<ngb-tabset>
<ngb-tab title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
const tabTitles = getTabTitles(fixture.nativeElement);
(<HTMLElement>tabTitles[1]).click();
fixture.detectChanges();
expectTabs(fixture.nativeElement, [false, true]);
(<HTMLElement>tabTitles[0]).click();
fixture.detectChanges();
expectTabs(fixture.nativeElement, [true, false]);
});
it('should support disabled tabs', () => {
const fixture = createTestComponent(`
<ngb-tabset>
<ngb-tab title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab title="bar" [disabled]="true"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expectTabs(fixture.nativeElement, [true, false], [false, true]);
});
it('should not change active tab on disabled tab title click', () => {
const fixture = createTestComponent(`
<ngb-tabset>
<ngb-tab title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab title="bar" [disabled]="true"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expectTabs(fixture.nativeElement, [true, false], [false, true]);
(<HTMLElement>getTabTitles(fixture.nativeElement)[1]).click();
fixture.detectChanges();
expectTabs(fixture.nativeElement, [true, false], [false, true]);
});
it('should allow initially active and disabled tabs', () => {
const fixture = createTestComponent(`
<ngb-tabset>
<ngb-tab title="bar" [disabled]="true"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expectTabs(fixture.nativeElement, [true], [true]);
});
it('should have nav-tabs default', () => {
const fixture = createTestComponent(`
<ngb-tabset>
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expect(fixture.nativeElement.querySelector('ul')).toHaveCssClass('nav-tabs');
expect(fixture.nativeElement.querySelector('ul')).not.toHaveCssClass('nav-pills');
});
it('should have pills upon setting pills', () => {
const fixture = createTestComponent(`
<ngb-tabset type="pills">
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expect(fixture.nativeElement.querySelector('ul')).toHaveCssClass('nav-pills');
expect(fixture.nativeElement.querySelector('ul')).not.toHaveCssClass('nav-tabs');
});
it('should allow arbitrary nav type', () => {
const fixture = createTestComponent(`
<ngb-tabset type="bordered">
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expect(fixture.nativeElement.querySelector('ul')).toHaveCssClass('nav-bordered');
expect(fixture.nativeElement.querySelector('ul')).not.toHaveCssClass('nav-pills');
expect(fixture.nativeElement.querySelector('ul')).not.toHaveCssClass('nav-tabs');
});
it('should have the "justify-content-start" class by default', () => {
const fixture = createTestComponent(`
<ngb-tabset>
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expect(fixture.nativeElement.querySelector('ul')).toHaveCssClass('justify-content-start');
});
it('should have the "justify-content-center" class upon setting justify to center', () => {
const fixture = createTestComponent(`
<ngb-tabset justify="center">
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expect(fixture.nativeElement.querySelector('ul')).toHaveCssClass('justify-content-center');
});
it('should have the "justify-content-end" upon setting justify to end', () => {
const fixture = createTestComponent(`
<ngb-tabset justify="end">
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expect(fixture.nativeElement.querySelector('ul')).toHaveCssClass('justify-content-end');
});
it('should have the "nav-fill" class upon setting justify to fill', () => {
const fixture = createTestComponent(`
<ngb-tabset justify="fill">
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expect(fixture.nativeElement.querySelector('ul')).toHaveCssClass('nav-fill');
});
it('should have the "nav-justified" class upon setting justify to justified', () => {
const fixture = createTestComponent(`
<ngb-tabset justify="justified">
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expect(fixture.nativeElement.querySelector('ul')).toHaveCssClass('nav-justified');
});
it('should have the "justify-content-start" class upon setting orientation to horizontal', () => {
const fixture = createTestComponent(`
<ngb-tabset orientation="horizontal">
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expect(fixture.nativeElement.querySelector('ul')).not.toHaveCssClass('flex-column');
expect(fixture.nativeElement.querySelector('ul')).toHaveCssClass('justify-content-start');
});
it('should have the "flex-column" class upon setting orientation to vertical', () => {
const fixture = createTestComponent(`
<ngb-tabset orientation="vertical">
<ngb-tab title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
`);
expect(fixture.nativeElement.querySelector('ul')).toHaveCssClass('flex-column');
expect(fixture.nativeElement.querySelector('ul')).not.toHaveCssClass('justify-content-start');
});
it('should change active tab by calling select on an exported directive instance', () => {
const fixture = createTestComponent(`
<ngb-tabset #myTabSet="ngbTabset">
<ngb-tab id="myFirstTab" title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab id="mySecondTab" title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
<button (click)="myTabSet.select('myFirstTab')">Select the first Tab</button>
<button (click)="myTabSet.select('mySecondTab')">Select the second Tab</button>
`);
const button = getButton(fixture.nativeElement);
// Click on a button to select the second tab
(<HTMLElement>button[1]).click();
fixture.detectChanges();
expectTabs(fixture.nativeElement, [false, true]);
// Click on a button to select the first tab
(<HTMLElement>button[0]).click();
fixture.detectChanges();
expectTabs(fixture.nativeElement, [true, false]);
});
it('should not change active tab by calling select on an exported directive instance in case of disable tab', () => {
const fixture = createTestComponent(`
<ngb-tabset #myTabSet="ngbTabset">
<ngb-tab id="myFirstTab" title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab id="mySecondTab" title="bar" [disabled]="true"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
<button (click)="myTabSet.select('mySecondTab')">Select the second Tab</button>
`);
const button = getButton(fixture.nativeElement);
// Click on a button to select the second disabled tab (should not change active tab).
(<HTMLElement>button[0]).click();
fixture.detectChanges();
expectTabs(fixture.nativeElement, [true, false], [false, true]);
});
it('should not remove inactive tabs content from DOM with `destroyOnHide` flag', () => {
const fixture = createTestComponent(`
<ngb-tabset #myTabSet="ngbTabset" [destroyOnHide]="false">
<ngb-tab id="myFirstTab" title="foo"><ng-template ngbTabContent>Foo</ng-template></ngb-tab>
<ngb-tab id="mySecondTab" title="bar"><ng-template ngbTabContent>Bar</ng-template></ngb-tab>
</ngb-tabset>
<button (click)="myTabSet.select('mySecondTab')">Select the second Tab</button>
`);
const button = getButton(fixture.nativeElement);
// Click on a button to select the second tab
(<HTMLElement>button[0]).click();
fixture.detectChanges();
let tabContents = getTabContent(fixture.nativeElement);
expect(tabContents.length).toBe(2);
expect(tabContents[1]).toHaveCssClass('active');
});
it('should emit tab change event when switching tabs', () => {
const fixture = createTestComponent(`
<ngb-tabset #myTabSet="ngbTabset" (tabChange)="changeCallback($event)">
<ngb-tab id="first" title="first"><ng-template ngbTabContent>First</ng-template></ngb-tab>
<ngb-tab id="second" title="second"><ng-template ngbTabContent>Second</ng-template></ngb-tab>
</ngb-tabset>
<button (click)="myTabSet.select('first')">Select the first Tab</button>
<button (click)="myTabSet.select('second')">Select the second Tab</button>
`);
const button = getButton(fixture.nativeElement);
spyOn(fixture.componentInstance, 'changeCallback');
// Select the second tab -> change event
(<HTMLElement>button[1]).click();
fixture.detectChanges();
expect(fixture.componentInstance.changeCallback)
.toHaveBeenCalledWith(jasmine.objectContaining({activeId: 'first', nextId: 'second'}));
// Select the first tab again -> change event
(<HTMLElement>button[0]).click();
fixture.detectChanges();
expect(fixture.componentInstance.changeCallback)
.toHaveBeenCalledWith(jasmine.objectContaining({activeId: 'second', nextId: 'first'}));
});
it('should not emit tab change event when selecting currently active and disabled tabs', () => {
const fixture = createTestComponent(`
<ngb-tabset #myTabSet="ngbTabset" (tabChange)="changeCallback($event)">
<ngb-tab id="first" title="first"><ng-template ngbTabContent>First</ng-template></ngb-tab>
<ngb-tab id="second" title="second" [disabled]="true"><ng-template ngbTabContent>Second</ng-template></ngb-tab>
</ngb-tabset>
<button (click)="myTabSet.select('first')">Select the first Tab</button>
<button (click)="myTabSet.select('second')">Select the second Tab</button>
`);
const button = getButton(fixture.nativeElement);
spyOn(fixture.componentInstance, 'changeCallback');
// Select the currently active tab -> no change event
(<HTMLElement>button[0]).click();
fixture.detectChanges();
expect(fixture.componentInstance.changeCallback).not.toHaveBeenCalled();
// Select the disabled tab -> no change event
(<HTMLElement>button[1]).click();
fixture.detectChanges();
expect(fixture.componentInstance.changeCallback).not.toHaveBeenCalled();
});
it('should cancel tab change when preventDefault() is called', () => {
const fixture = createTestComponent(`
<ngb-tabset #myTabSet="ngbTabset" (tabChange)="changeCallback($event)">
<ngb-tab id="first" title="first"><ng-template ngbTabContent>First</ng-template></ngb-tab>
<ngb-tab id="second" title="second"><ng-template ngbTabContent>Second</ng-template></ngb-tab>
</ngb-tabset>
<button (click)="myTabSet.select('first')">Select the first Tab</button>
<button (click)="myTabSet.select('second')">Select the second Tab</button>
`);
const button = getButton(fixture.nativeElement);
let changeEvent = null;
fixture.componentInstance.changeCallback = (event) => {
changeEvent = event;
event.preventDefault();
};
// Select the second tab -> selection will be canceled
(<HTMLElement>button[1]).click();
fixture.detectChanges();
expect(changeEvent).toEqual(jasmine.objectContaining({activeId: 'first', nextId: 'second'}));
expectTabs(fixture.nativeElement, [true, false]);
});
describe('Custom config', () => {
let config: NgbTabsetConfig;
beforeEach(() => { TestBed.configureTestingModule({imports: [NgbTabsetModule]}); });
beforeEach(inject([NgbTabsetConfig], (c: NgbTabsetConfig) => {
config = c;
config.type = 'pills';
}));
it('should initialize inputs with provided config', () => {
const fixture = TestBed.createComponent(NgbTabset);
fixture.detectChanges();
let tabset = fixture.componentInstance;
expect(tabset.type).toBe(config.type);
});
});
describe('Custom config as provider', () => {
let config = new NgbTabsetConfig();
config.type = 'pills';
beforeEach(() => {
TestBed.configureTestingModule(
{imports: [NgbTabsetModule], providers: [{provide: NgbTabsetConfig, useValue: config}]});
});
it('should initialize inputs with provided config as provider', () => {
const fixture = TestBed.createComponent(NgbTabset);
fixture.detectChanges();
let tabset = fixture.componentInstance;
expect(tabset.type).toBe(config.type);
});
});
});
@Component({selector: 'test-cmp', template: ''})
class TestComponent {
activeTabId: string;
changeCallback = (event: any) => {};
}