diff --git a/website/static/js/profile.js b/website/static/js/profile.js index e5c2b6135c5..6b2264a092b 100644 --- a/website/static/js/profile.js +++ b/website/static/js/profile.js @@ -875,6 +875,8 @@ var ListViewModel = function(ContentModel, urls, modes, preventUnsaved) { self.idp_attr_institution = ko.observable('').extend({trimmed: true}); self.idp_attr_department = ko.observable('').extend({trimmed: true}); + self.idp_attr_institution_ja = ko.observable('').extend({trimmed: true}); + self.idp_attr_department_ja = ko.observable('').extend({trimmed: true}); self.tracked = self.contents; @@ -1026,6 +1028,14 @@ ListViewModel.prototype.setContentFromIdP = function(content) { if (!isEmptyStr(dep)) { content.department(dep); } + var inst_ja = self.idp_attr_institution_ja(); + if (!isEmptyStr(inst_ja) && ko.isObservable(content.institution_ja)) { + content.institution_ja(inst_ja); + } + var dep_ja = self.idp_attr_department_ja(); + if (!isEmptyStr(dep_ja) && ko.isObservable(content.department_ja)) { + content.department_ja(dep_ja); + } }; ListViewModel.prototype.unserialize = function(data) { @@ -1058,6 +1068,18 @@ ListViewModel.prototype.unserialize = function(data) { self.idp_attr_department($osf.decodeText(val).trim()); } } + if ('institution_ja' in idp_attr) { + val = idp_attr.institution_ja; + if (!isEmptyStr(val)) { + self.idp_attr_institution_ja($osf.decodeText(val).trim()); + } + } + if ('department_ja' in idp_attr) { + val = idp_attr.department_ja; + if (!isEmptyStr(val)) { + self.idp_attr_department_ja($osf.decodeText(val).trim()); + } + } } // Ensure at least one item is visible @@ -1385,5 +1407,7 @@ module.exports = { // Expose private viewmodels _NameViewModel: NameViewModel, SocialViewModel: SocialViewModel, - BaseViewModel: BaseViewModel + BaseViewModel: BaseViewModel, + _JobsViewModel: JobsViewModel, + _JobViewModel: JobViewModel }; diff --git a/website/static/js/tests/profile.test.js b/website/static/js/tests/profile.test.js index bbdd7f2c24e..083318bdae6 100644 --- a/website/static/js/tests/profile.test.js +++ b/website/static/js/tests/profile.test.js @@ -130,6 +130,76 @@ describe.skip('profile', () => { // TODO: Test citation computes }); + describe('JobsViewModel - Japanese fields', () => { + var jobsURLs = { + crud: '/api/v1/settings/jobs/' + }; + var jobServer; + var vm; + + before(() => { + jobServer = utils.createServer(sinon, [ + {url: jobsURLs.crud, response: {editable: true, contents: [], idp_attr: {}}} + ]); + }); + + after(() => { + jobServer.restore(); + }); + + beforeEach(() => { + vm = new profile._JobsViewModel(jobsURLs, ['view', 'edit'], false); + }); + + describe('unserialize', () => { + it('should store institution_ja and department_ja from idp_attr', () => { + vm.unserialize({ + contents: [], + idp_attr: { + institution: 'Test University', + department: 'CS Department', + institution_ja: 'テスト大学', + department_ja: '情報工学科' + } + }); + assert.equal(vm.idp_attr_institution_ja(), 'テスト大学'); + assert.equal(vm.idp_attr_department_ja(), '情報工学科'); + }); + }); + + describe('setContentFromIdP', () => { + var content; + + beforeEach(() => { + content = new profile._JobViewModel(); + vm.contents([content]); + }); + + it('should assign institution_ja and department_ja to content', () => { + vm.idp_attr_institution_ja('テスト大学'); + vm.idp_attr_department_ja('情報工学科'); + vm.setContentFromIdP(content); + assert.equal(content.institution_ja(), 'テスト大学'); + assert.equal(content.department_ja(), '情報工学科'); + }); + + it('should not throw when content does not have institution_ja observable', () => { + vm.idp_attr_institution_ja('テスト大学'); + vm.idp_attr_department_ja('情報工学科'); + var contentWithoutJa = { + institution: function() {}, + department: function() {}, + isValid: function() { return true; }, + institutionObjectEmpty: function() { return false; } + }; + vm.contents([contentWithoutJa]); + assert.doesNotThrow(function() { + vm.setContentFromIdP(contentWithoutJa); + }); + }); + }); + }); + // TODO: Test other profile ViewModels }); });