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