From 6bf6ff9564640190413d255ed28181f3d9880ea3 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sat, 3 Oct 2015 15:47:20 +0200 Subject: [PATCH] If an inline files action provides an alt text show it * Added unit tests for icon display * Added unit tests for icon alt text display --- apps/files/js/fileactions.js | 3 +- apps/files/tests/js/fileactionsSpec.js | 56 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js index bde0b094b8..079c5330ec 100644 --- a/apps/files/js/fileactions.js +++ b/apps/files/js/fileactions.js @@ -144,7 +144,8 @@ order: action.order || 0, icon: action.icon, permissions: action.permissions, - type: action.type || FileActions.TYPE_DROPDOWN + type: action.type || FileActions.TYPE_DROPDOWN, + altText: action.altText || '' }; if (_.isUndefined(action.displayName)) { actionSpec.displayName = t('files', name); diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js index 1254843e66..6a57c56c3a 100644 --- a/apps/files/tests/js/fileactionsSpec.js +++ b/apps/files/tests/js/fileactionsSpec.js @@ -151,6 +151,62 @@ describe('OCA.Files.FileActions tests', function() { expect($tr.find('.action.action-match').length).toEqual(1); expect($tr.find('.action.action-nomatch').length).toEqual(0); }); + it('display inline icon', function() { + fileActions.registerAction({ + name: 'Icon', + displayName: 'IconDisplay', + type: OCA.Files.FileActions.TYPE_INLINE, + mime: 'all', + icon: OC.imagePath('core', 'actions/icon'), + permissions: OC.PERMISSION_READ + }); + fileActions.registerAction({ + name: 'NoIcon', + displayName: 'NoIconDisplay', + type: OCA.Files.FileActions.TYPE_INLINE, + mime: 'all', + permissions: OC.PERMISSION_READ + }); + + fileActions.display($tr.find('td.filename'), true, fileList); + + expect($tr.find('.action.action-icon').length).toEqual(1); + expect($tr.find('.action.action-icon').find('img').length).toEqual(1); + expect($tr.find('.action.action-icon').find('img').eq(0).attr('src')).toEqual(OC.imagePath('core', 'actions/icon')); + + expect($tr.find('.action.action-noicon').length).toEqual(1); + expect($tr.find('.action.action-noicon').find('img').length).toEqual(0); + }); + it('display alt text on inline icon', function() { + fileActions.registerAction({ + name: 'IconAltText', + displayName: 'IconAltTextDisplay', + type: OCA.Files.FileActions.TYPE_INLINE, + mime: 'all', + icon: OC.imagePath('core', 'actions/iconAltText'), + altText: 'alt icon text', + permissions: OC.PERMISSION_READ + }); + + fileActions.registerAction({ + name: 'IconNoAltText', + displayName: 'IconNoAltTextDisplay', + type: OCA.Files.FileActions.TYPE_INLINE, + mime: 'all', + icon: OC.imagePath('core', 'actions/iconNoAltText'), + permissions: OC.PERMISSION_READ + }); + + fileActions.display($tr.find('td.filename'), true, fileList); + + expect($tr.find('.action.action-iconalttext').length).toEqual(1); + expect($tr.find('.action.action-iconalttext').find('img').length).toEqual(1); + expect($tr.find('.action.action-iconalttext').find('img').eq(0).attr('alt')).toEqual('alt icon text'); + + expect($tr.find('.action.action-iconnoalttext').length).toEqual(1); + expect($tr.find('.action.action-iconnoalttext').find('img').length).toEqual(1); + expect($tr.find('.action.action-iconnoalttext').find('img').eq(0).attr('alt')).toEqual(''); + }); }); describe('action handler', function() { var actionStub, $tr, clock;