]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
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 | ||
f67539c2 TL |
6 | import { NgbAlertModule } from '@ng-bootstrap/ng-bootstrap'; |
7 | import { of } from 'rxjs'; | |
11fdf7f2 | 8 | |
f67539c2 TL |
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'; | |
9f95a23c | 13 | import { AlertPanelComponent } from '../alert-panel/alert-panel.component'; |
f6b5b4d7 | 14 | import { DocComponent } from '../doc/doc.component'; |
11fdf7f2 TL |
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>; | |
b3b6e05e TL |
21 | const expected_url = |
22 | 'http:localhost:3000/d/foo/somePath&refresh=2s&var-datasource=Dashboard1&kiosk&from=now-1h&to=now'; | |
2a845540 | 23 | const expected_logs_url = |
f38dd50b | 24 | 'http:localhost:3000/explore?orgId=1&left={"datasource": "Loki", "queries": [{"refId": "A"}], "range": {"from": "now-1h", "to": "now"}}&kiosk'; |
11fdf7f2 TL |
25 | |
26 | configureTestBed({ | |
f6b5b4d7 | 27 | declarations: [GrafanaComponent, AlertPanelComponent, LoadingPanelComponent, DocComponent], |
f67539c2 TL |
28 | imports: [NgbAlertModule, HttpClientTestingModule, RouterTestingModule, FormsModule], |
29 | providers: [CephReleaseNamePipe, SettingsService, SummaryService] | |
11fdf7f2 TL |
30 | }); |
31 | ||
32 | beforeEach(() => { | |
33 | fixture = TestBed.createComponent(GrafanaComponent); | |
34 | component = fixture.componentInstance; | |
35 | component.grafanaPath = 'somePath'; | |
2a845540 | 36 | component.type = 'metrics'; |
11fdf7f2 | 37 | component.uid = 'foo'; |
39ae355f | 38 | component.title = 'panel title'; |
11fdf7f2 TL |
39 | }); |
40 | ||
41 | it('should create', () => { | |
42 | expect(component).toBeTruthy(); | |
43 | }); | |
44 | ||
45 | it('should have found out that grafana does not exist', () => { | |
46 | fixture.detectChanges(); | |
47 | expect(component.grafanaExist).toBe(false); | |
48 | expect(component.baseUrl).toBe(undefined); | |
49 | expect(component.loading).toBe(true); | |
50 | expect(component.url).toBe(undefined); | |
51 | expect(component.grafanaSrc).toEqual(undefined); | |
52 | }); | |
53 | ||
54 | describe('with grafana initialized', () => { | |
55 | beforeEach(() => { | |
f67539c2 | 56 | TestBed.inject(SettingsService)['settings'] = { 'api/grafana/url': 'http:localhost:3000' }; |
2a845540 | 57 | component.type = 'metrics'; |
11fdf7f2 TL |
58 | fixture.detectChanges(); |
59 | }); | |
60 | ||
61 | it('should have found out that grafana exists and dashboard exists', () => { | |
62 | expect(component.time).toBe('from=now-1h&to=now'); | |
63 | expect(component.grafanaExist).toBe(true); | |
64 | expect(component.baseUrl).toBe('http:localhost:3000/d/'); | |
65 | expect(component.loading).toBe(false); | |
b3b6e05e | 66 | expect(component.url).toBe(expected_url); |
11fdf7f2 | 67 | expect(component.grafanaSrc).toEqual({ |
b3b6e05e | 68 | changingThisBreaksApplicationSecurity: expected_url |
11fdf7f2 TL |
69 | }); |
70 | }); | |
71 | ||
72 | it('should reset the values', () => { | |
73 | component.reset(); | |
74 | expect(component.time).toBe('from=now-1h&to=now'); | |
b3b6e05e | 75 | expect(component.url).toBe(expected_url); |
11fdf7f2 | 76 | expect(component.grafanaSrc).toEqual({ |
b3b6e05e | 77 | changingThisBreaksApplicationSecurity: expected_url |
11fdf7f2 TL |
78 | }); |
79 | }); | |
80 | ||
81 | it('should have Dashboard', () => { | |
f67539c2 | 82 | TestBed.inject(SettingsService).validateGrafanaDashboardUrl = () => of({ uid: 200 }); |
11fdf7f2 TL |
83 | expect(component.dashboardExist).toBe(true); |
84 | }); | |
85 | }); | |
2a845540 TL |
86 | |
87 | describe('with loki datasource', () => { | |
88 | beforeEach(() => { | |
89 | TestBed.inject(SettingsService)['settings'] = { 'api/grafana/url': 'http:localhost:3000' }; | |
90 | component.type = 'logs'; | |
91 | component.grafanaPath = 'explore?'; | |
92 | fixture.detectChanges(); | |
93 | }); | |
94 | ||
95 | it('should have found out that Loki Log Search exists', () => { | |
96 | expect(component.grafanaExist).toBe(true); | |
97 | expect(component.baseUrl).toBe('http:localhost:3000/d/'); | |
98 | expect(component.loading).toBe(false); | |
99 | expect(component.url).toBe(expected_logs_url); | |
100 | expect(component.grafanaSrc).toEqual({ | |
101 | changingThisBreaksApplicationSecurity: expected_logs_url | |
102 | }); | |
103 | }); | |
104 | }); | |
11fdf7f2 | 105 | }); |