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';
6 import { NgbAlertModule } from '@ng-bootstrap/ng-bootstrap';
7 import { of } from 'rxjs';
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';
18 describe('GrafanaComponent', () => {
19 let component: GrafanaComponent;
20 let fixture: ComponentFixture<GrafanaComponent>;
22 'http:localhost:3000/d/foo/somePath&refresh=2s&var-datasource=Dashboard1&kiosk&from=now-1h&to=now';
23 const expected_logs_url =
24 'http:localhost:3000/explore?orgId=1&left=["now-1h","now","Loki",{"refId":"A"}]&kiosk';
27 declarations: [GrafanaComponent, AlertPanelComponent, LoadingPanelComponent, DocComponent],
28 imports: [NgbAlertModule, HttpClientTestingModule, RouterTestingModule, FormsModule],
29 providers: [CephReleaseNamePipe, SettingsService, SummaryService]
33 fixture = TestBed.createComponent(GrafanaComponent);
34 component = fixture.componentInstance;
35 component.grafanaPath = 'somePath';
36 component.type = 'metrics';
37 component.uid = 'foo';
40 it('should create', () => {
41 expect(component).toBeTruthy();
44 it('should have found out that grafana does not exist', () => {
45 fixture.detectChanges();
46 expect(component.grafanaExist).toBe(false);
47 expect(component.baseUrl).toBe(undefined);
48 expect(component.loading).toBe(true);
49 expect(component.url).toBe(undefined);
50 expect(component.grafanaSrc).toEqual(undefined);
53 describe('with grafana initialized', () => {
55 TestBed.inject(SettingsService)['settings'] = { 'api/grafana/url': 'http:localhost:3000' };
56 component.type = 'metrics';
57 fixture.detectChanges();
60 it('should have found out that grafana exists and dashboard exists', () => {
61 expect(component.time).toBe('from=now-1h&to=now');
62 expect(component.grafanaExist).toBe(true);
63 expect(component.baseUrl).toBe('http:localhost:3000/d/');
64 expect(component.loading).toBe(false);
65 expect(component.url).toBe(expected_url);
66 expect(component.grafanaSrc).toEqual({
67 changingThisBreaksApplicationSecurity: expected_url
71 it('should reset the values', () => {
73 expect(component.time).toBe('from=now-1h&to=now');
74 expect(component.url).toBe(expected_url);
75 expect(component.grafanaSrc).toEqual({
76 changingThisBreaksApplicationSecurity: expected_url
80 it('should have Dashboard', () => {
81 TestBed.inject(SettingsService).validateGrafanaDashboardUrl = () => of({ uid: 200 });
82 expect(component.dashboardExist).toBe(true);
86 describe('with loki datasource', () => {
88 TestBed.inject(SettingsService)['settings'] = { 'api/grafana/url': 'http:localhost:3000' };
89 component.type = 'logs';
90 component.grafanaPath = 'explore?';
91 fixture.detectChanges();
94 it('should have found out that Loki Log Search exists', () => {
95 expect(component.grafanaExist).toBe(true);
96 expect(component.baseUrl).toBe('http:localhost:3000/d/');
97 expect(component.loading).toBe(false);
98 expect(component.url).toBe(expected_logs_url);
99 expect(component.grafanaSrc).toEqual({
100 changingThisBreaksApplicationSecurity: expected_logs_url