feat(localization): add localization for static strings

This commit is contained in:
David Litvak
2017-11-01 15:37:15 +01:00
committed by Benedikt Rötsch
parent eaec09a594
commit 68a8052bdf
24 changed files with 333 additions and 99 deletions

View File

@@ -7,7 +7,7 @@ describe('courses', () => {
return request(app).get('/courses')
.expect(200)
.then((response) => {
expect(response.text.match(/<h1>All Courses /)).toBeTruthy()
expect(response.text.match(/<h1>All courses /)).toBeTruthy()
})
})
test('it should render a course', () => {

View File

@@ -2,6 +2,7 @@
const { getCourses, getCourse, getCoursesByCategory, getLesson } = require('../../routes/courses')
const { getSettings } = require('../../routes/settings')
const { mockCourse, mockCategory } = require('./mocks/index')
const { translate, initializeTranslations } = require('../../i18n/i18n')
jest.mock('../../services/contentful')
const contentful = require('../../services/contentful')
@@ -25,6 +26,8 @@ const response = {
}
beforeAll(() => {
initializeTranslations()
contentful.getCourses.mockImplementation(() => [mockCourse])
contentful.getCourse.mockImplementation(() => mockCourse)
@@ -45,7 +48,7 @@ describe('Courses', () => {
test('it should courses list once', async () => {
await getCourses(request, response)
expect(response.render.mock.calls[0][0]).toBe('courses')
expect(response.render.mock.calls[0][1].title).toBe('All Courses (1)')
expect(response.render.mock.calls[0][1].title).toBe('All courses (1)')
expect(response.render.mock.calls[0][1].courses.length).toBe(1)
expect(response.render.mock.calls.length).toBe(1)
})
@@ -88,3 +91,17 @@ describe('Settings', () => {
expect(response.render.mock.calls[0][1].settings).toBe(response.locals.settings)
})
})
describe('i18n', () => {
test('It returns an error when locale file is not found', () => {
expect(translate('foo', 'bar-locale')).toBe('Localization file for bar-locale is not available')
})
test('It returns an error when symbol is not found on locale file', () => {
expect(translate('foo', 'en-US')).toBe('Translation not found for foo in en-US')
})
test('It returns the translated string when symbol is found on locale file', () => {
expect(translate('coursesLabel', 'en-US')).toBe('Courses')
})
})