diff --git a/app-starter/WguAppTemplate.vue b/app-starter/WguAppTemplate.vue index ca1f6633..ad734937 100644 --- a/app-starter/WguAppTemplate.vue +++ b/app-starter/WguAppTemplate.vue @@ -120,6 +120,7 @@ export default { } }, created () { + this.setGlobalAppLang(); // initially set global app language lookup this.setDocumentTitle(); }, mounted () { @@ -180,17 +181,24 @@ export default { return moduleWins; }, /** - * Sets the document title from language file. - */ + * Sets the document title from language file. + */ setDocumentTitle () { document.title = this.$t('app.browserTitle') || document.title; + }, + /** + * Sets the current i18n language to the global app language lookup. + */ + setGlobalAppLang () { + Vue.prototype.appLanguage = this.$i18n.locale; } }, watch: { /** - * Watch for locale changes. - */ + * Watch for locale changes. + */ '$i18n.locale': function () { + this.setGlobalAppLang(); this.setDocumentTitle(); } } diff --git a/tests/unit/specs/WguAppTemplate.spec.js b/tests/unit/specs/WguAppTemplate.spec.js index a093ee7e..29e18fa1 100644 --- a/tests/unit/specs/WguAppTemplate.spec.js +++ b/tests/unit/specs/WguAppTemplate.spec.js @@ -89,5 +89,26 @@ describe('WguAppTpl.vue', () => { expect(moduleData[0].type).to.equal('wgu-infoclick-win'); expect(moduleData[0].target).to.equal('menu'); }); + + it('has a method setGlobalAppLang', () => { + expect(vm.setGlobalAppLang).to.be.a('function'); + }); + }); + + describe('global app language lookup', () => { + let comp; + let vm; + beforeEach(() => { + comp = shallowMount(WguAppTpl); + vm = comp.vm; + }); + + it('is set correctly', () => { + expect(vm.$i18n.locale).to.equal(Vue.prototype.appLanguage); + }); + + afterEach(() => { + comp.destroy(); + }); }); });