|
1 | 1 | import { ComponentFixture, TestBed } from '@angular/core/testing';
|
| 2 | +import { By } from '@angular/platform-browser'; |
2 | 3 |
|
3 | 4 | import { TabsComponent } from './tabs.component';
|
4 | 5 |
|
5 | 6 | describe('TabsComponent', () => {
|
6 | 7 | let component: TabsComponent;
|
7 | 8 | let fixture: ComponentFixture<TabsComponent>;
|
8 | 9 |
|
| 10 | + const tabs = [{ label: 'Tab 1', active: true }, { label: 'Tab 2' }]; |
| 11 | + |
9 | 12 | beforeEach(async () => {
|
10 | 13 | await TestBed.configureTestingModule({
|
11 |
| - imports: [TabsComponent] |
| 14 | + imports: [TabsComponent], |
12 | 15 | })
|
13 | 16 | .compileComponents();
|
14 | 17 |
|
15 | 18 | fixture = TestBed.createComponent(TabsComponent);
|
| 19 | + fixture.componentRef.setInput('tabs', tabs); |
16 | 20 | component = fixture.componentInstance;
|
17 | 21 | fixture.detectChanges();
|
18 | 22 | });
|
19 | 23 |
|
20 | 24 | it('should create', () => {
|
21 | 25 | expect(component).toBeTruthy();
|
22 | 26 | });
|
| 27 | + |
| 28 | + it('should display the tabs', () => { |
| 29 | + const tabsRendered = fixture.debugElement.queryAll(By.css('.tab')); |
| 30 | + expect(tabsRendered.length).toBe(tabs.length); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should display the active tab', () => { |
| 34 | + const activeTab = fixture.debugElement.query(By.css('input:checked')); |
| 35 | + expect(activeTab.nativeElement.id).toContain(tabs[0].label); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should emit the selected tab on onSelectTab', () => { |
| 39 | + spyOn(component.activeTab, 'emit'); |
| 40 | + const expectedTab = 'Test Tab'; |
| 41 | + component.onSelectTab(expectedTab); |
| 42 | + expect(component.activeTab.emit).toHaveBeenCalledWith(expectedTab); |
| 43 | + }); |
23 | 44 | });
|
0 commit comments