]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { HttpClientTestingModule } from '@angular/common/http/testing'; |
2 | import { NO_ERRORS_SCHEMA } from '@angular/core'; | |
3 | import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
e306af50 | 4 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
11fdf7f2 TL |
5 | import { RouterTestingModule } from '@angular/router/testing'; |
6 | ||
f67539c2 | 7 | import { of } from 'rxjs'; |
11fdf7f2 | 8 | |
f67539c2 TL |
9 | import { RgwUserService } from '~/app/shared/api/rgw-user.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'; | |
11fdf7f2 TL |
13 | import { RgwUserListComponent } from './rgw-user-list.component'; |
14 | ||
15 | describe('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 | }); |