]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
4cc380c3d16ba06eb6a73c9b4be243f0b8d6df06
[ceph-ci.git] /
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 { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
7 import { ModalModule } from 'ngx-bootstrap/modal';
8 import { of } from 'rxjs';
9
10 import {
11   configureTestBed,
12   i18nProviders,
13   PermissionHelper
14 } from '../../../../testing/unit-test-helper';
15 import { RgwBucketService } from '../../../shared/api/rgw-bucket.service';
16 import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component';
17 import { SharedModule } from '../../../shared/shared.module';
18 import { RgwBucketDetailsComponent } from '../rgw-bucket-details/rgw-bucket-details.component';
19 import { RgwBucketListComponent } from './rgw-bucket-list.component';
20
21 describe('RgwBucketListComponent', () => {
22   let component: RgwBucketListComponent;
23   let fixture: ComponentFixture<RgwBucketListComponent>;
24   let rgwBucketService: RgwBucketService;
25   let rgwBucketServiceListSpy: jasmine.Spy;
26
27   configureTestBed({
28     declarations: [RgwBucketListComponent, RgwBucketDetailsComponent],
29     imports: [
30       BrowserAnimationsModule,
31       RouterTestingModule,
32       ModalModule.forRoot(),
33       SharedModule,
34       NgbNavModule,
35       HttpClientTestingModule
36     ],
37     providers: i18nProviders
38   });
39
40   beforeEach(() => {
41     rgwBucketService = TestBed.get(RgwBucketService);
42     rgwBucketServiceListSpy = spyOn(rgwBucketService, 'list');
43     rgwBucketServiceListSpy.and.returnValue(of(null));
44     fixture = TestBed.createComponent(RgwBucketListComponent);
45     component = fixture.componentInstance;
46   });
47
48   it('should create', () => {
49     fixture.detectChanges();
50     expect(component).toBeTruthy();
51   });
52
53   it('should test all TableActions combinations', () => {
54     const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
55     const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
56       component.tableActions
57     );
58
59     expect(tableActions).toEqual({
60       'create,update,delete': {
61         actions: ['Create', 'Edit', 'Delete'],
62         primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Create' }
63       },
64       'create,update': {
65         actions: ['Create', 'Edit'],
66         primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
67       },
68       'create,delete': {
69         actions: ['Create', 'Delete'],
70         primary: { multiple: 'Delete', executing: 'Create', single: 'Create', no: 'Create' }
71       },
72       create: {
73         actions: ['Create'],
74         primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
75       },
76       'update,delete': {
77         actions: ['Edit', 'Delete'],
78         primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Edit' }
79       },
80       update: {
81         actions: ['Edit'],
82         primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
83       },
84       delete: {
85         actions: ['Delete'],
86         primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
87       },
88       'no-permissions': {
89         actions: [],
90         primary: { multiple: '', executing: '', single: '', no: '' }
91       }
92     });
93   });
94
95   it('should test if bucket data is tranformed correctly', () => {
96     rgwBucketServiceListSpy.and.returnValue(
97       of([
98         {
99           bucket: 'bucket',
100           owner: 'testid',
101           usage: {
102             'rgw.main': {
103               size_actual: 4,
104               num_objects: 2
105             },
106             'rgw.another': {
107               size_actual: 6,
108               num_objects: 6
109             }
110           },
111           bucket_quota: {
112             max_size: 20,
113             max_objects: 10,
114             enabled: true
115           }
116         }
117       ])
118     );
119     fixture.detectChanges();
120     expect(component.buckets).toEqual([
121       {
122         bucket: 'bucket',
123         owner: 'testid',
124         usage: {
125           'rgw.main': { size_actual: 4, num_objects: 2 },
126           'rgw.another': { size_actual: 6, num_objects: 6 }
127         },
128         bucket_quota: {
129           max_size: 20,
130           max_objects: 10,
131           enabled: true
132         },
133         bucket_size: 10,
134         num_objects: 8,
135         size_usage: 0.5,
136         object_usage: 0.8
137       }
138     ]);
139   });
140   it('should usage bars only if quota enabled', () => {
141     rgwBucketServiceListSpy.and.returnValue(
142       of([
143         {
144           bucket: 'bucket',
145           owner: 'testid',
146           bucket_quota: {
147             max_size: 1024,
148             max_objects: 10,
149             enabled: true
150           }
151         }
152       ])
153     );
154     fixture.detectChanges();
155     const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
156     expect(usageBars.length).toBe(2);
157   });
158   it('should not show any usage bars if quota disabled', () => {
159     rgwBucketServiceListSpy.and.returnValue(
160       of([
161         {
162           bucket: 'bucket',
163           owner: 'testid',
164           bucket_quota: {
165             max_size: 1024,
166             max_objects: 10,
167             enabled: false
168           }
169         }
170       ])
171     );
172     fixture.detectChanges();
173     const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
174     expect(usageBars.length).toBe(0);
175   });
176 });