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