Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion website/static/js/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1385,5 +1407,7 @@ module.exports = {
// Expose private viewmodels
_NameViewModel: NameViewModel,
SocialViewModel: SocialViewModel,
BaseViewModel: BaseViewModel
BaseViewModel: BaseViewModel,
_JobsViewModel: JobsViewModel,
_JobViewModel: JobViewModel
};
70 changes: 70 additions & 0 deletions website/static/js/tests/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
Loading