summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mgr-summary.pipe.spec.ts
blob: 8bc2753808e5eb47cf9b932c63331bfc4a07c006 (plain)
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
import { TestBed } from '@angular/core/testing';

import { configureTestBed } from '~/testing/unit-test-helper';
import { MgrSummaryPipe } from './mgr-summary.pipe';

describe('MgrSummaryPipe', () => {
  let pipe: MgrSummaryPipe;

  configureTestBed({
    providers: [MgrSummaryPipe]
  });

  beforeEach(() => {
    pipe = TestBed.inject(MgrSummaryPipe);
  });

  it('create an instance', () => {
    expect(pipe).toBeTruthy();
  });

  it('transforms without value', () => {
    expect(pipe.transform(undefined)).toBe('');
  });

  it('transforms with active_name undefined', () => {
    const payload: Record<string, any> = {
      active_name: undefined,
      standbys: []
    };
    const expected = [
      { class: 'popover-info', content: 'n/a active', titleText: '' },
      { class: 'card-text-line-break', content: '', titleText: '' },
      { class: 'popover-info', content: '0 standby', titleText: '' }
    ];

    expect(pipe.transform(payload)).toEqual(expected);
  });

  it('transforms with 1 active and 2 standbys', () => {
    const payload = {
      active_name: 'x',
      standbys: [{ name: 'y' }, { name: 'z' }]
    };
    const expected = [
      { class: 'popover-info', content: '1 active', titleText: 'active daemon: x' },
      { class: 'card-text-line-break', content: '', titleText: '' },
      { class: 'popover-info', content: '2 standby', titleText: 'standby daemons: y, z' }
    ];

    expect(pipe.transform(payload)).toEqual(expected);
  });
});