diff options
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.spec.ts')
-rw-r--r-- | src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.spec.ts | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.spec.ts new file mode 100644 index 000000000..b62cd32eb --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/role-details/role-details.component.spec.ts @@ -0,0 +1,67 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; + +import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap'; + +import { SharedModule } from '~/app/shared/shared.module'; +import { configureTestBed } from '~/testing/unit-test-helper'; +import { RoleDetailsComponent } from './role-details.component'; + +describe('RoleDetailsComponent', () => { + let component: RoleDetailsComponent; + let fixture: ComponentFixture<RoleDetailsComponent>; + + configureTestBed({ + imports: [SharedModule, RouterTestingModule, HttpClientTestingModule, NgbNavModule], + declarations: [RoleDetailsComponent] + }); + + beforeEach(() => { + fixture = TestBed.createComponent(RoleDetailsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('should create scopes permissions [1/2]', () => { + component.scopes = ['log', 'rgw']; + component.selection = { + description: 'RGW Manager', + name: 'rgw-manager', + scopes_permissions: { + rgw: ['read', 'create', 'update', 'delete'] + }, + system: true + }; + expect(component.scopes_permissions.length).toBe(0); + component.ngOnChanges(); + expect(component.scopes_permissions).toEqual([ + { scope: 'log', read: false, create: false, update: false, delete: false }, + { scope: 'rgw', read: true, create: true, update: true, delete: true } + ]); + }); + + it('should create scopes permissions [2/2]', () => { + component.scopes = ['cephfs', 'log', 'rgw']; + component.selection = { + description: 'Test', + name: 'test', + scopes_permissions: { + log: ['read', 'update'], + rgw: ['read', 'create', 'update'] + }, + system: false + }; + expect(component.scopes_permissions.length).toBe(0); + component.ngOnChanges(); + expect(component.scopes_permissions).toEqual([ + { scope: 'cephfs', read: false, create: false, update: false, delete: false }, + { scope: 'log', read: true, create: false, update: true, delete: false }, + { scope: 'rgw', read: true, create: true, update: true, delete: false } + ]); + }); +}); |