Skip to content

Commit 2e4ddab

Browse files
committed
Fix for #3402
1 parent 2c72597 commit 2e4ddab

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

grails-app/assets/javascripts/organisation.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,16 @@ OrganisationViewModel = function (props, options) {
228228
self.transients = self.transients || {};
229229

230230
function toTitleCase(name) {
231-
return name.replace(/\S+/g, function(word) {
231+
return name.replace(/\S+/g, function(word, offset) {
232232
if (!word) {
233233
return word;
234234
}
235235
word = word.toLowerCase();
236236
var joiningWords = ['and', 'of', 'the', 'in', 'for', 'to', 'a', 'an', 'on', 'at', 'by', 'with', 'from', 'as', 'but', 'or', 'nor'];
237-
if (joiningWords.indexOf(word) >= 0) {
237+
if (offset && joiningWords.indexOf(word) >= 0) {
238238
return word;
239239
}
240-
return word.charAt(0).toUpperCase() + word.substring(1)
240+
return word.charAt(0).toUpperCase() + word.substring(1);
241241
});
242242
}
243243
self.prepopulateFromABN = function() {

src/test/js/spec/OrganisationSpec.js

+33
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,37 @@ describe("OrganisationViewModel Spec", function () {
155155

156156
});
157157

158+
it("Can tidy the case of the org entity name", function() {
159+
var options = {organisationSaveUrl:'/test/url', healthCheckUrl:'/test/health'};
160+
var org = { name: '', organisationId:"org1" };
161+
var model = new OrganisationPageViewModel(org, options);
162+
163+
var inputOutput = [
164+
["TEST ALL CAPS", "Test All Caps"],
165+
["THE TEST FOR FIRST JOINING WORD", "The Test for First Joining Word"],
166+
["Another test", "Another Test"],
167+
["Already Correct", "Already Correct"]
168+
];
169+
170+
let result = {
171+
entityName:''
172+
};
173+
174+
spyOn($, 'get').and.callFake(function () {
175+
var d = $.Deferred();
176+
// resolve using our mock data
177+
d.resolve(result);
178+
return d.promise();
179+
});
180+
181+
for (var i=0; i<inputOutput.length; i++) {
182+
model.name(''); // The name won't be overwritten if already set.
183+
result.entityName = inputOutput[i][0];
184+
model.prepopulateFromABN();
185+
186+
187+
expect(model.name()).toEqual(inputOutput[i][1]);
188+
}
189+
});
190+
158191
});

0 commit comments

Comments
 (0)