Skip to content

Commit

Permalink
fixes tests, addresses comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ecezalp committed Jul 12, 2021
1 parent fa5fcaf commit 7c9eaa2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,27 @@
* 2.0.
*/

/*
10000 to 10K
10100 to 10.1K
1000000 to 1M
1000000000 to 1B
*/
export const shortenCountIntoString = (count: number): string => {
if (count < 10000) {
return count.toString();
}
const si = [
{ v: 1e3, s: 'K' },
{ v: 1e6, s: 'M' },
{ v: 1e9, s: 'B' },
{ v: 1e12, s: 'T' },
{ v: 1e15, s: 'P' },
{ v: 1e18, s: 'E' },
const abbreviations = [
{ magnitude: 1e18, unit: 'E' },
{ magnitude: 1e15, unit: 'P' },
{ magnitude: 1e12, unit: 'T' },
{ magnitude: 1e9, unit: 'B' },
{ magnitude: 1e6, unit: 'M' },
{ magnitude: 1e3, unit: 'K' },
];
let i;
for (i = si.length - 1; i > 0; i--) {
if (count >= si[i].v) {
break;
}
}
const { magnitude, unit } = abbreviations.find(
(abbreviation) => count >= abbreviation.magnitude
) ?? {
magnitude: 1,
unit: '',
};

return (
toFixedWithoutRounding(count / si[i].v, 1).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + si[i].s
toFixedWithoutRounding(count / magnitude, 1).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + unit
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('CtiNoEvents', () => {
);

expect(wrapper.find('[data-test-subj="cti-total-event-count"]').text()).toEqual(
'Showing: 0 events'
'Showing: 0 indicators'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('CtiWithEvents', () => {
);

expect(wrapper.find('[data-test-subj="cti-total-event-count"]').text()).toEqual(
`Showing: ${mockCtiWithEventsProps.totalCount} events`
`Showing: ${mockCtiWithEventsProps.totalCount} indicators`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('ThreatIntelPanelView', () => {
);

expect(wrapper.find('[data-test-subj="cti-total-event-count"]').text()).toEqual(
`Showing: ${mockThreatIntelPanelViewProps.totalEventCount} events`
`Showing: ${mockThreatIntelPanelViewProps.totalEventCount} indicators`
);
});
});

0 comments on commit 7c9eaa2

Please sign in to comment.