diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index a63960da2b..78168336bb 100644 --- a/core/js/sharedialogview.js +++ b/core/js/sharedialogview.js @@ -260,6 +260,9 @@ var suggestions = users.concat(groups).concat(remotes).concat(emails).concat(lookup); if (suggestions.length > 0) { + suggestions.sort(function (a, b) { + return OC.Util.naturalSortCompare(a.label, b.label); + }); $shareWithField .autocomplete("option", "autoFocus", true); diff --git a/core/js/tests/specs/sharedialogviewSpec.js b/core/js/tests/specs/sharedialogviewSpec.js index 307adea85f..7e3232f86e 100644 --- a/core/js/tests/specs/sharedialogviewSpec.js +++ b/core/js/tests/specs/sharedialogviewSpec.js @@ -490,6 +490,80 @@ describe('OC.Share.ShareDialogView', function() { }); }); describe('autocompletion of users', function() { + it('is sorted naturally', function () { + dialog.render(); + var response = sinon.stub(); + dialog.autocompleteHandler({term: 'p'}, response); + var jsonData = JSON.stringify({ + 'ocs' : { + 'meta' : { + 'status' : 'success', + 'statuscode' : 100, + 'message' : null + }, + 'data' : { + 'exact' : { + 'users' : [], + 'groups' : [], + 'remotes': [] + }, + 'users' : [{ + "label": "Peter A.", + "value": { + "shareType": 0, + "shareWith": "Peter A." + } + }, + { + "label": "Petra", + "value": { + "shareType": 0, + "shareWith": "Petra" + } + }, + { + "label": "peter B.", + "value": { + "shareType": 0, + "shareWith": "peter B." + } + }], + 'groups' : [], + 'remotes': [] + } + } + }); + + fakeServer.requests[0].respond( + 200, + {'Content-Type': 'application/json'}, + jsonData + ); + + expect(response.calledWithExactly([ + { + "label": "Peter A.", + "value": { + "shareType": 0, + "shareWith": "Peter A." + } + }, + { + "label": "peter B.", + "value": { + "shareType": 0, + "shareWith": "peter B." + } + }, + { + "label": "Petra", + "value": { + "shareType": 0, + "shareWith": "Petra" + } + } + ])).toEqual(true); + }); it('triggers autocomplete display and focus with data when ajax search succeeds', function () { dialog.render(); var response = sinon.stub();