]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/monitor/monitor.component.spec.ts
import 15.2.1 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / monitor / monitor.component.spec.ts
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { NO_ERRORS_SCHEMA } from '@angular/core';
3 import { ComponentFixture, TestBed } from '@angular/core/testing';
4
5 import { of } from 'rxjs';
6
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>;
14 let getMonitorSpy: jasmine.Spy;
15
16 configureTestBed({
17 imports: [HttpClientTestingModule],
18 declarations: [MonitorComponent],
19 schemas: [NO_ERRORS_SCHEMA],
20 providers: [MonitorService, i18nProviders]
21 });
22
23 beforeEach(() => {
24 fixture = TestBed.createComponent(MonitorComponent);
25 component = fixture.componentInstance;
26 const getMonitorPayload: Record<string, any> = {
27 in_quorum: [
28 {
29 stats: { num_sessions: [[1, 5]] }
30 },
31 {
32 stats: {
33 num_sessions: [
34 [1, 1],
35 [2, 10],
36 [3, 1]
37 ]
38 }
39 },
40 {
41 stats: {
42 num_sessions: [
43 [1, 0],
44 [2, 3]
45 ]
46 }
47 },
48 {
49 stats: {
50 num_sessions: [
51 [1, 2],
52 [2, 1],
53 [3, 7],
54 [4, 5]
55 ]
56 }
57 }
58 ],
59 mon_status: null,
60 out_quorum: []
61 };
62 getMonitorSpy = spyOn(TestBed.get(MonitorService), 'getMonitor').and.returnValue(
63 of(getMonitorPayload)
64 );
65 });
66
67 it('should create', () => {
68 expect(component).toBeTruthy();
69 });
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 });
104 });