diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2017-12-12 14:39:31 +0300 |
---|---|---|
committer | Winnie Hellmann <winnie@gitlab.com> | 2017-12-18 13:13:41 +0300 |
commit | 1109a5cea46b25b3bd27b095c5fd11881d88bd72 (patch) | |
tree | d98a26763f56fef0cebe894fd5fd4ece0870d1c2 /spec | |
parent | 3b679ef9f148f29aba09f84ba383063f34166d8c (diff) |
Move dateTickFormat to separate module
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/helpers/locale_helper.js | 11 | ||||
-rw-r--r-- | spec/javascripts/lib/utils/tick_formats_spec.js | 40 | ||||
-rw-r--r-- | spec/javascripts/locale/index_spec.js | 10 |
3 files changed, 52 insertions, 9 deletions
diff --git a/spec/javascripts/helpers/locale_helper.js b/spec/javascripts/helpers/locale_helper.js new file mode 100644 index 00000000000..99e6ce61234 --- /dev/null +++ b/spec/javascripts/helpers/locale_helper.js @@ -0,0 +1,11 @@ +/* eslint-disable import/prefer-default-export */ + +export const setLanguage = (languageCode) => { + const htmlElement = document.querySelector('html'); + + if (languageCode) { + htmlElement.setAttribute('lang', languageCode); + } else { + htmlElement.removeAttribute('lang'); + } +}; diff --git a/spec/javascripts/lib/utils/tick_formats_spec.js b/spec/javascripts/lib/utils/tick_formats_spec.js new file mode 100644 index 00000000000..283989b4fc8 --- /dev/null +++ b/spec/javascripts/lib/utils/tick_formats_spec.js @@ -0,0 +1,40 @@ +import { dateTickFormat, initDateFormats } from '~/lib/utils/tick_formats'; + +import { setLanguage } from '../../helpers/locale_helper'; + +describe('tick formats', () => { + describe('dateTickFormat', () => { + beforeAll(() => { + setLanguage('de'); + initDateFormats(); + }); + + afterAll(() => { + setLanguage(null); + }); + + it('returns year for first of January', () => { + const tick = dateTickFormat(new Date('2001-01-01')); + + expect(tick).toBe('2001'); + }); + + it('returns month for first of February', () => { + const tick = dateTickFormat(new Date('2001-02-01')); + + expect(tick).toBe('Februar'); + }); + + it('returns day and month for second of February', () => { + const tick = dateTickFormat(new Date('2001-02-02')); + + expect(tick).toBe('2. Feb.'); + }); + + it('ignores time', () => { + const tick = dateTickFormat(new Date('2001-02-02 12:34:56')); + + expect(tick).toBe('2. Feb.'); + }); + }); +}); diff --git a/spec/javascripts/locale/index_spec.js b/spec/javascripts/locale/index_spec.js index 0f685c6d69d..29b0b21eed7 100644 --- a/spec/javascripts/locale/index_spec.js +++ b/spec/javascripts/locale/index_spec.js @@ -1,14 +1,6 @@ import { createDateTimeFormat, languageCode } from '~/locale'; -const setLanguage = (languageCode) => { - const htmlElement = document.querySelector('html'); - - if (languageCode) { - htmlElement.setAttribute('lang', languageCode); - } else { - htmlElement.removeAttribute('lang'); - } -}; +import { setLanguage } from '../helpers/locale_helper'; describe('locale', () => { afterEach(() => { |