]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Add unit tests for all frontend pipes 22182/head
authorTiago Melo <tmelo@suse.com>
Wed, 23 May 2018 13:30:55 +0000 (14:30 +0100)
committerTiago Melo <tmelo@suse.com>
Thu, 24 May 2018 11:44:06 +0000 (12:44 +0100)
Signed-off-by: Tiago Melo <tmelo@suse.com>
18 files changed:
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirror-health-color.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/log-color.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mds-summary.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mgr-summary.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mon-summary.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/osd-summary.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status-style.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/empty.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/cd-date.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless-binary.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless.pipe.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/health-color.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/list.pipe.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/relative-date.pipe.spec.ts

index f22bcf2a599b3b2af9d2ad7c9914e05efd8c517e..2b1738c8b4cb97f01d6a52d06515bf5fec9dc668 100644 (file)
@@ -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');
+  });
 });
index 43af68d08af2c1bc956d7100fe6b1b91e9adb90d..58514878cb2a7604dddb29fe15e96bf89ea28a4c 100644 (file)
@@ -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('');
+  });
 });
index 37883a82a98713bb2d1e87276befea5bd84db306..ce9e045f08e5964552b000028bdde0739ae2b8c5 100644 (file)
@@ -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('');
+  });
 });
index fdab76c4808d28a344b4b62bf6610e1e2a5e35c3..0800019941b6ac48a26c7b1d5e39746c5069ee71 100644 (file)
@@ -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');
+  });
 });
index 49526cf3fcd78353a01a07293963bde364e610ea..49f23bcba06a7d8086351ee454270152c6305405 100644 (file)
@@ -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)');
+  });
 });
index 466eec1ac30ea1a1b3e4b0ada9c62ff5727997d5..111fd148b18e8c07d6a70c95e9559af27afa7f97 100644 (file)
@@ -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)');
+  });
 });
index 67c5f10c5e357464a0eeb403545f7a336868ea32..18c694bfe71264618af57656e986825475bf85cf 100644 (file)
@@ -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' });
+  });
 });
index d7d5592b653fe5f769a3944de33cd80832b7cb17..8b65547665828e74b554391f429b6e096000f3e0 100644 (file)
@@ -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');
+  });
 });
index 9e5b0b2b5ffff98fa21e6f11743aea65769bff81..462907906f36776b4fe8e65f2007285f25ae07db 100644 (file)
@@ -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');
+  });
 });
index 4270abef9732953e9bebdbfeb348da11a1e0194d..08212b2687ae316fd48f598794ed47c425663603 100644 (file)
@@ -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);
+  });
 });
index bfe10c2f46977d5a39b4005dc05705b3bf6e85ba..fa81c4d8ce5c3b9302b895e09b0ebe45fa7742fb 100644 (file)
@@ -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');
+  });
 });
index 2424ebc16bb80723ddaa9043c12213cf277ea7e4..268fe61588f553c9168ad2b0d0b88fa0daf300d1 100644 (file)
@@ -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');
+  });
 });
index 4bbfdd8564c999b94bfeec1632c7405745e8daca..edc7fe181baaffbc1628fa2bd155807a518dbeb0 100644 (file)
@@ -2,9 +2,55 @@ import { FormatterService } from '../services/formatter.service';
 import { DimlessPipe } from './dimless.pipe';
 
 describe('DimlessPipe', () => {
+  const formatterService = new FormatterService();
+  const pipe = new DimlessPipe(formatterService);
+
   it('create an instance', () => {
-    const formatterService = new FormatterService();
-    const pipe = new DimlessPipe(formatterService);
     expect(pipe).toBeTruthy();
   });
+
+  it('transforms 1000^0', () => {
+    const value = Math.pow(1000, 0);
+    expect(pipe.transform(value)).toBe('1');
+  });
+
+  it('transforms 1000^1', () => {
+    const value = Math.pow(1000, 1);
+    expect(pipe.transform(value)).toBe('1k');
+  });
+
+  it('transforms 1000^2', () => {
+    const value = Math.pow(1000, 2);
+    expect(pipe.transform(value)).toBe('1M');
+  });
+
+  it('transforms 1000^3', () => {
+    const value = Math.pow(1000, 3);
+    expect(pipe.transform(value)).toBe('1G');
+  });
+
+  it('transforms 1000^4', () => {
+    const value = Math.pow(1000, 4);
+    expect(pipe.transform(value)).toBe('1T');
+  });
+
+  it('transforms 1000^5', () => {
+    const value = Math.pow(1000, 5);
+    expect(pipe.transform(value)).toBe('1P');
+  });
+
+  it('transforms 1000^6', () => {
+    const value = Math.pow(1000, 6);
+    expect(pipe.transform(value)).toBe('1E');
+  });
+
+  it('transforms 1000^7', () => {
+    const value = Math.pow(1000, 7);
+    expect(pipe.transform(value)).toBe('1Z');
+  });
+
+  it('transforms 1000^8', () => {
+    const value = Math.pow(1000, 8);
+    expect(pipe.transform(value)).toBe('1Y');
+  });
 });
index 875211576c062b5c0811d6da393b06f48985d6f2..89fbe8ac288573c53edb7060100643b94bc972ce 100644 (file)
@@ -9,7 +9,7 @@ export class DimlessPipe implements PipeTransform {
 
   transform(value: any, args?: any): any {
     return this.formatter.format_number(value, 1000, [
-      ' ',
+      '',
       'k',
       'M',
       'G',
index 1427de361bd6a61498689545d697d5d4d09c3184..c516ad3835da56480a84e8160764e203b748e263 100644 (file)
@@ -1,8 +1,54 @@
 import { FilterPipe } from './filter.pipe';
 
 describe('FilterPipe', () => {
+  const pipe = new FilterPipe();
+
   it('create an instance', () => {
-    const pipe = new FilterPipe();
     expect(pipe).toBeTruthy();
   });
+
+  it('filter words with "foo"', () => {
+    const value = ['foo', 'bar', 'foobar'];
+    const filters = [
+      {
+        value: 'foo',
+        applyFilter: (row, val) => {
+          return row.indexOf(val) !== -1;
+        }
+      }
+    ];
+    expect(pipe.transform(value, filters)).toEqual(['foo', 'foobar']);
+  });
+
+  it('filter words with "foo" and "bar"', () => {
+    const value = ['foo', 'bar', 'foobar'];
+    const filters = [
+      {
+        value: 'foo',
+        applyFilter: (row, val) => {
+          return row.indexOf(val) !== -1;
+        }
+      },
+      {
+        value: 'bar',
+        applyFilter: (row, val) => {
+          return row.indexOf(val) !== -1;
+        }
+      }
+    ];
+    expect(pipe.transform(value, filters)).toEqual(['foobar']);
+  });
+
+  it('filter with no value', () => {
+    const value = ['foo', 'bar', 'foobar'];
+    const filters = [
+      {
+        value: '',
+        applyFilter: (row, val) => {
+          return false;
+        }
+      }
+    ];
+    expect(pipe.transform(value, filters)).toEqual(['foo', 'bar', 'foobar']);
+  });
 });
index e0e44e0eb85db66a2263d45d8a319e2ba6baa28f..2293dd9aca78d1fc4f6d77909b899751a74ca6fa 100644 (file)
@@ -1,8 +1,25 @@
 import { HealthColorPipe } from './health-color.pipe';
 
 describe('HealthColorPipe', () => {
+  const pipe = new HealthColorPipe();
+
   it('create an instance', () => {
-    const pipe = new HealthColorPipe();
     expect(pipe).toBeTruthy();
   });
+
+  it('transforms "HEALTH_OK"', () => {
+    expect(pipe.transform('HEALTH_OK')).toEqual({ color: '#00bb00' });
+  });
+
+  it('transforms "HEALTH_WARN"', () => {
+    expect(pipe.transform('HEALTH_WARN')).toEqual({ color: '#ffa500' });
+  });
+
+  it('transforms "HEALTH_ERR"', () => {
+    expect(pipe.transform('HEALTH_ERR')).toEqual({ color: '#ff0000' });
+  });
+
+  it('transforms others', () => {
+    expect(pipe.transform('abc')).toBe(null);
+  });
 });
index 768f12a24e5292d7b748100522761fc573ef6a1e..d26fd65ec5e1857265eb6836567ec87bdce7a4d3 100644 (file)
@@ -1,8 +1,13 @@
 import { ListPipe } from './list.pipe';
 
 describe('ListPipe', () => {
+  const pipe = new ListPipe();
+
   it('create an instance', () => {
-    const pipe = new ListPipe();
     expect(pipe).toBeTruthy();
   });
+
+  it('transforms "[1,2,3]"', () => {
+    expect(pipe.transform([1, 2, 3])).toBe('1, 2, 3');
+  });
 });
index 1295b0dc25b6d772b9561602be109d659b1214c0..b0f6534c633a3f59c74b4b6c767e5c56232ec2fb 100644 (file)
@@ -1,8 +1,26 @@
+import * as moment from 'moment';
+
 import { RelativeDatePipe } from './relative-date.pipe';
 
 describe('RelativeDatePipe', () => {
+  const pipe = new RelativeDatePipe();
+
   it('create an instance', () => {
-    const pipe = new RelativeDatePipe();
     expect(pipe).toBeTruthy();
   });
+
+  it('transforms without value', () => {
+    const value = undefined;
+    expect(pipe.transform(value)).toBe('unknown');
+  });
+
+  it('transforms "in 7 days"', () => {
+    const value = moment().add(7, 'days').unix();
+    expect(pipe.transform(value)).toBe('in 7 days');
+  });
+
+  it('transforms "7 days ago"', () => {
+    const value = moment().subtract(7, 'days').unix();
+    expect(pipe.transform(value)).toBe('7 days ago');
+  });
 });