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';
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';
16 describe('RgwBucketListComponent', () => {
17 let component: RgwBucketListComponent;
18 let fixture: ComponentFixture<RgwBucketListComponent>;
19 let rgwBucketService: RgwBucketService;
20 let rgwBucketServiceListSpy: jasmine.Spy;
23 declarations: [RgwBucketListComponent, RgwBucketDetailsComponent],
25 BrowserAnimationsModule,
29 HttpClientTestingModule
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;
41 it('should create', () => {
42 fixture.detectChanges();
43 expect(component).toBeTruthy();
46 it('should test all TableActions combinations', () => {
47 const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
48 const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
49 component.tableActions
52 expect(tableActions).toEqual({
53 'create,update,delete': {
54 actions: ['Create', 'Edit', 'Delete'],
55 primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Create' }
58 actions: ['Create', 'Edit'],
59 primary: { multiple: 'Create', executing: 'Edit', single: 'Edit', no: 'Create' }
62 actions: ['Create', 'Delete'],
63 primary: { multiple: 'Delete', executing: 'Create', single: 'Create', no: 'Create' }
67 primary: { multiple: 'Create', executing: 'Create', single: 'Create', no: 'Create' }
70 actions: ['Edit', 'Delete'],
71 primary: { multiple: 'Delete', executing: 'Edit', single: 'Edit', no: 'Edit' }
75 primary: { multiple: 'Edit', executing: 'Edit', single: 'Edit', no: 'Edit' }
79 primary: { multiple: 'Delete', executing: 'Delete', single: 'Delete', no: 'Delete' }
83 primary: { multiple: '', executing: '', single: '', no: '' }
88 it('should test if bucket data is tranformed correctly', () => {
89 rgwBucketServiceListSpy.and.returnValue(
112 fixture.detectChanges();
113 expect(component.buckets).toEqual([
118 'rgw.main': { size_actual: 4, num_objects: 2 },
119 'rgw.another': { size_actual: 6, num_objects: 6 }
133 it('should usage bars only if quota enabled', () => {
134 rgwBucketServiceListSpy.and.returnValue(
147 fixture.detectChanges();
148 const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
149 expect(usageBars.length).toBe(2);
151 it('should not show any usage bars if quota disabled', () => {
152 rgwBucketServiceListSpy.and.returnValue(
165 fixture.detectChanges();
166 const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
167 expect(usageBars.length).toBe(0);