]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/grafana/grafana.component.spec.ts
import 15.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / components / grafana / grafana.component.spec.ts
CommitLineData
11fdf7f2
TL
1import { HttpClientTestingModule } from '@angular/common/http/testing';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
3import { FormsModule } from '@angular/forms';
4import { RouterTestingModule } from '@angular/router/testing';
5
6import { AlertModule } from 'ngx-bootstrap/alert';
7
8import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
9import { SummaryService } from '../../../shared/services/summary.service';
10import { SettingsService } from '../../api/settings.service';
11import { CephReleaseNamePipe } from '../../pipes/ceph-release-name.pipe';
9f95a23c 12import { AlertPanelComponent } from '../alert-panel/alert-panel.component';
f6b5b4d7 13import { DocComponent } from '../doc/doc.component';
11fdf7f2
TL
14import { LoadingPanelComponent } from '../loading-panel/loading-panel.component';
15import { GrafanaComponent } from './grafana.component';
16
17describe('GrafanaComponent', () => {
18 let component: GrafanaComponent;
19 let fixture: ComponentFixture<GrafanaComponent>;
20
21 configureTestBed({
f6b5b4d7 22 declarations: [GrafanaComponent, AlertPanelComponent, LoadingPanelComponent, DocComponent],
11fdf7f2
TL
23 imports: [AlertModule.forRoot(), HttpClientTestingModule, RouterTestingModule, FormsModule],
24 providers: [CephReleaseNamePipe, SettingsService, SummaryService, i18nProviders]
25 });
26
27 beforeEach(() => {
28 fixture = TestBed.createComponent(GrafanaComponent);
29 component = fixture.componentInstance;
30 component.grafanaPath = 'somePath';
31 component.uid = 'foo';
32 });
33
34 it('should create', () => {
35 expect(component).toBeTruthy();
36 });
37
38 it('should have found out that grafana does not exist', () => {
39 fixture.detectChanges();
40 expect(component.grafanaExist).toBe(false);
41 expect(component.baseUrl).toBe(undefined);
42 expect(component.loading).toBe(true);
43 expect(component.url).toBe(undefined);
44 expect(component.grafanaSrc).toEqual(undefined);
45 });
46
47 describe('with grafana initialized', () => {
48 beforeEach(() => {
49 TestBed.get(SettingsService).settings = { 'api/grafana/url': 'http:localhost:3000' };
50 fixture.detectChanges();
51 });
52
53 it('should have found out that grafana exists and dashboard exists', () => {
54 expect(component.time).toBe('from=now-1h&to=now');
55 expect(component.grafanaExist).toBe(true);
56 expect(component.baseUrl).toBe('http:localhost:3000/d/');
57 expect(component.loading).toBe(false);
58 expect(component.url).toBe(
59 'http:localhost:3000/d/foo/somePath&refresh=2s&kiosk&from=now-1h&to=now'
60 );
61 expect(component.grafanaSrc).toEqual({
62 changingThisBreaksApplicationSecurity:
63 'http:localhost:3000/d/foo/somePath&refresh=2s&kiosk&from=now-1h&to=now'
64 });
65 });
66
67 it('should reset the values', () => {
68 component.reset();
69 expect(component.time).toBe('from=now-1h&to=now');
70 expect(component.url).toBe(
71 'http:localhost:3000/d/foo/somePath&refresh=2s&kiosk&from=now-1h&to=now'
72 );
73 expect(component.grafanaSrc).toEqual({
74 changingThisBreaksApplicationSecurity:
75 'http:localhost:3000/d/foo/somePath&refresh=2s&kiosk&from=now-1h&to=now'
76 });
77 });
78
79 it('should have Dashboard', () => {
80 TestBed.get(SettingsService).validateGrafanaDashboardUrl = { uid: 200 };
81 expect(component.dashboardExist).toBe(true);
82 });
83 });
84});