diff options
author | Tom Needham <tom@owncloud.com> | 2015-10-21 12:46:08 +0000 |
---|---|---|
committer | Tom Needham <tom@owncloud.com> | 2015-10-21 12:46:08 +0000 |
commit | 8a6d22d7514ffebc01c7c96513042c9ec3573334 (patch) | |
tree | 0a9d305f1e5f6cb9fa5c21acc647b5c85fb54c05 /core | |
parent | 2ca5b1aa1f9961948be2b1dbc1694203e6392f79 (diff) | |
download | nextcloud-server-8a6d22d7514ffebc01c7c96513042c9ec3573334.tar.gz nextcloud-server-8a6d22d7514ffebc01c7c96513042c9ec3573334.zip |
Add JS tests for share autocompletion handling
Diffstat (limited to 'core')
-rw-r--r-- | core/js/tests/specs/sharedialogviewSpec.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/core/js/tests/specs/sharedialogviewSpec.js b/core/js/tests/specs/sharedialogviewSpec.js index db34d55ebd7..ba5954c5d8e 100644 --- a/core/js/tests/specs/sharedialogviewSpec.js +++ b/core/js/tests/specs/sharedialogviewSpec.js @@ -692,5 +692,61 @@ describe('OC.Share.ShareDialogView', function() { expect(dialog.$el.find('.shareWithRemoteInfo').length).toEqual(0); }); }); + describe('autocompeltion of users', function() { + it('triggers autocomplete display and focus with data when ajax search succeeds', function () { + dialog.render(); + var response = sinon.stub(); + dialog.autocompleteHandler({term: 'bob'}, response); + var jsonData = JSON.stringify({ + "data": [{"label": "bob", "value": {"shareType": 0, "shareWith": "test"}}], + "status": "success" + }); + fakeServer.requests[0].respond( + 200, + {'Content-Type': 'application/json'}, + jsonData + ); + expect(response.calledWithExactly(JSON.parse(jsonData).data)).toEqual(true); + expect(autocompleteStub.calledWith("option", "autoFocus", true)).toEqual(true); + }); + + it('gracefully handles successful ajax call with failure content', function () { + dialog.render(); + var response = sinon.stub(); + dialog.autocompleteHandler({term: 'bob'}, response); + var jsonData = JSON.stringify({"status": "failure"}); + fakeServer.requests[0].respond( + 200, + {'Content-Type': 'application/json'}, + jsonData + ); + expect(response.calledWithExactly()).toEqual(true); + }); + + it('throws a notification when the ajax search lookup fails', function () { + notificationStub = sinon.stub(OC.Notification, 'show'); + dialog.render(); + dialog.autocompleteHandler({term: 'bob'}, sinon.stub()); + fakeServer.requests[0].respond(500); + expect(notificationStub.calledOnce).toEqual(true); + notificationStub.restore(); + }); + + describe('renders the autocomplete elements', function() { + it('renders a group element', function() { + dialog.render(); + var el = dialog.autocompleteRenderItem($("<ul></ul>"), {label: "1", value: { shareType: OC.Share.SHARE_TYPE_GROUP }}); + expect(el.is('li')).toEqual(true); + expect(el.hasClass('group')).toEqual(true); + }); + + it('renders a remote element', function() { + dialog.render(); + var el = dialog.autocompleteRenderItem($("<ul></ul>"), {label: "1", value: { shareType: OC.Share.SHARE_TYPE_REMOTE }}); + expect(el.is('li')).toEqual(true); + expect(el.hasClass('user')).toEqual(true); + }); + }); + }); }); |