]>
Commit | Line | Data |
---|---|---|
92f5a8d4 | 1 | import { HttpClientTestingModule } from '@angular/common/http/testing'; |
11fdf7f2 TL |
2 | import { NO_ERRORS_SCHEMA } from '@angular/core'; |
3 | import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
4 | ||
92f5a8d4 TL |
5 | import { of } from 'rxjs'; |
6 | ||
11fdf7f2 TL |
7 | import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper'; |
8 | import { MonitorService } from '../../../shared/api/monitor.service'; | |
9 | import { MonitorComponent } from './monitor.component'; | |
10 | ||
11 | describe('MonitorComponent', () => { | |
12 | let component: MonitorComponent; | |
13 | let fixture: ComponentFixture<MonitorComponent>; | |
92f5a8d4 | 14 | let getMonitorSpy: jasmine.Spy; |
11fdf7f2 TL |
15 | |
16 | configureTestBed({ | |
92f5a8d4 | 17 | imports: [HttpClientTestingModule], |
11fdf7f2 TL |
18 | declarations: [MonitorComponent], |
19 | schemas: [NO_ERRORS_SCHEMA], | |
92f5a8d4 | 20 | providers: [MonitorService, i18nProviders] |
11fdf7f2 TL |
21 | }); |
22 | ||
23 | beforeEach(() => { | |
24 | fixture = TestBed.createComponent(MonitorComponent); | |
25 | component = fixture.componentInstance; | |
9f95a23c | 26 | const getMonitorPayload: Record<string, any> = { |
92f5a8d4 TL |
27 | in_quorum: [ |
28 | { | |
29 | stats: { num_sessions: [[1, 5]] } | |
30 | }, | |
31 | { | |
801d1391 TL |
32 | stats: { |
33 | num_sessions: [ | |
34 | [1, 1], | |
35 | [2, 10], | |
36 | [3, 1] | |
37 | ] | |
38 | } | |
92f5a8d4 TL |
39 | }, |
40 | { | |
801d1391 TL |
41 | stats: { |
42 | num_sessions: [ | |
43 | [1, 0], | |
44 | [2, 3] | |
45 | ] | |
46 | } | |
92f5a8d4 TL |
47 | }, |
48 | { | |
801d1391 TL |
49 | stats: { |
50 | num_sessions: [ | |
51 | [1, 2], | |
52 | [2, 1], | |
53 | [3, 7], | |
54 | [4, 5] | |
55 | ] | |
56 | } | |
92f5a8d4 TL |
57 | } |
58 | ], | |
59 | mon_status: null, | |
60 | out_quorum: [] | |
61 | }; | |
62 | getMonitorSpy = spyOn(TestBed.get(MonitorService), 'getMonitor').and.returnValue( | |
63 | of(getMonitorPayload) | |
64 | ); | |
11fdf7f2 TL |
65 | }); |
66 | ||
67 | it('should create', () => { | |
68 | expect(component).toBeTruthy(); | |
69 | }); | |
92f5a8d4 TL |
70 | |
71 | it('should sort by open sessions column correctly', () => { | |
72 | component.refresh(); | |
73 | ||
74 | expect(getMonitorSpy).toHaveBeenCalled(); | |
75 | ||
76 | expect(component.inQuorum.columns[3].comparator(undefined, undefined)).toBe(0); | |
77 | expect(component.inQuorum.columns[3].comparator(null, null)).toBe(0); | |
78 | expect(component.inQuorum.columns[3].comparator([], [])).toBe(0); | |
79 | expect( | |
80 | component.inQuorum.columns[3].comparator( | |
81 | component.inQuorum.data[0].cdOpenSessions, | |
82 | component.inQuorum.data[3].cdOpenSessions | |
83 | ) | |
84 | ).toBe(0); | |
85 | expect( | |
86 | component.inQuorum.columns[3].comparator( | |
87 | component.inQuorum.data[0].cdOpenSessions, | |
88 | component.inQuorum.data[1].cdOpenSessions | |
89 | ) | |
90 | ).toBe(1); | |
91 | expect( | |
92 | component.inQuorum.columns[3].comparator( | |
93 | component.inQuorum.data[1].cdOpenSessions, | |
94 | component.inQuorum.data[0].cdOpenSessions | |
95 | ) | |
96 | ).toBe(-1); | |
97 | expect( | |
98 | component.inQuorum.columns[3].comparator( | |
99 | component.inQuorum.data[2].cdOpenSessions, | |
100 | component.inQuorum.data[1].cdOpenSessions | |
101 | ) | |
102 | ).toBe(1); | |
103 | }); | |
11fdf7f2 | 104 | }); |