From b6305630c417bcb92c55a6b461c63ca0911a8b03 Mon Sep 17 00:00:00 2001 From: Tiago Melo Date: Wed, 23 May 2018 14:30:55 +0100 Subject: [PATCH] mgr/dashboard: Add unit tests for all frontend pipes Signed-off-by: Tiago Melo --- .../block/mirror-health-color.pipe.spec.ts | 19 ++++++- .../app/ceph/dashboard/log-color.pipe.spec.ts | 28 ++++++++++- .../ceph/dashboard/mds-summary.pipe.spec.ts | 38 +++++++++++++- .../ceph/dashboard/mgr-summary.pipe.spec.ts | 23 ++++++++- .../ceph/dashboard/mon-summary.pipe.spec.ts | 23 ++++++++- .../ceph/dashboard/osd-summary.pipe.spec.ts | 21 +++++++- .../dashboard/pg-status-style.pipe.spec.ts | 18 ++++++- .../app/ceph/dashboard/pg-status.pipe.spec.ts | 13 ++++- .../src/app/shared/empty.pipe.spec.ts | 13 ++++- .../src/app/shared/pipes/cd-date.pipe.spec.ts | 18 ++++++- .../pipes/ceph-short-version.pipe.spec.ts | 15 +++++- .../shared/pipes/dimless-binary.pipe.spec.ts | 50 ++++++++++++++++++- .../src/app/shared/pipes/dimless.pipe.spec.ts | 50 ++++++++++++++++++- .../src/app/shared/pipes/dimless.pipe.ts | 2 +- .../src/app/shared/pipes/filter.pipe.spec.ts | 48 +++++++++++++++++- .../shared/pipes/health-color.pipe.spec.ts | 19 ++++++- .../src/app/shared/pipes/list.pipe.spec.ts | 7 ++- .../shared/pipes/relative-date.pipe.spec.ts | 20 +++++++- 18 files changed, 405 insertions(+), 20 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirror-health-color.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirror-health-color.pipe.spec.ts index f22bcf2a599b3..2b1738c8b4cb9 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirror-health-color.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirror-health-color.pipe.spec.ts @@ -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'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/log-color.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/log-color.pipe.spec.ts index 43af68d08af2c..58514878cb2a7 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/log-color.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/log-color.pipe.spec.ts @@ -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(''); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mds-summary.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mds-summary.pipe.spec.ts index 37883a82a9871..ce9e045f08e59 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mds-summary.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mds-summary.pipe.spec.ts @@ -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(''); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mgr-summary.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mgr-summary.pipe.spec.ts index fdab76c4808d2..0800019941b6a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mgr-summary.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mgr-summary.pipe.spec.ts @@ -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'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mon-summary.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mon-summary.pipe.spec.ts index 49526cf3fcd78..49f23bcba06a7 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mon-summary.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mon-summary.pipe.spec.ts @@ -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)'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/osd-summary.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/osd-summary.pipe.spec.ts index 466eec1ac30ea..111fd148b18e8 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/osd-summary.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/osd-summary.pipe.spec.ts @@ -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)'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status-style.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status-style.pipe.spec.ts index 67c5f10c5e357..18c694bfe7126 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status-style.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status-style.pipe.spec.ts @@ -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' }); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status.pipe.spec.ts index d7d5592b653fe..8b65547665828 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status.pipe.spec.ts @@ -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'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/empty.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/empty.pipe.spec.ts index 9e5b0b2b5ffff..462907906f367 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/empty.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/empty.pipe.spec.ts @@ -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'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/cd-date.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/cd-date.pipe.spec.ts index 4270abef97329..08212b2687ae3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/cd-date.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/cd-date.pipe.spec.ts @@ -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); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.spec.ts index bfe10c2f46977..fa81c4d8ce5c3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.spec.ts @@ -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'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless-binary.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless-binary.pipe.spec.ts index 2424ebc16bb80..268fe61588f55 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless-binary.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless-binary.pipe.spec.ts @@ -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'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless.pipe.spec.ts index 4bbfdd8564c99..edc7fe181baaf 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless.pipe.spec.ts @@ -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'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless.pipe.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless.pipe.ts index 875211576c062..89fbe8ac28857 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless.pipe.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/dimless.pipe.ts @@ -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', diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.spec.ts index 1427de361bd6a..c516ad3835da5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/filter.pipe.spec.ts @@ -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']); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/health-color.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/health-color.pipe.spec.ts index e0e44e0eb85db..2293dd9aca78d 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/health-color.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/health-color.pipe.spec.ts @@ -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); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/list.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/list.pipe.spec.ts index 768f12a24e529..d26fd65ec5e18 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/list.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/list.pipe.spec.ts @@ -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'); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/relative-date.pipe.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/relative-date.pipe.spec.ts index 1295b0dc25b6d..b0f6534c633a3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/relative-date.pipe.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/relative-date.pipe.spec.ts @@ -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'); + }); }); -- 2.39.5