diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-12-18 14:19:14 +0300 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-12-18 14:19:14 +0300 |
commit | c20720cf84132d7bf14763aba0570bd8882f9c6d (patch) | |
tree | 69d943464250790018b156b2d75f6ca8ba1536fd /spec | |
parent | dcc0455c4864b4251559cfc922bf7c53ae317497 (diff) | |
parent | e720e8b8fbc9c7e04e528a54cce37d18c776d2d2 (diff) |
Merge branch 'winh-translate-contributors-page-dates' into 'master'
Translate contributors page dates
Closes #39283 and #38592
See merge request gitlab-org/gitlab-ce!15846
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/graphs/stat_graph_contributors_spec.js | 26 | ||||
-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 | 35 |
4 files changed, 112 insertions, 0 deletions
diff --git a/spec/javascripts/graphs/stat_graph_contributors_spec.js b/spec/javascripts/graphs/stat_graph_contributors_spec.js new file mode 100644 index 00000000000..962423462e7 --- /dev/null +++ b/spec/javascripts/graphs/stat_graph_contributors_spec.js @@ -0,0 +1,26 @@ +import ContributorsStatGraph from '~/graphs/stat_graph_contributors'; +import { ContributorsGraph } from '~/graphs/stat_graph_contributors_graph'; + +import { setLanguage } from '../helpers/locale_helper'; + +describe('ContributorsStatGraph', () => { + describe('change_date_header', () => { + beforeAll(() => { + setLanguage('de'); + }); + + afterAll(() => { + setLanguage(null); + }); + + it('uses the locale to display date ranges', () => { + ContributorsGraph.init_x_domain([{ date: '2013-01-31' }, { date: '2012-01-31' }]); + setFixtures('<div id="date_header"></div>'); + const graph = new ContributorsStatGraph(); + + graph.change_date_header(); + + expect(document.getElementById('date_header').innerText).toBe('31. Januar 2012 – 31. Januar 2013'); + }); + }); +}); 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 new file mode 100644 index 00000000000..29b0b21eed7 --- /dev/null +++ b/spec/javascripts/locale/index_spec.js @@ -0,0 +1,35 @@ +import { createDateTimeFormat, languageCode } from '~/locale'; + +import { setLanguage } from '../helpers/locale_helper'; + +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'); + }); + }); +}); |