diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2017-12-11 15:25:49 +0300 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2017-12-18 13:13:41 +0300 |
commit | 4f73e14f2c30c907d4ead31dd8034aea37f14544 (patch) | |
tree | ceac6268f2a8942fdd30fbea372ce85b1205d32b /spec | |
parent | 2bad3b0eaf855a8050e565a05deebdf323ca4fd2 (diff) |
Add createDateTimeFormat to format dates based on locale
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/locale/index_spec.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/javascripts/locale/index_spec.js b/spec/javascripts/locale/index_spec.js new file mode 100644 index 00000000000..0f685c6d69d --- /dev/null +++ b/spec/javascripts/locale/index_spec.js @@ -0,0 +1,43 @@ +import { createDateTimeFormat, languageCode } from '~/locale'; + +const setLanguage = (languageCode) => { + const htmlElement = document.querySelector('html'); + + if (languageCode) { + htmlElement.setAttribute('lang', languageCode); + } else { + htmlElement.removeAttribute('lang'); + } +}; + +describe('locale', () => { + afterEach(() => { + setLanguage(null); + }); + + describe('languageCode', () => { + it('parses the lang attribute', () => { + setLanguage('ja'); + + expect(languageCode()).toBe('ja'); + }); + + it('falls back to English', () => { + setLanguage(null); + + expect(languageCode()).toBe('en'); + }); + }); + + describe('createDateTimeFormat', () => { + beforeEach(() => { + setLanguage('de'); + }); + + it('creates an instance of Intl.DateTimeFormat', () => { + const dateFormat = createDateTimeFormat({ year: 'numeric', month: 'long', day: 'numeric' }); + + expect(dateFormat.format(new Date(2015, 6, 3))).toBe('3. Juli 2015'); + }); + }); +}); |