summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mds-summary.pipe.spec.ts
blob: c62b35c548e598a8edec331f3640596d7d278b4a (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { TestBed } from '@angular/core/testing';

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

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

  configureTestBed({
    providers: [MdsSummaryPipe]
  });

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

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

  it('transforms with 0 active and 2 standy', () => {
    const payload = {
      standbys: [{ name: 'a' }],
      filesystems: [{ mdsmap: { info: [{ state: 'up:standby-replay' }] } }]
    };
    const expected = [
      { class: 'popover-info', content: '0 active', titleText: '1 standbyReplay' },
      { class: 'card-text-line-break', content: '', titleText: '' },
      { class: 'popover-info', content: '2 standby', titleText: 'standby daemons: a' }
    ];

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

  it('transforms with 1 active and 1 standy', () => {
    const payload = {
      standbys: [{ name: 'b' }],
      filesystems: [{ mdsmap: { info: [{ state: 'up:active', name: 'a' }] } }]
    };
    const expected = [
      { class: 'popover-info', content: '1 active', titleText: 'active daemon: a' },
      { class: 'card-text-line-break', content: '', titleText: '' },
      { class: 'popover-info', content: '1 standby', titleText: 'standby daemons: b' }
    ];
    expect(pipe.transform(payload)).toEqual(expected);
  });

  it('transforms with 0 filesystems', () => {
    const payload: Record<string, any> = {
      standbys: [0],
      filesystems: []
    };
    const expected = [{ class: 'popover-info', content: 'no filesystems', titleText: '' }];

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

  it('transforms without filesystem', () => {
    const payload = { standbys: [{ name: 'a' }] };
    const expected = [
      { class: 'popover-info', content: '1 up', titleText: '' },
      { class: 'card-text-line-break', content: '', titleText: '' },
      { class: 'popover-info', content: 'no filesystems', titleText: 'standby daemons: a' }
    ];

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

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