mirror of
https://github.com/mastodon/mastodon.git
synced 2026-07-02 04:40:49 -05:00
Fix short numbers rounding up instead of truncating (#37899) (#38114)
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
Chromatic / Check for relevant changes (push) Waiting to run
Chromatic / Run Chromatic (push) Blocked by required conditions
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
Chromatic / Check for relevant changes (push) Waiting to run
Chromatic / Run Chromatic (push) Blocked by required conditions
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Blocked by required conditions
This commit is contained in:
parent
69b1f60f4e
commit
75ef5bfd2d
|
|
@ -0,0 +1,80 @@
|
|||
import { IntlProvider } from 'react-intl';
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
import { ShortNumber } from '../short_number';
|
||||
|
||||
function renderShortNumber(value: number) {
|
||||
return render(
|
||||
<IntlProvider locale='en'>
|
||||
<ShortNumber value={value} />
|
||||
</IntlProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
describe('ShortNumber Component', () => {
|
||||
it('does not abbreviate numbers under 1000', () => {
|
||||
renderShortNumber(999);
|
||||
expect(screen.getByText('999')).toBeDefined();
|
||||
});
|
||||
|
||||
it('formats thousands correctly for 1000', () => {
|
||||
renderShortNumber(1000);
|
||||
expect(screen.getByText('1K')).toBeDefined();
|
||||
});
|
||||
|
||||
it('truncates decimals for 1051', () => {
|
||||
renderShortNumber(1051);
|
||||
expect(screen.getByText('1K')).toBeDefined();
|
||||
});
|
||||
|
||||
it('truncates decimals for 2999', () => {
|
||||
renderShortNumber(2999);
|
||||
expect(screen.getByText('2.9K')).toBeDefined();
|
||||
});
|
||||
|
||||
it('truncates decimals for 9999', () => {
|
||||
renderShortNumber(9999);
|
||||
expect(screen.getByText('9.9K')).toBeDefined();
|
||||
});
|
||||
|
||||
it('truncates decimals for 10501', () => {
|
||||
renderShortNumber(10501);
|
||||
expect(screen.getByText('10K')).toBeDefined();
|
||||
});
|
||||
|
||||
it('truncates decimals for 11000', () => {
|
||||
renderShortNumber(11000);
|
||||
expect(screen.getByText('11K')).toBeDefined();
|
||||
});
|
||||
|
||||
it('truncates decimals for 99999', () => {
|
||||
renderShortNumber(99999);
|
||||
expect(screen.getByText('99K')).toBeDefined();
|
||||
});
|
||||
|
||||
it('truncates decimals for 100501', () => {
|
||||
renderShortNumber(100501);
|
||||
expect(screen.getByText('100K')).toBeDefined();
|
||||
});
|
||||
|
||||
it('truncates decimals for 101000', () => {
|
||||
renderShortNumber(101000);
|
||||
expect(screen.getByText('101K')).toBeDefined();
|
||||
});
|
||||
|
||||
it('truncates decimals for 999999', () => {
|
||||
renderShortNumber(999999);
|
||||
expect(screen.getByText('999K')).toBeDefined();
|
||||
});
|
||||
|
||||
it('truncates decimals for 2999999', () => {
|
||||
renderShortNumber(2999999);
|
||||
expect(screen.getByText('2.9M')).toBeDefined();
|
||||
});
|
||||
|
||||
it('truncates decimals for 9999999', () => {
|
||||
renderShortNumber(9999999);
|
||||
expect(screen.getByText('9.9M')).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
@ -51,6 +51,7 @@ const ShortNumberCounter: React.FC<ShortNumberCounterProps> = ({ value }) => {
|
|||
<FormattedNumber
|
||||
value={rawNumber ?? 0}
|
||||
maximumFractionDigits={maxFractionDigits}
|
||||
roundingMode='trunc'
|
||||
/>
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user