Skip to content

Use explicit optional locale arg in math functions, rework tests accordingly - #2155

Merged
david-crespo merged 1 commit into
mainfrom
locale-arg
Apr 17, 2024
Merged

david-crespo merged 1 commit into
mainfrom
locale-arg

Conversation

@david-crespo

Copy link
Copy Markdown
Collaborator

This is basically a refactor. It should not change any functionality, though it does add a test we didn't have before.

While discussing changes to date functions in #2153 (comment), I learned that the more natural way to tell the built-in locale-aware functions you want to use whatever the browser's current locale is while also passing some options is to pass undefined as the locale instead of navigator.language (which should still work but is a bit weirder-feeling). The nice thing about passing undefined is it goes really well with an optional locale arg that defaults to undefined, and which we only explicitly use in the tests.

@vercel

vercel Bot commented Apr 17, 2024

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
console ✅ Ready (Inspect) Visit Preview Apr 17, 2024 3:14am

Comment thread app/util/math.ts
// a separate function because I wanted to test it with a bunch of locales
// to make sure the toLowerCase thing is ok
export const toEngNotation = (num: number | bigint, locale = navigator.language) =>
const toEngNotation = (num: number | bigint, locale?: string) =>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't have to test this directly anymore because displayBigNum takes a locale arg too, so we don't have to export it at all.

Comment thread test/e2e/ip-pools.e2e.ts
})

test.describe('german locale', () => {
test.use({ locale: 'de-DE' })

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love that playwright!

Comment thread app/util/math.spec.ts
[1n, ['1', false]],
[155n, ['155', false]],
[999999n, ['999,999', false]],
[999999n, ['999.999', false]],

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was sort of a bug, but I'm pretty sure it was only due to the way we're mocking this for the tests. I think in a browser it would have worked correctly.

@david-crespo
david-crespo enabled auto-merge (squash) April 17, 2024 03:18
@david-crespo
david-crespo merged commit c726356 into main Apr 17, 2024
@david-crespo
david-crespo deleted the locale-arg branch April 17, 2024 03:20

This branch was successfully deployed

1 active deployment
Preview — d6ba2754 Deployed Apr 17, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant