New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use "M" shorthand for messages >= one million #4659
base: master
Are you sure you want to change the base?
Conversation
Implements [Unread messages count] Abandon "k" (= thousand) when it reaches million+ thelounge#4615
You didn't edit the test. |
Implements [Unread messages count] Abandon "k" (= thousand) when it reaches million+ thelounge#4615
Done. |
@@ -6,10 +6,15 @@ describe("roundBadgeNumber helper", function () { | |||
expect(roundBadgeNumber(123)).to.equal("123"); | |||
}); | |||
|
|||
it("should return numbers above 999 in thousands", function () { | |||
it("should return numbers between 1000 and 999999 with a 'k' suffix", function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a few more expects, e.g. 999999 is in fact 999k
@@ -3,5 +3,9 @@ export default (count: number) => { | |||
return count.toString(); | |||
} | |||
|
|||
return (count / 1000).toFixed(2).slice(0, -1) + "k"; | |||
const suffixes = ["", "k", "M"]; | |||
const magnitudeIndex = Math.min(Math.floor(Math.log10(count) / 3), suffixes.length - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I understand the use case here, I think it's simpler to just have two if cases to handle M/k
.
if(count >= 1000000) M
if(count >= 1000) k
count
expect(roundBadgeNumber(1000)).to.be.equal("1.0k"); | ||
}); | ||
|
||
it("should return numbers above 999999 with a 'M' suffix", function () { | ||
expect(roundBadgeNumber(1000000)).to.be.equal("1.0M"); | ||
expect(roundBadgeNumber(1234567)).to.be.equal("1.2M"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test for much higher magnitude number (with current code it would validate that it magnitudeIndex
works` as expected.
Implements [Unread messages count] Abandon "k" (= thousand) when it reaches million+ #4615