]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.spec.ts
74f0ff400897329d8ce4619b32f70bbcd405cd57
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / auth / role-details / role-details.component.spec.ts
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { RouterTestingModule } from '@angular/router/testing';
4
5 import { TabsModule } from 'ngx-bootstrap/tabs';
6
7 import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
8 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
9 import { SharedModule } from '../../../shared/shared.module';
10 import { RoleDetailsComponent } from './role-details.component';
11
12 describe('RoleDetailsComponent', () => {
13 let component: RoleDetailsComponent;
14 let fixture: ComponentFixture<RoleDetailsComponent>;
15
16 configureTestBed({
17 imports: [SharedModule, TabsModule.forRoot(), RouterTestingModule, HttpClientTestingModule],
18 declarations: [RoleDetailsComponent],
19 providers: i18nProviders
20 });
21
22 beforeEach(() => {
23 fixture = TestBed.createComponent(RoleDetailsComponent);
24 component = fixture.componentInstance;
25 fixture.detectChanges();
26 });
27
28 it('should create', () => {
29 expect(component).toBeTruthy();
30 });
31
32 it('should create scopes permissions [1/2]', () => {
33 component.scopes = ['log', 'rgw'];
34 component.selection = new CdTableSelection([
35 {
36 description: 'RGW Manager',
37 name: 'rgw-manager',
38 scopes_permissions: {
39 rgw: ['read', 'create', 'update', 'delete']
40 },
41 system: true
42 }
43 ]);
44 expect(component.scopes_permissions.length).toBe(0);
45 component.ngOnChanges();
46 expect(component.scopes_permissions).toEqual([
47 { scope: 'log', read: false, create: false, update: false, delete: false },
48 { scope: 'rgw', read: true, create: true, update: true, delete: true }
49 ]);
50 });
51
52 it('should create scopes permissions [2/2]', () => {
53 component.scopes = ['cephfs', 'log', 'rgw'];
54 component.selection = new CdTableSelection([
55 {
56 description: 'Test',
57 name: 'test',
58 scopes_permissions: {
59 log: ['read', 'update'],
60 rgw: ['read', 'create', 'update']
61 },
62 system: false
63 }
64 ]);
65 expect(component.scopes_permissions.length).toBe(0);
66 component.ngOnChanges();
67 expect(component.scopes_permissions).toEqual([
68 { scope: 'cephfs', read: false, create: false, update: false, delete: false },
69 { scope: 'log', read: true, create: false, update: true, delete: false },
70 { scope: 'rgw', read: true, create: true, update: true, delete: false }
71 ]);
72 });
73 });