From 2e4ddabd5805ab9250c7d6639868266cdbe46633 Mon Sep 17 00:00:00 2001 From: chrisala Date: Wed, 8 Jan 2025 14:33:37 +1100 Subject: [PATCH] Fix for #3402 --- grails-app/assets/javascripts/organisation.js | 6 ++-- src/test/js/spec/OrganisationSpec.js | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/grails-app/assets/javascripts/organisation.js b/grails-app/assets/javascripts/organisation.js index 500422f0f..40ebf051f 100644 --- a/grails-app/assets/javascripts/organisation.js +++ b/grails-app/assets/javascripts/organisation.js @@ -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() { diff --git a/src/test/js/spec/OrganisationSpec.js b/src/test/js/spec/OrganisationSpec.js index c59799a08..fd75833d6 100644 --- a/src/test/js/spec/OrganisationSpec.js +++ b/src/test/js/spec/OrganisationSpec.js @@ -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