Skip to content

Commit e952687

Browse files
committed
Added unit test
1 parent 47b96c9 commit e952687

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

core/js/share.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ OC.Share={
656656
var html = '<li style="clear: both;" data-share-type="'+escapeHTML(shareType)+'" data-share-with="'+escapeHTML(shareWith)+'" title="' + escapeHTML(shareWith) + '">';
657657
var showCrudsButton;
658658
html += '<a href="#" class="unshare"><img class="svg" alt="'+t('core', 'Unshare')+'" title="'+t('core', 'Unshare')+'" src="'+OC.imagePath('core', 'actions/delete')+'"/></a>';
659-
if (shareType == OC.Share.SHARE_TYPE_USER) {
659+
if (shareType === OC.Share.SHARE_TYPE_USER) {
660660
html += '<div id="avatar-' + escapeHTML(shareWith) + '" class="avatar"></div>';
661661
} else {
662662
html += '<div class="avatar" style="padding-right: 32px"></div>';
@@ -692,7 +692,7 @@ OC.Share={
692692
html += '</div>';
693693
html += '</li>';
694694
html = $(html).appendTo('#shareWithList');
695-
if (shareType == OC.Share.SHARE_TYPE_USER) {
695+
if (shareType === OC.Share.SHARE_TYPE_USER) {
696696
$('#avatar-' + escapeHTML(shareWith)).avatar(escapeHTML(shareWith), 32);
697697
}
698698
// insert cruds button into last label element

core/js/tests/specs/shareSpec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('OC.Share tests', function() {
2626
var oldAppConfig;
2727
var loadItemStub;
2828
var autocompleteStub;
29+
var avatarStub;
2930

3031
beforeEach(function() {
3132
$('#testArea').append($('<div id="shareContainer"></div>'));
@@ -54,13 +55,16 @@ describe('OC.Share tests', function() {
5455
var $el = $('<div></div>').data('ui-autocomplete', {});
5556
return $el;
5657
});
58+
59+
avatarStub = sinon.stub($.fn, 'avatar');
5760
});
5861
afterEach(function() {
5962
/* jshint camelcase:false */
6063
oc_appconfig.core = oldAppConfig;
6164
loadItemStub.restore();
6265

6366
autocompleteStub.restore();
67+
avatarStub.restore();
6468
$('#dropdown').remove();
6569
});
6670
it('calls loadItem with the correct arguments', function() {
@@ -405,6 +409,37 @@ describe('OC.Share tests', function() {
405409
});
406410
});
407411
});
412+
describe('check for avatar', function() {
413+
beforeEach(function() {
414+
loadItemStub.returns({
415+
reshare: [],
416+
shares: [{
417+
id: 100,
418+
item_source: 123,
419+
permissions: 31,
420+
share_type: OC.Share.SHARE_TYPE_USER,
421+
share_with: 'user1',
422+
share_with_displayname: 'User One'
423+
}]
424+
});
425+
OC.Share.showDropDown(
426+
'file',
427+
123,
428+
$container,
429+
true,
430+
31,
431+
'shared_file_name.txt'
432+
);
433+
});
434+
it('test correct function call', function() {
435+
expect(avatarStub.calledOnce).toEqual(true);
436+
var args = avatarStub.getCall(0).args;
437+
438+
expect($('#avatar-user1')[0]).toEqual(jasmine.anything());
439+
expect(args.length).toEqual(2);
440+
expect(args[0]).toEqual('user1');
441+
});
442+
});
408443
describe('"sharesChanged" event', function() {
409444
var autocompleteOptions;
410445
var handler;

0 commit comments

Comments
 (0)