From 31fa2f73d4089630b158d23f765db3a675b77683 Mon Sep 17 00:00:00 2001 From: Ilja Neumann Date: Tue, 17 Jan 2017 14:35:22 +0100 Subject: [PATCH] Sharing dialog: Names sorting is case sensitive #25971 Sharing dialog: Names sorting is case sensitive: adding tests #25971 Signed-off-by: Morris Jobke --- core/js/sharedialogview.js | 3 + core/js/tests/specs/sharedialogviewSpec.js | 74 ++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js index a63960da2b8..78168336bb7 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 307adea85ff..7e3232f86e1 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(); -- 2.39.5