-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(MoneyInput): use locale from context if no locale provided
- Loading branch information
Showing
9 changed files
with
126 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { MoneyInput, type MoneyInputProps } from './money-input'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/react/src/components/money-input/toLocale.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { toLocale } from './toLocale'; | ||
|
||
describe('toLocale', () => { | ||
it.each` | ||
language | expected | ||
${'en'} | ${'en-CA'} | ||
${'fr'} | ${'fr-CA'} | ||
`('should return $expected for $language with CAD currency', ({ language, expected }) => { | ||
expect(toLocale(language, 'CAD')).toBe(expected); | ||
}); | ||
|
||
it.each` | ||
language | expected | ||
${'en'} | ${'en-US'} | ||
${'fr'} | ${'fr-US'} | ||
`('should return $expected for $language with USD currency', ({ language, expected }) => { | ||
expect(toLocale(language, 'USD')).toBe(expected); | ||
}); | ||
|
||
it('should return language as is if language is a locale', () => { | ||
expect(toLocale('fr-FR', 'EUR')).toBe('fr-FR'); | ||
}); | ||
|
||
it.each` | ||
language | currency | expected | ||
${'en'} | ${'EUR'} | ${'en'} | ||
${'fr'} | ${'GBP'} | ${'fr'} | ||
${'fr'} | ${'ABC'} | ${'fr'} | ||
`('should return $language as is for unmapped $currency currency', ({ language, currency, expected }) => { | ||
expect(toLocale(language, currency)).toBe(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function toLocale( | ||
language: string, | ||
currency: string, | ||
): string { | ||
if (!language.match(/^[a-z]{2}-[a-z]{2}$/i)) { | ||
switch (currency.toUpperCase()) { | ||
case 'CAD': | ||
return `${language}-CA`; | ||
case 'USD': | ||
return `${language}-US`; | ||
} | ||
} | ||
|
||
return language; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { render } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { DesignSystem, DesignSystemProps } from '../components/design-system'; | ||
import { equisoftTheme } from '../theme'; | ||
|
||
export function renderWithProviders( | ||
ui: Parameters<typeof render>[0], | ||
renderOptions: Omit<Parameters<typeof render>[1], 'wrapper'> | undefined = undefined, | ||
wrapperProps: DesignSystemProps = {}, | ||
): ReturnType<typeof render> { | ||
const { | ||
isolateStyles, | ||
language, | ||
staticDevice, | ||
theme, | ||
} = { | ||
isolateStyles: false, | ||
language: 'fr', | ||
theme: equisoftTheme, | ||
...wrapperProps, | ||
}; | ||
return render( | ||
ui, | ||
{ | ||
...renderOptions, | ||
wrapper: ({ children }) => ( | ||
<MemoryRouter> | ||
<DesignSystem | ||
isolateStyles={isolateStyles} | ||
language={language} | ||
staticDevice={staticDevice} | ||
theme={theme} | ||
> | ||
{children} | ||
</DesignSystem> | ||
</MemoryRouter> | ||
), | ||
}, | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters