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';
25 declarations: [GrafanaComponent, AlertPanelComponent, LoadingPanelComponent, DocComponent],
26 imports: [NgbAlertModule, HttpClientTestingModule, RouterTestingModule, FormsModule],
27 providers: [CephReleaseNamePipe, SettingsService, SummaryService]
31 fixture = TestBed.createComponent(GrafanaComponent);
32 component = fixture.componentInstance;
33 component.grafanaPath = 'somePath';
34 component.uid = 'foo';
37 it('should create', () => {
38 expect(component).toBeTruthy();
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);
50 describe('with grafana initialized', () => {
52 TestBed.inject(SettingsService)['settings'] = { 'api/grafana/url': 'http:localhost:3000' };
53 fixture.detectChanges();
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
67 it('should reset the values', () => {
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
76 it('should have Dashboard', () => {
77 TestBed.inject(SettingsService).validateGrafanaDashboardUrl = () => of({ uid: 200 });
78 expect(component.dashboardExist).toBe(true);