]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
3739b8f541ce10c00c8abd7f72c1b78e29ba9082
[ceph-ci.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { By } from '@angular/platform-browser';
4 import { RouterTestingModule } from '@angular/router/testing';
5
6 import { ToastModule } from 'ng2-toastr';
7
8 import {
9   configureTestBed,
10   i18nProviders,
11   PermissionHelper
12 } from '../../../../testing/unit-test-helper';
13 import { TableActionsComponent } from '../../../shared/datatable/table-actions/table-actions.component';
14 import { SharedModule } from '../../../shared/shared.module';
15 import { MgrModulesListComponent } from './mgr-modules-list.component';
16
17 describe('MgrModulesListComponent', () => {
18   let component: MgrModulesListComponent;
19   let fixture: ComponentFixture<MgrModulesListComponent>;
20
21   configureTestBed({
22     declarations: [MgrModulesListComponent],
23     imports: [RouterTestingModule, SharedModule, HttpClientTestingModule, ToastModule.forRoot()],
24     providers: i18nProviders
25   });
26
27   beforeEach(() => {
28     fixture = TestBed.createComponent(MgrModulesListComponent);
29     component = fixture.componentInstance;
30   });
31
32   it('should create', () => {
33     fixture.detectChanges();
34     expect(component).toBeTruthy();
35   });
36
37   describe('show action buttons and drop down actions depending on permissions', () => {
38     let tableActions: TableActionsComponent;
39     let scenario: { fn; empty; single };
40     let permissionHelper: PermissionHelper;
41
42     const getTableActionComponent = (): TableActionsComponent => {
43       fixture.detectChanges();
44       return fixture.debugElement.query(By.directive(TableActionsComponent)).componentInstance;
45     };
46
47     beforeEach(() => {
48       permissionHelper = new PermissionHelper(component.permission, () =>
49         getTableActionComponent()
50       );
51       scenario = {
52         fn: () => tableActions.getCurrentButton().name,
53         single: 'Edit',
54         empty: 'Edit'
55       };
56     });
57
58     describe('with read and update', () => {
59       beforeEach(() => {
60         tableActions = permissionHelper.setPermissionsAndGetActions(0, 1, 0);
61       });
62
63       it('shows action button', () => permissionHelper.testScenarios(scenario));
64
65       it('shows all actions', () => {
66         expect(tableActions.tableActions.length).toBe(3);
67         expect(tableActions.tableActions).toEqual(component.tableActions);
68       });
69     });
70
71     describe('with only read', () => {
72       beforeEach(() => {
73         tableActions = permissionHelper.setPermissionsAndGetActions(0, 0, 0);
74       });
75
76       it('shows no main action', () => {
77         permissionHelper.testScenarios({
78           fn: () => tableActions.getCurrentButton(),
79           single: undefined,
80           empty: undefined
81         });
82       });
83
84       it('shows no actions', () => {
85         expect(tableActions.tableActions.length).toBe(0);
86         expect(tableActions.tableActions).toEqual([]);
87       });
88     });
89   });
90 });