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