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 { 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 import { ToastrModule } from 'ngx-toastr';
17 describe('RgwBucketListComponent', () => {
18 let component: RgwBucketListComponent;
19 let fixture: ComponentFixture<RgwBucketListComponent>;
20 let rgwBucketService: RgwBucketService;
21 let rgwBucketServiceListSpy: jasmine.Spy;
24 declarations: [RgwBucketListComponent, RgwBucketDetailsComponent],
26 BrowserAnimationsModule,
30 HttpClientTestingModule,
31 ToastrModule.forRoot()
36 rgwBucketService = TestBed.inject(RgwBucketService);
37 rgwBucketServiceListSpy = spyOn(rgwBucketService, 'list');
38 rgwBucketServiceListSpy.and.returnValue(of([]));
39 fixture = TestBed.createComponent(RgwBucketListComponent);
40 component = fixture.componentInstance;
41 spyOn(component, 'setTableRefreshTimeout').and.stub();
42 fixture.detectChanges();
45 it('should create', () => {
46 expect(component).toBeTruthy();
47 expect(rgwBucketServiceListSpy).toHaveBeenCalledTimes(1);
50 it('should test all TableActions combinations', () => {
51 const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
52 const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
53 component.tableActions
56 expect(tableActions).toEqual({
57 'create,update,delete': {
58 actions: ['Create', 'Edit', 'Delete'],
67 actions: ['Create', 'Edit'],
76 actions: ['Create', 'Delete'],
94 actions: ['Edit', 'Delete'],
132 it('should test if bucket data is transformed correctly', () => {
133 rgwBucketServiceListSpy.and.returnValue(
156 component.getBucketList(null);
157 expect(rgwBucketServiceListSpy).toHaveBeenCalledTimes(2);
158 expect(component.buckets).toEqual([
163 'rgw.main': { size_actual: 4, num_objects: 2 },
164 'rgw.none': { size_actual: 6, num_objects: 6 }
179 it('should usage bars only if quota enabled', () => {
180 rgwBucketServiceListSpy.and.returnValue(
193 component.getBucketList(null);
194 expect(rgwBucketServiceListSpy).toHaveBeenCalledTimes(2);
195 fixture.detectChanges();
196 const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
197 expect(usageBars.length).toBe(2);
200 it('should not show any usage bars if quota disabled', () => {
201 rgwBucketServiceListSpy.and.returnValue(
214 component.getBucketList(null);
215 expect(rgwBucketServiceListSpy).toHaveBeenCalledTimes(2);
216 fixture.detectChanges();
217 const usageBars = fixture.debugElement.nativeElement.querySelectorAll('cd-usage-bar');
218 expect(usageBars.length).toBe(0);