From 3a1d8fa45f22503ba9841d71b7ea630d400b2ae5 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Sun, 19 Nov 2017 22:41:28 +0100 Subject: [PATCH] adjust, fix and extend tests Signed-off-by: Arthur Schiwon --- core/js/share.js | 22 ++++++-------- core/js/tests/specs/shareSpec.js | 51 ++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/core/js/share.js b/core/js/share.js index 281c414b90..86954b2ced 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -197,24 +197,20 @@ OC.Share = _.extend(OC.Share || {}, { delete OC.Share.statuses[itemSource]; } }, - _formatRegularShare: function(shareWith, shareWithDisplayName, message) { - // display avatar of the user - var avatar = ''; - var hidden = '' + message + ' ' + escapeHTML(shareWithDisplayName) + ' '; - return avatar + hidden; - }, /** * Format a remote address * - * @param {String} remoteAddress full remote share + * @param {String} shareWith userid, full remote share, or whatever + * @param {String} shareWithDisplayName + * @param {String} message * @return {String} HTML code to display */ - _formatRemoteShare: function(remoteAddress, message) { - var parts = this._REMOTE_OWNER_REGEXP.exec(remoteAddress); + _formatRemoteShare: function(shareWith, shareWithDisplayName, message) { + var parts = this._REMOTE_OWNER_REGEXP.exec(shareWith); if (!parts) { // display avatar of the user - var avatar = ''; - var hidden = '' + message + ' ' + escapeHTML(remoteAddress) + ' '; + var avatar = ''; + var hidden = '' + message + ' ' + escapeHTML(shareWithDisplayName) + ' '; return avatar + hidden; } @@ -250,7 +246,7 @@ OC.Share = _.extend(OC.Share || {}, { _formatShareList: function(recipients) { var _parent = this; return $.map(recipients, function(shareWithDisplayName, shareWith) { - return _parent._formatRegularShare(shareWith, shareWithDisplayName, t('core', 'Shared with')); + return _parent._formatRemoteShare(shareWith, shareWithDisplayName, t('core', 'Shared with')); }); }, /** @@ -304,7 +300,7 @@ OC.Share = _.extend(OC.Share || {}, { // even if reshared, only show "Shared by" if (ownerId) { message = t('core', 'Shared by'); - avatars = this._formatRegularShare(ownerId, owner, message); + avatars = this._formatRemoteShare(ownerId, owner, message); } else if (recipients) { avatars = this._formatShareList(recipients); } diff --git a/core/js/tests/specs/shareSpec.js b/core/js/tests/specs/shareSpec.js index 70c698c99a..19e9a92ca9 100644 --- a/core/js/tests/specs/shareSpec.js +++ b/core/js/tests/specs/shareSpec.js @@ -45,6 +45,7 @@ describe('OC.Share tests', function() { var $action; $file.attr('data-share-owner', input); + $file.attr('data-share-owner-id', input); OC.Share.markFileAsShared($file); $action = $file.find('.action-share>span').parent(); @@ -119,6 +120,7 @@ describe('OC.Share tests', function() { it('shows a shared folder icon for folders shared with the current user', function() { $file.attr('data-type', 'dir'); $file.attr('data-share-owner', 'someoneelse'); + $file.attr('data-share-owner-id', 'someoneelse'); OC.Share.markFileAsShared($file); checkIcon('filetypes/folder-shared'); @@ -155,7 +157,9 @@ describe('OC.Share tests', function() { function checkRecipients(input, output, title) { var $action; - $file.attr('data-share-recipients', input); + var concatenated = _.values(input).join(', '); + $file.attr('data-share-recipients', concatenated); + $file.attr('data-share-recipient-data', JSON.stringify(input)); OC.Share.markFileAsShared($file, true); $action = $file.find('.action-share>span').parent(); @@ -177,66 +181,89 @@ describe('OC.Share tests', function() { } it('displays the local share owner as is', function() { - checkRecipients('User One', 'Shared with User One', null); + checkRecipients({'User One': 'User One'}, 'Shared with User One', null); }); it('displays the user name part of a remote recipient', function() { checkRecipients( - 'User One@someserver.com', + {'User One@someserver.com': 'User One@someserver.com'}, 'User One@…', 'Shared with User One@someserver.com' ); checkRecipients( - 'User One@someserver.com/', + '{User One@someserver.com/: User One@someserver.com/}', 'User One@…', 'Shared with User One@someserver.com' ); checkRecipients( - 'User One@someserver.com/root/of/owncloud', + {'User One@someserver.com/root/of/owncloud': 'User One@someserver.com/root/of/owncloud'}, 'User One@…', 'Shared with User One@someserver.com' ); }); it('displays the user name part with domain of a remote share owner', function() { checkRecipients( - 'User One@example.com@someserver.com', + {'User One@example.com@someserver.com': 'User One@example.com@someserver.com'}, 'User One@example.com', 'Shared with User One@example.com@someserver.com' ); checkRecipients( - 'User One@example.com@someserver.com/', + {'User One@example.com@someserver.com/': 'User One@example.com@someserver.com/'}, 'User One@example.com', 'Shared with User One@example.com@someserver.com' ); checkRecipients( - 'User One@example.com@someserver.com/root/of/owncloud', + {'User One@example.com@someserver.com/root/of/nextcloud': 'User One@example.com@someserver.com/root/of/nextcloud'}, 'User One@example.com', 'Shared with User One@example.com@someserver.com' ); }); it('display multiple remote recipients', function() { checkRecipients( - 'One@someserver.com, two@otherserver.com', + { + 'One@someserver.com': 'One@someserver.com', + 'two@otherserver.com': 'two@otherserver.com' + }, 'One@… two@…', ['Shared with One@someserver.com', 'Shared with two@otherserver.com'] ); checkRecipients( - 'One@someserver.com/, two@otherserver.com', + { + 'One@someserver.com/': 'One@someserver.com/', + 'two@otherserver.com': 'two@otherserver.com' + }, 'One@… two@…', ['Shared with One@someserver.com', 'Shared with two@otherserver.com'] ); checkRecipients( - 'One@someserver.com/root/of/owncloud, two@otherserver.com', + { + 'One@someserver.com/root/of/owncloud': 'One@someserver.com/root/of/owncloud', + 'two@otherserver.com': 'two@otherserver.com' + }, 'One@… two@…', ['Shared with One@someserver.com', 'Shared with two@otherserver.com'] ); }); it('display mixed recipients', function() { checkRecipients( - 'One, two@otherserver.com', + { + 'One': 'One', + 'two@otherserver.com': 'two@otherserver.com' + }, 'Shared with One two@…', ['Shared with two@otherserver.com'] ); }); + it('display multiple with divergent displaynames', function() { + checkRecipients( + { + 'One': 'Yoko Ono', + 'two@otherserver.com': 'two@otherserver.com', + 'Three': 'Green, Mina' + }, + 'Shared with Yoko Ono two@… Shared with Green, Mina', + ['Shared with two@otherserver.com'] + ); + }); }); }); });