Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

brettgilio
Copy link

Implements [Unread messages count] Abandon "k" (= thousand) when it reaches million+ #4615

Implements [Unread messages count] Abandon "k" (= thousand) when it reaches million+ thelounge#4615
@brunnre8
Copy link
Member

You didn't edit the test.
Not that you can actually run the tests mind you, our client side test framework is broken at the moment but still.

@brettgilio brettgilio closed this Dec 22, 2022
@brettgilio brettgilio reopened this Dec 22, 2022
Implements [Unread messages count] Abandon "k" (= thousand) when it reaches million+ thelounge#4615
@brettgilio brettgilio changed the title Use "m" shorthand for messages >= one million. Use "m" shorthand for messages >= one million Dec 22, 2022
@brettgilio brettgilio changed the title Use "m" shorthand for messages >= one million Use "M" shorthand for messages >= one million Dec 23, 2022
@brettgilio
Copy link
Author

You didn't edit the test. Not that you can actually run the tests mind you, our client side test framework is broken at the moment but still.

Done.

@brunnre8 brunnre8 added Meta: Internal This is an internal codebase change (testing, linting, etc.). Status: needs-review PR not yet reviewed by enough maintainers labels Dec 30, 2022
@@ -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 () {
Copy link
Member

@xPaw xPaw Feb 15, 2023

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);
Copy link
Member

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");
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Meta: Internal This is an internal codebase change (testing, linting, etc.). Status: needs-review PR not yet reviewed by enough maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants