Skip to content

Commit

Permalink
Merge pull request #3406 from AtlasOfLivingAustralia/feature/issue3404
Browse files Browse the repository at this point in the history
Fix for #3402
  • Loading branch information
salomon-j authored Jan 9, 2025
2 parents 02aefec + 2e4ddab commit d378fc8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
6 changes: 3 additions & 3 deletions grails-app/assets/javascripts/organisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,16 @@ OrganisationViewModel = function (props, options) {
self.transients = self.transients || {};

function toTitleCase(name) {
return name.replace(/\S+/g, function(word) {
return name.replace(/\S+/g, function(word, offset) {
if (!word) {
return word;
}
word = word.toLowerCase();
var joiningWords = ['and', 'of', 'the', 'in', 'for', 'to', 'a', 'an', 'on', 'at', 'by', 'with', 'from', 'as', 'but', 'or', 'nor'];
if (joiningWords.indexOf(word) >= 0) {
if (offset && joiningWords.indexOf(word) >= 0) {
return word;
}
return word.charAt(0).toUpperCase() + word.substring(1)
return word.charAt(0).toUpperCase() + word.substring(1);
});
}
self.prepopulateFromABN = function() {
Expand Down
33 changes: 33 additions & 0 deletions src/test/js/spec/OrganisationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,37 @@ describe("OrganisationViewModel Spec", function () {

});

it("Can tidy the case of the org entity name", function() {
var options = {organisationSaveUrl:'/test/url', healthCheckUrl:'/test/health'};
var org = { name: '', organisationId:"org1" };
var model = new OrganisationPageViewModel(org, options);

var inputOutput = [
["TEST ALL CAPS", "Test All Caps"],
["THE TEST FOR FIRST JOINING WORD", "The Test for First Joining Word"],
["Another test", "Another Test"],
["Already Correct", "Already Correct"]
];

let result = {
entityName:''
};

spyOn($, 'get').and.callFake(function () {
var d = $.Deferred();
// resolve using our mock data
d.resolve(result);
return d.promise();
});

for (var i=0; i<inputOutput.length; i++) {
model.name(''); // The name won't be overwritten if already set.
result.entityName = inputOutput[i][0];
model.prepopulateFromABN();


expect(model.name()).toEqual(inputOutput[i][1]);
}
});

});

0 comments on commit d378fc8

Please sign in to comment.