]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-bucket-list/rgw-bucket-list.component.spec.ts
import ceph pacific 16.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / rgw / rgw-bucket-list / rgw-bucket-list.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 { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
7 import { of } from 'rxjs';
8
9 import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service';
10 import { TableActionsComponent } from '~/app/shared/datatable/table-actions/table-actions.component';
11 import { SharedModule } from '~/app/shared/shared.module';
12 import { configureTestBed, PermissionHelper } from '~/testing/unit-test-helper';
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([]));
37 fixture = TestBed.createComponent(RgwBucketListComponent);
38 component = fixture.componentInstance;
39 spyOn(component, 'timeConditionReached').and.stub();
40 fixture.detectChanges();
41 });
42
43 it('should create', () => {
44 expect(component).toBeTruthy();
45 expect(rgwBucketServiceListSpy).toHaveBeenCalledTimes(1);
46 });
47
48 it('should test all TableActions combinations', () => {
49 const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
50 const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
51 component.tableActions
52 );
53
54 expect(tableActions).toEqual({
55 'create,update,delete': {
56 actions: ['Create', 'Edit', 'Delete'],
57 primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Create' }
58 },
59 'create,update': {
60 actions: ['Create', 'Edit'],
61 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
62 },
63 'create,delete': {
64 actions: ['Create', 'Delete'],
65 primary: { multiple: 'Delete', executing: 'Create', single: 'Create', no: 'Create' }
66 },
67 create: {
68 actions: ['Create'],
69 primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
70 },
71 'update,delete': {
72 actions: ['Edit', 'Delete'],
73 primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Edit' }
74 },
75 update: {
76 actions: ['Edit'],
77 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
78 },
79 delete: {
80 actions: ['Delete'],
81 primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
82 },
83 'no-permissions': {
84 actions: [],
85 primary: { multiple: '', executing: '', single: '', no: '' }
86 }
87 });
88 });
89
90 it('should test if bucket data is tranformed correctly', () => {
91 rgwBucketServiceListSpy.and.returnValue(
92 of([
93 {
94 bucket: 'bucket',
95 owner: 'testid',
96 usage: {
97 'rgw.main': {
98 size_actual: 4,
99 num_objects: 2
100 },
101 'rgw.none': {
102 size_actual: 6,
103 num_objects: 6
104 }
105 },
106 bucket_quota: {
107 max_size: 20,
108 max_objects: 10,
109 enabled: true
110 }
111 }
112 ])
113 );
114 component.getBucketList(null);
115 expect(rgwBucketServiceListSpy).toHaveBeenCalledTimes(2);
116 expect(component.buckets).toEqual([
117 {
118 bucket: 'bucket',
119 owner: 'testid',
120 usage: {
121 'rgw.main': { size_actual: 4, num_objects: 2 },
122 'rgw.none': { size_actual: 6, num_objects: 6 }
123 },
124 bucket_quota: {
125 max_size: 20,
126 max_objects: 10,
127 enabled: true
128 },
129 bucket_size: 4,
130 num_objects: 2,
131 size_usage: 0.2,
132 object_usage: 0.2
133 }
134 ]);
135 });
136
137 it('should usage bars only if quota enabled', () => {
138 rgwBucketServiceListSpy.and.returnValue(
139 of([
140 {
141 bucket: 'bucket',
142 owner: 'testid',
143 bucket_quota: {
144 max_size: 1024,
145 max_objects: 10,
146 enabled: true
147 }
148 }
149 ])
150 );
151 component.getBucketList(null);
152 expect(rgwBucketServiceListSpy).toHaveBeenCalledTimes(2);
153 fixture.detectChanges();
154 const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
155 expect(usageBars.length).toBe(2);
156 });
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 component.getBucketList(null);
173 expect(rgwBucketServiceListSpy).toHaveBeenCalledTimes(2);
174 fixture.detectChanges();
175 const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
176 expect(usageBars.length).toBe(0);
177 });
178 });