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