]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
5bfd2898866af76796f6ee52369952ddc01b612d
[ceph-ci.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
4 import { RouterTestingModule } from '@angular/router/testing';
5
6 import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
7 import { ToastrModule } from 'ngx-toastr';
8
9 import { CephModule } from '~/app/ceph/ceph.module';
10 import { ClusterModule } from '~/app/ceph/cluster/cluster.module';
11 import { DashboardModule } from '~/app/ceph/dashboard/dashboard.module';
12 import { CoreModule } from '~/app/core/core.module';
13 import { TableActionsComponent } from '~/app/shared/datatable/table-actions/table-actions.component';
14 import { SharedModule } from '~/app/shared/shared.module';
15 import { configureTestBed, PermissionHelper } from '~/testing/unit-test-helper';
16 import { ActiveAlertListComponent } from './active-alert-list.component';
17 import { PrometheusAlertService } from '~/app/shared/services/prometheus-alert.service';
18 import { of } from 'rxjs';
19
20 describe('ActiveAlertListComponent', () => {
21   let component: ActiveAlertListComponent;
22   let fixture: ComponentFixture<ActiveAlertListComponent>;
23
24   configureTestBed({
25     imports: [
26       BrowserAnimationsModule,
27       HttpClientTestingModule,
28       NgbNavModule,
29       RouterTestingModule,
30       ToastrModule.forRoot(),
31       SharedModule,
32       ClusterModule,
33       DashboardModule,
34       CephModule,
35       CoreModule
36     ]
37   });
38
39   beforeEach(() => {
40     fixture = TestBed.createComponent(ActiveAlertListComponent);
41     component = fixture.componentInstance;
42     let prometheusAlertService = TestBed.inject(PrometheusAlertService);
43     spyOn(prometheusAlertService, 'getAlerts').and.callFake(() => of([]));
44   });
45
46   it('should create', () => {
47     fixture.detectChanges();
48     expect(component).toBeTruthy();
49   });
50
51   it('should test all TableActions combinations', () => {
52     component.ngOnInit();
53     const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
54     const tableActions: TableActionsComponent = permissionHelper.setPermissionsAndGetActions(
55       component.tableActions
56     );
57
58     expect(tableActions).toEqual({
59       'create,update,delete': {
60         actions: ['Create Silence'],
61         primary: {
62           multiple: 'Create Silence',
63           executing: 'Create Silence',
64           single: 'Create Silence',
65           no: 'Create Silence'
66         }
67       },
68       'create,update': {
69         actions: ['Create Silence'],
70         primary: {
71           multiple: 'Create Silence',
72           executing: 'Create Silence',
73           single: 'Create Silence',
74           no: 'Create Silence'
75         }
76       },
77       'create,delete': {
78         actions: ['Create Silence'],
79         primary: {
80           multiple: 'Create Silence',
81           executing: 'Create Silence',
82           single: 'Create Silence',
83           no: 'Create Silence'
84         }
85       },
86       create: {
87         actions: ['Create Silence'],
88         primary: {
89           multiple: 'Create Silence',
90           executing: 'Create Silence',
91           single: 'Create Silence',
92           no: 'Create Silence'
93         }
94       },
95       'update,delete': {
96         actions: [],
97         primary: { multiple: '', executing: '', single: '', no: '' }
98       },
99       update: { actions: [], primary: { multiple: '', executing: '', single: '', no: '' } },
100       delete: { actions: [], primary: { multiple: '', executing: '', single: '', no: '' } },
101       'no-permissions': {
102         actions: [],
103         primary: { multiple: '', executing: '', single: '', no: '' }
104       }
105     });
106   });
107 });