From bd8fde63a63c43a9debe6399167fadb8297eb097 Mon Sep 17 00:00:00 2001 From: tohosaku Date: Tue, 24 Mar 2020 13:35:22 +0900 Subject: [PATCH 1/2] Fix languages customization --- src/defaults.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/defaults.js b/src/defaults.js index 2d2a7e1a3..df8d705e2 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -260,10 +260,10 @@ function upload (type, file, cbs) { /* String translate function */ function translate (key, variables) { - const lang = languages[language] - if (!lang) throw new Error(`Unknown language ${language}`) + const lang = defaults.languages[defaults.language] + if (!lang) throw new Error(`Unknown language ${defaults.language}`) - let string = lang[key] || languages[default_language][key] + let string = lang[key] || defaults.languages[default_language][key] if (typeof string === 'undefined') throw new Error(`Unknown translate string ${key}`) From 04a58061b73a4b6920b920cef62f31d99737b79b Mon Sep 17 00:00:00 2001 From: tohosaku Date: Tue, 7 Apr 2020 12:38:52 +0900 Subject: [PATCH 2/2] Add Unit Test --- tests/unit/defaults.spec.js | 54 ++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/tests/unit/defaults.spec.js b/tests/unit/defaults.spec.js index ab5086a2b..7b4a14b57 100644 --- a/tests/unit/defaults.spec.js +++ b/tests/unit/defaults.spec.js @@ -1,22 +1,38 @@ -/* -Stub test file -TODO: Write unit tests for all interfaces -*/ +import { defaults } from '../../src/defaults' -import { defaults } from '../../src/defaults'; +describe('defaults', () => { + it('should be an object', () => { + expect(typeof defaults).toBe('object') + }) + it('should have standard properties defined', () => { + expect(typeof (defaults.themes)).toBe('object') + expect(typeof (defaults.templates)).toBe('object') + expect(typeof (defaults.iconlibs)).toBe('object') + expect(typeof (defaults.editors)).toBe('object') + expect(typeof (defaults.languages)).toBe('object') + expect(Array.isArray(defaults.resolvers)).toBe(true) + expect(Array.isArray(defaults.custom_validators)).toBe(true) + }) +}) -describe("defaults", function() { - it("should be an object", function(){ - expect(typeof defaults).toBe("object"); - }); - it("should have standard properties defined", function(){ - expect(typeof(defaults.themes)).toBe("object"); - expect(typeof(defaults.templates)).toBe("object"); - expect(typeof(defaults.iconlibs)).toBe("object"); - expect(typeof(defaults.editors)).toBe("object"); - expect(typeof(defaults.languages)).toBe("object"); - expect(Array.isArray(defaults.resolvers)).toBe(true); - expect(Array.isArray(defaults.custom_validators)).toBe(true); - }); -}); +describe('languages test', () => { + beforeEach(() => { + defaults.languages.es = { + error_notset: 'propiedad debe existir' + } + defaults.language = 'es' + }) + + it('should translate other language', () => { + expect(defaults.translate('error_notset')).toBe('propiedad debe existir') + }) + + it('should return default message. if no translation', () => { + expect(defaults.translate('error_notempty')).toBe('Value required') + }) + + it('throw error to unknown translate string', () => { + expect(() => defaults.translate('unknown_message')).toThrow() + }) +})