Skip to content

Commit

Permalink
mgr/dashboard: Add unit tests for all frontend pipes
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Melo <tmelo@suse.com>
(cherry picked from commit b630563)
  • Loading branch information
Tiago Melo committed May 25, 2018
1 parent aa04c27 commit 50fbc04
Show file tree
Hide file tree
Showing 18 changed files with 405 additions and 20 deletions.
@@ -1,8 +1,25 @@
import { MirrorHealthColorPipe } from './mirror-health-color.pipe';

describe('MirrorHealthColorPipe', () => {
const pipe = new MirrorHealthColorPipe();

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

it('transforms "warning"', () => {
expect(pipe.transform('warning')).toBe('label label-warning');
});

it('transforms "error"', () => {
expect(pipe.transform('error')).toBe('label label-danger');
});

it('transforms "success"', () => {
expect(pipe.transform('success')).toBe('label label-success');
});

it('transforms others', () => {
expect(pipe.transform('abc')).toBe('label label-info');
});
});
@@ -1,8 +1,34 @@
import { LogColorPipe } from './log-color.pipe';

describe('LogColorPipe', () => {
const pipe = new LogColorPipe();

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

it('transforms "INF"', () => {
const value = { priority: '[INF]' };
expect(pipe.transform(value)).toBe('');
});

it('transforms "WRN"', () => {
const value = { priority: '[WRN]' };
const result = {
color: '#ffa500',
'font-weight': 'bold'
};
expect(pipe.transform(value)).toEqual(result);
});

it('transforms "ERR"', () => {
const value = { priority: '[ERR]' };
const result = { color: '#FF2222' };
expect(pipe.transform(value)).toEqual(result);
});

it('transforms others', () => {
const value = { priority: '[foo]' };
expect(pipe.transform(value)).toBe('');
});
});
@@ -1,8 +1,44 @@
import { MdsSummaryPipe } from './mds-summary.pipe';

describe('MdsSummaryPipe', () => {
const pipe = new MdsSummaryPipe();

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

it('transforms with 0 active and 2 standy', () => {
const value = {
standbys: [0],
filesystems: [{ mdsmap: { info: [{ state: 'up:standby-replay' }] } }]
};
const result = { color: '#FF2222' };
expect(pipe.transform(value)).toBe('0 active, 2 standby');
});

it('transforms with 1 active and 1 standy', () => {
const value = {
standbys: [0],
filesystems: [{ mdsmap: { info: [{ state: 'up:active' }] } }]
};
const result = { color: '#FF2222' };
expect(pipe.transform(value)).toBe('1 active, 1 standby');
});

it('transforms with 0 filesystems', () => {
const value = {
standbys: [0],
filesystems: []
};
expect(pipe.transform(value)).toBe('no filesystems');
});

it('transforms without filesystem', () => {
const value = { standbys: [0] };
expect(pipe.transform(value)).toBe('1, no filesystems');
});

it('transforms without value', () => {
expect(pipe.transform(undefined)).toBe('');
});
});
@@ -1,8 +1,29 @@
import { MgrSummaryPipe } from './mgr-summary.pipe';

describe('MgrSummaryPipe', () => {
const pipe = new MgrSummaryPipe();

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

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

it('transforms with active_name undefined', () => {
const value = {
active_name: undefined,
standbys: []
};
expect(pipe.transform(value)).toBe('active: n/a');
});

it('transforms with 1 active and 2 standbys', () => {
const value = {
active_name: 'a',
standbys: ['b', 'c']
};
expect(pipe.transform(value)).toBe('active: a, 2 standbys');
});
});
@@ -1,8 +1,29 @@
import { MonSummaryPipe } from './mon-summary.pipe';

describe('MonSummaryPipe', () => {
const pipe = new MonSummaryPipe();

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

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

it('transforms with 3 mons in quorum', () => {
const value = {
monmap: { mons: [0, 1, 2] },
quorum: [0, 1, 2]
};
expect(pipe.transform(value)).toBe('3 (quorum 0, 1, 2)');
});

it('transforms with 2/3 mons in quorum', () => {
const value = {
monmap: { mons: [0, 1, 2] },
quorum: [0, 1]
};
expect(pipe.transform(value)).toBe('3 (quorum 0, 1)');
});
});
@@ -1,8 +1,27 @@
import { OsdSummaryPipe } from './osd-summary.pipe';

describe('OsdSummaryPipe', () => {
const pipe = new OsdSummaryPipe();

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

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

it('transforms with 1 up', () => {
const value = {
osds: [{ in: true, out: false }]
};
expect(pipe.transform(value)).toBe('1 (0 up, 1 in)');
});

it('transforms with 1 up and 1 in', () => {
const value = {
osds: [{ in: true, up: false }, { in: false, up: true }]
};
expect(pipe.transform(value)).toBe('2 (1 up, 1 in)');
});
});
@@ -1,8 +1,24 @@
import { PgStatusStylePipe } from './pg-status-style.pipe';

describe('PgStatusStylePipe', () => {
const pipe = new PgStatusStylePipe();

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

it('transforms with pg status error', () => {
const value = { 'incomplete+clean': 8 };
expect(pipe.transform(value)).toEqual({ color: '#FF0000' });
});

it('transforms with pg status warning', () => {
const value = { 'active': 8 };
expect(pipe.transform(value)).toEqual({ color: '#FFC200' });
});

it('transforms with pg status other', () => {
const value = { 'active+clean': 8 };
expect(pipe.transform(value)).toEqual({ color: '#00BB00' });
});
});
@@ -1,8 +1,19 @@
import { PgStatusPipe } from './pg-status.pipe';

describe('PgStatusPipe', () => {
const pipe = new PgStatusPipe();

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

it('transforms with 1 status', () => {
const value = { 'active+clean': 8 };
expect(pipe.transform(value)).toBe('8 active+clean');
});

it('transforms with 2 status', () => {
const value = { active: 8, incomplete: 8 };
expect(pipe.transform(value)).toBe('8 active, 8 incomplete');
});
});
@@ -1,8 +1,19 @@
import { EmptyPipe } from './empty.pipe';

describe('EmptyPipe', () => {
const pipe = new EmptyPipe();

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

it('transforms with empty value', () => {
const value = undefined;
expect(pipe.transform(value)).toBe('-');
});

it('transforms with some value', () => {
const value = 'foo';
expect(pipe.transform(value)).toBe('foo');
});
});
@@ -1,8 +1,24 @@
import { DatePipe } from '@angular/common';

import * as moment from 'moment';

import { CdDatePipe } from './cd-date.pipe';

describe('CdDatePipe', () => {
const datePipe = new DatePipe('en-US');
let pipe = new CdDatePipe(datePipe);

it('create an instance', () => {
const pipe = new CdDatePipe(null);
pipe = new CdDatePipe(datePipe);
expect(pipe).toBeTruthy();
});

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

it('transforms with some date', () => {
const result = moment(1527085564486).format('M/D/YY LTS');
expect(pipe.transform(1527085564486)).toBe(result);
});
});
@@ -1,8 +1,21 @@
import { CephShortVersionPipe } from './ceph-short-version.pipe';

describe('CephShortVersionPipe', () => {
const pipe = new CephShortVersionPipe();

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

it('transforms with correct version format', () => {
const value =
'ceph version 13.1.0-534-g23d3751b89 (23d3751b897b31d2bda57aeaf01acb5ff3c4a9cd) nautilus (dev)';
expect(pipe.transform(value)).toBe('13.1.0-534-g23d3751b89');
});

it('transforms with wrong version format', () => {
const value =
'foo';
expect(pipe.transform(value)).toBe('foo');
});
});
Expand Up @@ -2,9 +2,55 @@ import { FormatterService } from '../services/formatter.service';
import { DimlessBinaryPipe } from './dimless-binary.pipe';

describe('DimlessBinaryPipe', () => {
const formatterService = new FormatterService();
const pipe = new DimlessBinaryPipe(formatterService);

it('create an instance', () => {
const formatterService = new FormatterService();
const pipe = new DimlessBinaryPipe(formatterService);
expect(pipe).toBeTruthy();
});

it('transforms 1024^0', () => {
const value = Math.pow(1024, 0);
expect(pipe.transform(value)).toBe('1B');
});

it('transforms 1024^1', () => {
const value = Math.pow(1024, 1);
expect(pipe.transform(value)).toBe('1KiB');
});

it('transforms 1024^2', () => {
const value = Math.pow(1024, 2);
expect(pipe.transform(value)).toBe('1MiB');
});

it('transforms 1024^3', () => {
const value = Math.pow(1024, 3);
expect(pipe.transform(value)).toBe('1GiB');
});

it('transforms 1024^4', () => {
const value = Math.pow(1024, 4);
expect(pipe.transform(value)).toBe('1TiB');
});

it('transforms 1024^5', () => {
const value = Math.pow(1024, 5);
expect(pipe.transform(value)).toBe('1PiB');
});

it('transforms 1024^6', () => {
const value = Math.pow(1024, 6);
expect(pipe.transform(value)).toBe('1EiB');
});

it('transforms 1024^7', () => {
const value = Math.pow(1024, 7);
expect(pipe.transform(value)).toBe('1ZiB');
});

it('transforms 1024^8', () => {
const value = Math.pow(1024, 8);
expect(pipe.transform(value)).toBe('1YiB');
});
});

0 comments on commit 50fbc04

Please sign in to comment.