-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from Ferlab-Ste-Justine/feat/FLUI-65-add-loca…
…le-to-number-format feat(number): FLUI-65 manage locale in number
- Loading branch information
Showing
5 changed files
with
76 additions
and
3 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
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,44 @@ | ||
import { setLocale } from './localeUtils'; | ||
|
||
export const localStorageMock = (function () { | ||
let store: any = {}; | ||
return { | ||
clear: function () { | ||
store = {}; | ||
}, | ||
getItem: (key: string) => store[key], | ||
removeItem: function (key: string) { | ||
delete store[key]; | ||
}, | ||
setItem: function (key: string, value: string) { | ||
store[key] = value.toString(); | ||
}, | ||
}; | ||
})(); | ||
|
||
describe(`${setLocale.name}()`, () => { | ||
beforeEach(() => { | ||
window.localStorage.clear(); | ||
Object.defineProperty(window, 'localStorage', { value: localStorageMock }); | ||
}); | ||
it('should setItem with "fr" if locale is "fr"', () => { | ||
setLocale('fr'); | ||
expect(localStorage.getItem('locale')).toStrictEqual('fr'); | ||
}); | ||
it('should setItem with "en" if locale is "en"', () => { | ||
setLocale('en'); | ||
expect(localStorage.getItem('locale')).toStrictEqual('en'); | ||
}); | ||
it('should setItem with "en" if locale is undefined', () => { | ||
setLocale(undefined as never); | ||
expect(localStorage.getItem('locale')).toStrictEqual('en'); | ||
}); | ||
it('should setItem with "en" if locale is null', () => { | ||
setLocale(null as never); | ||
expect(localStorage.getItem('locale')).toStrictEqual('en'); | ||
}); | ||
it('should setItem with "en" if locale is an empty string', () => { | ||
setLocale(''); | ||
expect(localStorage.getItem('locale')).toStrictEqual('en'); | ||
}); | ||
}); |
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,3 @@ | ||
export const setLocale = (locale: string): void => { | ||
localStorage.setItem('locale', locale || 'en'); | ||
}; |
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