]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | import { NgZone } from '@angular/core'; |
2 | import { fakeAsync, TestBed, tick } from '@angular/core/testing'; | |
11fdf7f2 | 3 | |
f67539c2 | 4 | import { configureTestBed } from '~/testing/unit-test-helper'; |
11fdf7f2 TL |
5 | import { RefreshIntervalService } from './refresh-interval.service'; |
6 | ||
7 | describe('RefreshIntervalService', () => { | |
8 | let service: RefreshIntervalService; | |
9 | ||
9f95a23c | 10 | configureTestBed({ |
9f95a23c TL |
11 | providers: [RefreshIntervalService] |
12 | }); | |
13 | ||
11fdf7f2 | 14 | beforeEach(() => { |
f67539c2 | 15 | service = TestBed.inject(RefreshIntervalService); |
11fdf7f2 TL |
16 | }); |
17 | ||
18 | it('should be created', () => { | |
19 | expect(service).toBeTruthy(); | |
20 | }); | |
21 | ||
22 | it('should initial private interval time right', () => { | |
23 | sessionStorage.setItem('dashboard_interval', '10000'); | |
f67539c2 | 24 | const ngZone = TestBed.inject(NgZone); |
9f95a23c | 25 | service = new RefreshIntervalService(ngZone); |
11fdf7f2 TL |
26 | expect(service.getRefreshInterval()).toBe(10000); |
27 | }); | |
28 | ||
29 | describe('setRefreshInterval', () => { | |
30 | let notifyCount: number; | |
31 | ||
32 | it('should send notification to component at correct interval time when interval changed', fakeAsync(() => { | |
33 | service.intervalData$.subscribe(() => { | |
34 | notifyCount++; | |
35 | }); | |
36 | ||
37 | notifyCount = 0; | |
38 | service.setRefreshInterval(10000); | |
39 | tick(10000); | |
40 | expect(service.getRefreshInterval()).toBe(10000); | |
41 | expect(notifyCount).toBe(1); | |
42 | ||
43 | notifyCount = 0; | |
44 | service.setRefreshInterval(30000); | |
45 | tick(30000); | |
46 | expect(service.getRefreshInterval()).toBe(30000); | |
47 | expect(notifyCount).toBe(1); | |
48 | ||
49 | service.ngOnDestroy(); | |
50 | })); | |
51 | }); | |
52 | }); |