]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; |
2 | ||
3 | import { TabsetComponent, TabsModule } from 'ngx-bootstrap/tabs'; | |
4 | ||
5 | import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper'; | |
6 | import { AppModule } from '../../../app.module'; | |
7 | import { CdTableSelection } from '../../../shared/models/cd-table-selection'; | |
8 | import { Permissions } from '../../../shared/models/permissions'; | |
9 | import { RbdConfigurationListComponent } from '../../block/rbd-configuration-list/rbd-configuration-list.component'; | |
10 | import { PoolDetailsComponent } from './pool-details.component'; | |
11 | ||
12 | describe('PoolDetailsComponent', () => { | |
13 | let poolDetailsComponent: PoolDetailsComponent; | |
14 | let fixture: ComponentFixture<PoolDetailsComponent>; | |
15 | ||
16 | configureTestBed({ | |
17 | imports: [TabsModule.forRoot(), AppModule], | |
18 | declarations: [PoolDetailsComponent, RbdConfigurationListComponent], | |
19 | providers: [i18nProviders] | |
20 | }); | |
21 | ||
22 | beforeEach(() => { | |
23 | fixture = TestBed.createComponent(PoolDetailsComponent); | |
24 | poolDetailsComponent = fixture.componentInstance; | |
25 | poolDetailsComponent.selection = new CdTableSelection(); | |
26 | poolDetailsComponent.permissions = new Permissions({ | |
27 | grafana: ['read'] | |
28 | }); | |
29 | fixture.detectChanges(); | |
30 | }); | |
31 | ||
32 | it('should create', () => { | |
33 | expect(poolDetailsComponent).toBeTruthy(); | |
34 | }); | |
35 | ||
36 | describe('Pool details tabset', () => { | |
37 | beforeEach(() => { | |
38 | poolDetailsComponent.selection.selected = [ | |
39 | { | |
40 | tiers: [0], | |
41 | pool: 0 | |
42 | } | |
43 | ]; | |
11fdf7f2 TL |
44 | }); |
45 | ||
46 | it('should recognize a tabset child', () => { | |
47 | fixture.detectChanges(); | |
48 | const tabsetChild: TabsetComponent = poolDetailsComponent.tabsetChild; | |
49 | expect(tabsetChild).toBeDefined(); | |
50 | }); | |
51 | ||
52 | it('should show "Cache Tiers Details" tab if selected pool has "tiers"', () => { | |
53 | fixture.detectChanges(); | |
54 | const tabs = poolDetailsComponent.tabsetChild.tabs; | |
55 | expect(tabs.length).toBe(3); | |
56 | expect(tabs[2].heading).toBe('Cache Tiers Details'); | |
57 | expect(tabs[0].active).toBeTruthy(); | |
58 | }); | |
59 | ||
60 | it('should not show "Cache Tiers Details" tab if selected pool has no "tiers"', () => { | |
61 | poolDetailsComponent.selection.selected = [ | |
62 | { | |
63 | tiers: [] | |
64 | } | |
65 | ]; | |
11fdf7f2 TL |
66 | fixture.detectChanges(); |
67 | const tabs = poolDetailsComponent.tabsetChild.tabs; | |
68 | expect(tabs.length).toEqual(2); | |
69 | expect(tabs[0].active).toBeTruthy(); | |
70 | }); | |
71 | ||
eafe8130 | 72 | it('current active status of tabs should not change when selection is the same as previous selection', () => { |
11fdf7f2 TL |
73 | fixture.detectChanges(); |
74 | const tabs = poolDetailsComponent.tabsetChild.tabs; | |
75 | expect(tabs[0].active).toBeTruthy(); | |
76 | ||
77 | tabs[1].active = true; | |
78 | fixture.detectChanges(); | |
79 | expect(tabs[1].active).toBeTruthy(); | |
80 | }); | |
eafe8130 TL |
81 | |
82 | it('returns pool details correctly', () => { | |
83 | const pool = { prop1: 1, cdIsBinary: true, prop2: 2, cdExecuting: true, prop3: 3 }; | |
84 | const expectedPool = { prop1: 1, prop2: 2, prop3: 3 }; | |
85 | ||
86 | expect(poolDetailsComponent.filterNonPoolData(pool)).toEqual(expectedPool); | |
87 | }); | |
88 | ||
89 | it('pool data filtering is called', () => { | |
90 | const filterNonPoolDataSpy = spyOn( | |
91 | poolDetailsComponent, | |
92 | 'filterNonPoolData' | |
93 | ).and.callThrough(); | |
94 | ||
95 | fixture.detectChanges(); | |
96 | ||
97 | expect(filterNonPoolDataSpy).toHaveBeenCalled(); | |
98 | }); | |
11fdf7f2 TL |
99 | }); |
100 | }); |