]>
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 | ||
6 | import { AlertModule } from 'ngx-bootstrap/alert'; | |
7 | ||
8 | import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper'; | |
9 | import { SummaryService } from '../../../shared/services/summary.service'; | |
10 | import { SettingsService } from '../../api/settings.service'; | |
11 | import { CephReleaseNamePipe } from '../../pipes/ceph-release-name.pipe'; | |
9f95a23c | 12 | import { AlertPanelComponent } from '../alert-panel/alert-panel.component'; |
f6b5b4d7 | 13 | import { DocComponent } from '../doc/doc.component'; |
11fdf7f2 TL |
14 | import { LoadingPanelComponent } from '../loading-panel/loading-panel.component'; |
15 | import { GrafanaComponent } from './grafana.component'; | |
16 | ||
17 | describe('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 | }); |