]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.spec.ts
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / auth / role-details / role-details.component.spec.ts
CommitLineData
11fdf7f2
TL
1import { HttpClientTestingModule } from '@angular/common/http/testing';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
3import { RouterTestingModule } from '@angular/router/testing';
4
11fdf7f2
TL
5import { TabsModule } from 'ngx-bootstrap/tabs';
6
7import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
8import { CdTableSelection } from '../../../shared/models/cd-table-selection';
9import { SharedModule } from '../../../shared/shared.module';
10import { RoleDetailsComponent } from './role-details.component';
11
12describe('RoleDetailsComponent', () => {
13 let component: RoleDetailsComponent;
14 let fixture: ComponentFixture<RoleDetailsComponent>;
15
16 configureTestBed({
494da23a 17 imports: [SharedModule, TabsModule.forRoot(), RouterTestingModule, HttpClientTestingModule],
11fdf7f2
TL
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 component.selection.selected = [
36 {
37 description: 'RGW Manager',
38 name: 'rgw-manager',
39 scopes_permissions: {
40 rgw: ['read', 'create', 'update', 'delete']
41 },
42 system: true
43 }
44 ];
45 component.selection.update();
46 expect(component.scopes_permissions.length).toBe(0);
47 component.ngOnChanges();
48 expect(component.scopes_permissions).toEqual([
49 { scope: 'log', read: false, create: false, update: false, delete: false },
50 { scope: 'rgw', read: true, create: true, update: true, delete: true }
51 ]);
52 });
53
54 it('should create scopes permissions [2/2]', () => {
55 component.scopes = ['cephfs', 'log', 'rgw'];
56 component.selection = new CdTableSelection();
57 component.selection.selected = [
58 {
59 description: 'Test',
60 name: 'test',
61 scopes_permissions: {
62 log: ['read', 'update'],
63 rgw: ['read', 'create', 'update']
64 },
65 system: false
66 }
67 ];
68 component.selection.update();
69 expect(component.scopes_permissions.length).toBe(0);
70 component.ngOnChanges();
71 expect(component.scopes_permissions).toEqual([
72 { scope: 'cephfs', read: false, create: false, update: false, delete: false },
73 { scope: 'log', read: true, create: false, update: true, delete: false },
74 { scope: 'rgw', read: true, create: true, update: true, delete: false }
75 ]);
76 });
77});