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