Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mgr/dashboard: Add unit tests for all frontend pipes
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
Showing
18 changed files
with
405 additions
and
20 deletions.
There are no files selected for viewing
19 changes: 18 additions & 1 deletion
19
src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirror-health-color.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); |
28 changes: 27 additions & 1 deletion
28
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/log-color.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(''); | ||
}); | ||
}); |
38 changes: 37 additions & 1 deletion
38
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mds-summary.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(''); | ||
}); | ||
}); |
23 changes: 22 additions & 1 deletion
23
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mgr-summary.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); |
23 changes: 22 additions & 1 deletion
23
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/mon-summary.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)'); | ||
}); | ||
}); |
21 changes: 20 additions & 1 deletion
21
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/osd-summary.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)'); | ||
}); | ||
}); |
18 changes: 17 additions & 1 deletion
18
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status-style.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' }); | ||
}); | ||
}); |
13 changes: 12 additions & 1 deletion
13
src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/pg-status.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); |
13 changes: 12 additions & 1 deletion
13
src/pybind/mgr/dashboard/frontend/src/app/shared/empty.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); |
18 changes: 17 additions & 1 deletion
18
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/cd-date.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
15 changes: 14 additions & 1 deletion
15
src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ceph-short-version.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.