1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { RouterTestingModule } from '@angular/router/testing';
5 import { ToastModule } from 'ng2-toastr';
6 import { TabsModule } from 'ngx-bootstrap/tabs';
8 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
9 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
10 import { SharedModule } from '../../../shared/shared.module';
11 import { RoleDetailsComponent } from './role-details.component';
13 describe('RoleDetailsComponent', () => {
14 let component: RoleDetailsComponent;
15 let fixture: ComponentFixture<RoleDetailsComponent>;
20 ToastModule.forRoot(),
23 HttpClientTestingModule
25 declarations: [RoleDetailsComponent],
26 providers: i18nProviders
30 fixture = TestBed.createComponent(RoleDetailsComponent);
31 component = fixture.componentInstance;
32 fixture.detectChanges();
35 it('should create', () => {
36 expect(component).toBeTruthy();
39 it('should create scopes permissions [1/2]', () => {
40 component.scopes = ['log', 'rgw'];
41 component.selection = new CdTableSelection();
42 component.selection.selected = [
44 description: 'RGW Manager',
47 rgw: ['read', 'create', 'update', 'delete']
52 component.selection.update();
53 expect(component.scopes_permissions.length).toBe(0);
54 component.ngOnChanges();
55 expect(component.scopes_permissions).toEqual([
56 { scope: 'log', read: false, create: false, update: false, delete: false },
57 { scope: 'rgw', read: true, create: true, update: true, delete: true }
61 it('should create scopes permissions [2/2]', () => {
62 component.scopes = ['cephfs', 'log', 'rgw'];
63 component.selection = new CdTableSelection();
64 component.selection.selected = [
69 log: ['read', 'update'],
70 rgw: ['read', 'create', 'update']
75 component.selection.update();
76 expect(component.scopes_permissions.length).toBe(0);
77 component.ngOnChanges();
78 expect(component.scopes_permissions).toEqual([
79 { scope: 'cephfs', read: false, create: false, update: false, delete: false },
80 { scope: 'log', read: true, create: false, update: true, delete: false },
81 { scope: 'rgw', read: true, create: true, update: true, delete: false }