expect(pipe.transform(undefined)).toBe('');
});
- it('transforms having 1 with 0 up and 1 in', () => {
+ it('transforms having 3 osd with 3 up, 3 in, 0 down, 0 out', () => {
const value = {
- osds: [{ in: true, out: false }]
+ osds: [{ up: 1, in: 1 }, { up: 1, in: 1 }, { up: 1, in: 1 }]
};
expect(pipe.transform(value)).toEqual([
{
- content: '1 (0 up, 1 in',
- style: { 'margin-right': '-5px', color: '' }
+ content: '3 total',
+ class: ''
},
{
- content: ', ',
- style: { 'margin-right': '0', color: '' }
+ content: '',
+ class: 'card-text-line-break'
},
{
- content: '1 down',
- style: { 'margin-right': '-5px', color: OsdSummaryPipe.COLOR_ERROR }
+ content: '3 up, 3 in',
+ class: ''
+ }
+ ]);
+ });
+
+ it('transforms having 3 osd with 2 up, 1 in, 1 down, 1 out', () => {
+ const value = {
+ osds: [{ up: 1, in: 1 }, { up: 1, in: 0 }, { up: 0, in: 0 }]
+ };
+ expect(pipe.transform(value)).toEqual([
+ {
+ content: '3 total',
+ class: ''
+ },
+ {
+ content: '',
+ class: 'card-text-line-break'
+ },
+ {
+ content: '2 up, 1 in',
+ class: ''
+ },
+ {
+ content: '',
+ class: 'card-text-line-break'
+ },
+ {
+ content: '1 down, 1 out',
+ class: 'card-text-error'
+ }
+ ]);
+ });
+
+ it('transforms having 3 osd with 2 up, 2 in, 1 down, 0 out', () => {
+ const value = {
+ osds: [{ up: 1, in: 1 }, { up: 1, in: 1 }, { up: 0, in: 0 }]
+ };
+ expect(pipe.transform(value)).toEqual([
+ {
+ content: '3 total',
+ class: ''
+ },
+ {
+ content: '',
+ class: 'card-text-line-break'
+ },
+ {
+ content: '2 up, 2 in',
+ class: ''
},
{
- content: ')',
- style: { 'margin-right': '0', color: '' }
+ content: '',
+ class: 'card-text-line-break'
+ },
+ {
+ content: '1 down',
+ class: 'card-text-error'
}
]);
});
- it('transforms having 2 with 2 up and 1 in', () => {
+ it('transforms having 3 osd with 3 up, 2 in, 0 down, 1 out', () => {
const value = {
- osds: [{ in: true, up: true }, { in: false, up: true }]
+ osds: [{ up: 1, in: 1 }, { up: 1, in: 1 }, { up: 1, in: 0 }]
};
expect(pipe.transform(value)).toEqual([
{
- content: '2 (2 up, 1 in',
- style: { 'margin-right': '-5px', color: '' }
+ content: '3 total',
+ class: ''
+ },
+ {
+ content: '',
+ class: 'card-text-line-break'
+ },
+ {
+ content: '3 up, 2 in',
+ class: ''
+ },
+ {
+ content: '',
+ class: 'card-text-line-break'
},
{
- content: ')',
- style: { 'margin-right': '0', color: '' }
+ content: '1 out',
+ class: 'card-text-error'
}
]);
});
name: 'osdSummary'
})
export class OsdSummaryPipe implements PipeTransform {
- static readonly COLOR_ERROR = '#ff0000';
-
transform(value: any, args?: any): any {
if (!value) {
return '';
let inCount = 0;
let upCount = 0;
- _.each(value.osds, (osd, i) => {
+ _.each(value.osds, (osd) => {
if (osd.in) {
inCount++;
}
const osdSummary = [
{
- content: `${value.osds.length} (${upCount} up, ${inCount} in`,
- style: { 'margin-right': '-5px', color: '' }
+ content: `${value.osds.length} total`,
+ class: ''
}
];
+ osdSummary.push({
+ content: '',
+ class: 'card-text-line-break'
+ });
+ osdSummary.push({
+ content: `${upCount} up, ${inCount} in`,
+ class: ''
+ });
const downCount = value.osds.length - upCount;
- if (downCount > 0) {
+ const outCount = upCount - inCount;
+ if (downCount > 0 || outCount > 0) {
osdSummary.push({
- content: ', ',
- style: { 'margin-right': '0', color: '' }
+ content: '',
+ class: 'card-text-line-break'
});
+
+ const downText = downCount > 0 ? `${downCount} down` : '';
+ const separator = downCount > 0 && outCount > 0 ? ', ' : '';
+ const outText = outCount > 0 ? `${outCount} out` : '';
osdSummary.push({
- content: `${downCount} down`,
- style: { 'margin-right': '-5px', color: OsdSummaryPipe.COLOR_ERROR }
+ content: `${downText}${separator}${outText}`,
+ class: 'card-text-error'
});
}
- osdSummary.push({
- content: ')',
- style: { 'margin-right': '0', color: '' }
- });
-
return osdSummary;
}
}