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';
6 import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
7 import { of } from 'rxjs';
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';
20 describe('RgwBucketListComponent', () => {
21 let component: RgwBucketListComponent;
22 let fixture: ComponentFixture<RgwBucketListComponent>;
23 let rgwBucketService: RgwBucketService;
24 let rgwBucketServiceListSpy: jasmine.Spy;
27 declarations: [RgwBucketListComponent, RgwBucketDetailsComponent],
29 BrowserAnimationsModule,
33 HttpClientTestingModule
35 providers: i18nProviders
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;
46 it('should create', () => {
47 fixture.detectChanges();
48 expect(component).toBeTruthy();
51 it('should test all TableActions combinations', () => {
52 const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
53 const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
54 component.tableActions
57 expect(tableActions).toEqual({
58 'create,update,delete': {
59 actions: ['Create', 'Edit', 'Delete'],
60 primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Create' }
63 actions: ['Create', 'Edit'],
64 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
67 actions: ['Create', 'Delete'],
68 primary: { multiple: 'Delete', executing: 'Create', single: 'Create', no: 'Create' }
72 primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
75 actions: ['Edit', 'Delete'],
76 primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Edit' }
80 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
84 primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
88 primary: { multiple: '', executing: '', single: '', no: '' }
93 it('should test if bucket data is tranformed correctly', () => {
94 rgwBucketServiceListSpy.and.returnValue(
117 fixture.detectChanges();
118 expect(component.buckets).toEqual([
123 'rgw.main': { size_actual: 4, num_objects: 2 },
124 'rgw.another': { size_actual: 6, num_objects: 6 }
138 it('should usage bars only if quota enabled', () => {
139 rgwBucketServiceListSpy.and.returnValue(
152 fixture.detectChanges();
153 const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
154 expect(usageBars.length).toBe(2);
156 it('should not show any usage bars if quota disabled', () => {
157 rgwBucketServiceListSpy.and.returnValue(
170 fixture.detectChanges();
171 const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
172 expect(usageBars.length).toBe(0);