]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.spec.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / rgw / rgw-user-list / rgw-user-list.component.spec.ts
CommitLineData
11fdf7f2
TL
1import { HttpClientTestingModule } from '@angular/common/http/testing';
2import { NO_ERRORS_SCHEMA } from '@angular/core';
3import { ComponentFixture, TestBed } from '@angular/core/testing';
e306af50 4import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
11fdf7f2
TL
5import { RouterTestingModule } from '@angular/router/testing';
6
f67539c2 7import { of } from 'rxjs';
11fdf7f2 8
f67539c2
TL
9import { RgwUserService } from '~/app/shared/api/rgw-user.service';
10import { TableActionsComponent } from '~/app/shared/datatable/table-actions/table-actions.component';
11import { SharedModule } from '~/app/shared/shared.module';
12import { configureTestBed, PermissionHelper } from '~/testing/unit-test-helper';
11fdf7f2
TL
13import { RgwUserListComponent } from './rgw-user-list.component';
14
15describe('RgwUserListComponent', () => {
16 let component: RgwUserListComponent;
17 let fixture: ComponentFixture<RgwUserListComponent>;
f67539c2
TL
18 let rgwUserService: RgwUserService;
19 let rgwUserServiceListSpy: jasmine.Spy;
11fdf7f2
TL
20
21 configureTestBed({
22 declarations: [RgwUserListComponent],
f67539c2
TL
23 imports: [BrowserAnimationsModule, RouterTestingModule, HttpClientTestingModule, SharedModule],
24 schemas: [NO_ERRORS_SCHEMA]
11fdf7f2
TL
25 });
26
27 beforeEach(() => {
f67539c2
TL
28 rgwUserService = TestBed.inject(RgwUserService);
29 rgwUserServiceListSpy = spyOn(rgwUserService, 'list');
30 rgwUserServiceListSpy.and.returnValue(of([]));
11fdf7f2
TL
31 fixture = TestBed.createComponent(RgwUserListComponent);
32 component = fixture.componentInstance;
f67539c2
TL
33 spyOn(component, 'timeConditionReached').and.stub();
34 fixture.detectChanges();
11fdf7f2
TL
35 });
36
37 it('should create', () => {
11fdf7f2 38 expect(component).toBeTruthy();
f67539c2 39 expect(rgwUserServiceListSpy).toHaveBeenCalledTimes(1);
11fdf7f2
TL
40 });
41
9f95a23c
TL
42 it('should test all TableActions combinations', () => {
43 const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
44 const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
45 component.tableActions
46 );
47
48 expect(tableActions).toEqual({
49 'create,update,delete': {
50 actions: ['Create', 'Edit', 'Delete'],
51 primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Create' }
52 },
53 'create,update': {
54 actions: ['Create', 'Edit'],
55 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
56 },
57 'create,delete': {
58 actions: ['Create', 'Delete'],
59 primary: { multiple: 'Delete', executing: 'Create', single: 'Create', no: 'Create' }
60 },
61 create: {
62 actions: ['Create'],
63 primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
64 },
65 'update,delete': {
66 actions: ['Edit', 'Delete'],
67 primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Edit' }
68 },
69 update: {
70 actions: ['Edit'],
71 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
72 },
73 delete: {
74 actions: ['Delete'],
75 primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
76 },
77 'no-permissions': {
78 actions: [],
79 primary: { multiple: '', executing: '', single: '', no: '' }
80 }
11fdf7f2
TL
81 });
82 });
f67539c2
TL
83
84 it('should test if rgw-user data is tranformed correctly', () => {
85 rgwUserServiceListSpy.and.returnValue(
86 of([
87 {
88 user_id: 'testid',
89 stats: {
90 size_actual: 6,
91 num_objects: 6
92 },
93 user_quota: {
94 max_size: 20,
95 max_objects: 10,
96 enabled: true
97 }
98 }
99 ])
100 );
101 component.getUserList(null);
102 expect(rgwUserServiceListSpy).toHaveBeenCalledTimes(2);
103 expect(component.users).toEqual([
104 {
105 user_id: 'testid',
106 stats: {
107 size_actual: 6,
108 num_objects: 6
109 },
110 user_quota: {
111 max_size: 20,
112 max_objects: 10,
113 enabled: true
114 }
115 }
116 ]);
117 });
118
119 it('should usage bars only if quota enabled', () => {
120 rgwUserServiceListSpy.and.returnValue(
121 of([
122 {
123 user_id: 'testid',
124 stats: {
125 size_actual: 6,
126 num_objects: 6
127 },
128 user_quota: {
129 max_size: 1024,
130 max_objects: 10,
131 enabled: true
132 }
133 }
134 ])
135 );
136 component.getUserList(null);
137 expect(rgwUserServiceListSpy).toHaveBeenCalledTimes(2);
138 fixture.detectChanges();
139 const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
140 expect(usageBars.length).toBe(2);
141 });
142
143 it('should not show any usage bars if quota disabled', () => {
144 rgwUserServiceListSpy.and.returnValue(
145 of([
146 {
147 user_id: 'testid',
148 stats: {
149 size_actual: 6,
150 num_objects: 6
151 },
152 user_quota: {
153 max_size: 1024,
154 max_objects: 10,
155 enabled: false
156 }
157 }
158 ])
159 );
160 component.getUserList(null);
161 expect(rgwUserServiceListSpy).toHaveBeenCalledTimes(2);
162 fixture.detectChanges();
163 const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
164 expect(usageBars.length).toBe(0);
165 });
11fdf7f2 166});