From e952687dcdd5d5da7f081a7b1fea38fb9937d259 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 12 Feb 2015 16:49:31 +0100 Subject: Added unit test --- core/js/tests/specs/shareSpec.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'core/js/tests') diff --git a/core/js/tests/specs/shareSpec.js b/core/js/tests/specs/shareSpec.js index 7eb22261e10..21d93d4a4b0 100644 --- a/core/js/tests/specs/shareSpec.js +++ b/core/js/tests/specs/shareSpec.js @@ -26,6 +26,7 @@ describe('OC.Share tests', function() { var oldAppConfig; var loadItemStub; var autocompleteStub; + var avatarStub; beforeEach(function() { $('#testArea').append($('
')); @@ -54,6 +55,8 @@ describe('OC.Share tests', function() { var $el = $('
').data('ui-autocomplete', {}); return $el; }); + + avatarStub = sinon.stub($.fn, 'avatar'); }); afterEach(function() { /* jshint camelcase:false */ @@ -61,6 +64,7 @@ describe('OC.Share tests', function() { loadItemStub.restore(); autocompleteStub.restore(); + avatarStub.restore(); $('#dropdown').remove(); }); it('calls loadItem with the correct arguments', function() { @@ -405,6 +409,37 @@ describe('OC.Share tests', function() { }); }); }); + describe('check for avatar', function() { + beforeEach(function() { + loadItemStub.returns({ + reshare: [], + shares: [{ + id: 100, + item_source: 123, + permissions: 31, + share_type: OC.Share.SHARE_TYPE_USER, + share_with: 'user1', + share_with_displayname: 'User One' + }] + }); + OC.Share.showDropDown( + 'file', + 123, + $container, + true, + 31, + 'shared_file_name.txt' + ); + }); + it('test correct function call', function() { + expect(avatarStub.calledOnce).toEqual(true); + var args = avatarStub.getCall(0).args; + + expect($('#avatar-user1')[0]).toEqual(jasmine.anything()); + expect(args.length).toEqual(2); + expect(args[0]).toEqual('user1'); + }); + }); describe('"sharesChanged" event', function() { var autocompleteOptions; var handler; -- cgit v1.2.3 From ecb7d4477525942d6104168f9361337247af9c48 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 12 Feb 2015 17:05:59 +0100 Subject: Small unit test rewrite --- core/js/tests/specs/shareSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/js/tests') diff --git a/core/js/tests/specs/shareSpec.js b/core/js/tests/specs/shareSpec.js index 21d93d4a4b0..189c77b5ba7 100644 --- a/core/js/tests/specs/shareSpec.js +++ b/core/js/tests/specs/shareSpec.js @@ -435,7 +435,7 @@ describe('OC.Share tests', function() { expect(avatarStub.calledOnce).toEqual(true); var args = avatarStub.getCall(0).args; - expect($('#avatar-user1')[0]).toEqual(jasmine.anything()); + expect($('#avatar-user1').length).toEqual(1); expect(args.length).toEqual(2); expect(args[0]).toEqual('user1'); }); -- cgit v1.2.3 From 9a6da8e6e2739c42c0f2e458ab8738e8b018187f Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 13 Feb 2015 12:57:24 +0100 Subject: Extended avatar unit tests --- core/js/tests/specs/shareSpec.js | 75 ++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 14 deletions(-) (limited to 'core/js/tests') diff --git a/core/js/tests/specs/shareSpec.js b/core/js/tests/specs/shareSpec.js index 189c77b5ba7..1856fc27bc6 100644 --- a/core/js/tests/specs/shareSpec.js +++ b/core/js/tests/specs/shareSpec.js @@ -26,6 +26,7 @@ describe('OC.Share tests', function() { var oldAppConfig; var loadItemStub; var autocompleteStub; + var oldEnableAvatars; var avatarStub; beforeEach(function() { @@ -56,6 +57,8 @@ describe('OC.Share tests', function() { return $el; }); + oldEnableAvatars = oc_config.enable_avatars; + oc_config.enable_avatars = false; avatarStub = sinon.stub($.fn, 'avatar'); }); afterEach(function() { @@ -65,6 +68,7 @@ describe('OC.Share tests', function() { autocompleteStub.restore(); avatarStub.restore(); + oc_config.enable_avatars = oldEnableAvatars; $('#dropdown').remove(); }); it('calls loadItem with the correct arguments', function() { @@ -420,24 +424,67 @@ describe('OC.Share tests', function() { share_type: OC.Share.SHARE_TYPE_USER, share_with: 'user1', share_with_displayname: 'User One' + },{ + id: 101, + item_source: 123, + permissions: 31, + share_type: OC.Share.SHARE_TYPE_GROUP, + share_with: 'group', + share_with_displayname: 'group' }] }); - OC.Share.showDropDown( - 'file', - 123, - $container, - true, - 31, - 'shared_file_name.txt' - ); }); - it('test correct function call', function() { - expect(avatarStub.calledOnce).toEqual(true); - var args = avatarStub.getCall(0).args; - expect($('#avatar-user1').length).toEqual(1); - expect(args.length).toEqual(2); - expect(args[0]).toEqual('user1'); + describe('avatars enabled', function() { + beforeEach(function() { + oc_config.enable_avatars = true; + OC.Share.showDropDown( + 'file', + 123, + $container, + true, + 31, + 'shared_file_name.txt' + ); + }); + + afterEach(function() { + oc_config.enable_avatars = false; + }); + + it('test correct function call', function() { + expect(avatarStub.calledOnce).toEqual(true); + var args = avatarStub.getCall(0).args; + + + expect($('#shareWithList').children().length).toEqual(2); + + expect($('#avatar-user1').length).toEqual(1); + expect(args.length).toEqual(2); + expect(args[0]).toEqual('user1'); + }); + + it('test no avatar for groups', function() { + expect($('#shareWithList').children().length).toEqual(2); + expect($('#shareWithList li:nth-child(2) .avatar').attr('id')).not.toBeDefined(); + }); + }); + + describe('avatars disabled', function() { + beforeEach(function() { + OC.Share.showDropDown( + 'file', + 123, + $container, + true, + 31, + 'shared_file_name.txt' + ); + }); + + it('no avatar classes', function() { + expect($('.avatar').length).toEqual(0); + }); }); }); describe('"sharesChanged" event', function() { -- cgit v1.2.3