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