From 9334023579e1bf2472d95335d000b10393d10d57 Mon Sep 17 00:00:00 2001 From: hcphat Date: Thu, 18 Jun 2026 15:18:37 +0700 Subject: [PATCH] =?UTF-8?q?ref=20[Bug][NII=20Redmine#60941]=20IdP=E3=81=8B?= =?UTF-8?q?=E3=82=89=E5=8F=97=E9=A0=98=E3=81=99=E3=82=8B=E8=AA=8D=E8=A8=BC?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E8=A1=A8=E7=A4=BA=E3=81=AE=E6=97=A5=E6=9C=AC?= =?UTF-8?q?=E8=AA=9E=E6=96=87=E5=AD=97=E5=8C=96=E3=81=91=E8=A7=A3=E6=B6=88?= =?UTF-8?q?=E3=81=AB=E3=81=8A=E3=81=91=E3=82=8B=E3=80=81=E3=83=97=E3=83=AD?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB=E8=A8=AD=E5=AE=9A=E7=94=BB?= =?UTF-8?q?=E9=9D=A2=E3=80=8CIdP=E3=83=97=E3=83=AD=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=81=8B=E3=82=89=E8=AA=AD=E8=BE=BC=E3=81=BF?= =?UTF-8?q?=E3=80=8D=E3=83=AA=E3=83=B3=E3=82=AF=E3=81=AE=E8=87=AA=E5=8B=95?= =?UTF-8?q?=E5=85=A5=E5=8A=9B=E7=AF=84=E5=9B=B2=E3=81=AB=E3=81=A4=E3=81=84?= =?UTF-8?q?=E3=81=A6:=20Fix=20IDP=20Japanese=20fields=20(institution=5Fja/?= =?UTF-8?q?department=5Fja)=20not=20auto-filled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- website/static/js/profile.js | 26 ++++++++- website/static/js/tests/profile.test.js | 70 +++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) 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 }); });