X Tutup
Skip to content

Commit 557f148

Browse files
JammingBenphil-davis
authored andcommitted
Add JS tests, rename some things
1 parent da3687c commit 557f148

File tree

7 files changed

+125
-12
lines changed

7 files changed

+125
-12
lines changed

apps/files/js/fileactions.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@
223223

224224
/**
225225
* Returns an array of file actions matching the given conditions while
226-
* omitting the default actions like "Rename", "Download" etc.
226+
* omitting the actions which apply to all mime types ("Rename", "Download" etc.)
227227
*
228228
* @param {string} mime mime type
229229
* @param {string} type "dir" or "file"
230230
* @param {int} permissions permissions
231231
*
232232
* @return {Object.<OCA.Files.FileAction>} array of action specs
233233
*/
234-
getActionsWithoutDefaults: function (mime, type, permissions) {
234+
getActionsWithoutAll: function (mime, type, permissions) {
235235
return this._getActions(mime, type, permissions, true);
236236
},
237237

@@ -289,14 +289,14 @@
289289
* @param {string} mime mime type
290290
* @param {string} type "dir" or "file"
291291
* @param {int} permissions permissions
292-
* @param {boolean} excludeDefaults excludeDefaults
292+
* @param {boolean} excludeAll excludeAll
293293
*
294294
* @return {Object.<OCA.Files.FileAction>} array of action specs
295295
*/
296-
_getActions: function (mime, type, permissions, excludeDefaults) {
296+
_getActions: function (mime, type, permissions, excludeAll) {
297297
var actions = {};
298298

299-
if (this.actions.all && excludeDefaults !== true) {
299+
if (this.actions.all && excludeAll !== true) {
300300
actions = $.extend(actions, this.actions.all);
301301
}
302302
if (type) {//type is 'dir' or 'file'

apps/files/js/fileactionsappdrawer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090

9191
render: function() {
9292
var fileActions = this._context.fileActions;
93-
var actions = fileActions.getActionsWithoutDefaults(
93+
var actions = fileActions.getActionsWithoutAll(
9494
fileActions.getCurrentMimeType(),
9595
fileActions.getCurrentType(),
9696
fileActions.getCurrentPermissions()

apps/files/js/filelist.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@
665665
var mime = this.fileActions.getCurrentMimeType();
666666
var type = this.fileActions.getCurrentType();
667667
var permissions = this.fileActions.getCurrentPermissions();
668-
var actionsWithoutDefaults = this.fileActions.getActionsWithoutDefaults(mime,type, permissions);
668+
var actionsWithoutAll = this.fileActions.getActionsWithoutAll(mime,type, permissions);
669669
var context = {
670670
$file: $tr,
671671
fileList: this,
@@ -674,7 +674,7 @@
674674
};
675675

676676
// don't show app drawer for directories as we want to open them per default
677-
if (Object.keys(actionsWithoutDefaults).length > 1 && type !== 'dir') {
677+
if (Object.keys(actionsWithoutAll).length > 1 && type !== 'dir') {
678678
var appDrawer = new OCA.Files.FileActionsAppDrawer();
679679
appDrawer.show(context, $tr.find('td.filename'));
680680
event.preventDefault();

apps/files/tests/js/fileactionsSpec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,52 @@ describe('OCA.Files.FileActions tests', function() {
278278
expect($tr.find('.action.action-iconnoalttext').find('.icon').length).toEqual(1);
279279
expect($tr.find('.action.action-iconnoalttext').find('.hidden-visually').length).toEqual(0);
280280
});
281+
it('get all file actions for a specific mime type', function() {
282+
fileActions.registerAction({
283+
mime: 'application/pdf',
284+
name: 'View PDF file',
285+
type: OCA.Files.FileActions.TYPE_INLINE,
286+
permissions: OC.PERMISSION_READ,
287+
icon: OC.imagePath('core', 'actions/test')
288+
});
289+
290+
fileActions.registerAction({
291+
mime: 'application/pdf',
292+
name: 'Edit PDF file',
293+
type: OCA.Files.FileActions.TYPE_INLINE,
294+
permissions: OC.PERMISSION_UPDATE,
295+
icon: OC.imagePath('core', 'actions/test')
296+
});
297+
298+
var actions = fileActions.getActions(
299+
'application/pdf',
300+
OCA.Files.FileActions.TYPE_INLINE,
301+
OC.PERMISSION_READ
302+
);
303+
304+
expect(Object.keys(actions).length).toEqual(3);
305+
expect(Object.keys(actions).indexOf('View PDF file') >= 0).toEqual(true);
306+
expect(Object.keys(actions).indexOf('Edit PDF file') <= 0).toEqual(true);
307+
});
308+
it('get file actions for a specific mime type omitting the ones which apply to all mime types', function() {
309+
fileActions.registerAction({
310+
mime: 'application/pdf',
311+
name: 'View PDF file',
312+
type: OCA.Files.FileActions.TYPE_INLINE,
313+
permissions: OC.PERMISSION_READ,
314+
icon: OC.imagePath('core', 'actions/test')
315+
});
316+
317+
var actions = fileActions.getActionsWithoutAll(
318+
'application/pdf',
319+
OCA.Files.FileActions.TYPE_INLINE,
320+
OC.PERMISSION_READ
321+
);
322+
323+
expect(Object.keys(actions).length).toEqual(1);
324+
expect(Object.keys(actions).indexOf('View PDF file') >= 0).toEqual(true);
325+
expect(Object.keys(actions).indexOf('Testdefault') <= 0).toEqual(true);
326+
});
281327
});
282328
describe('action handler', function() {
283329
var actionStub, $tr, clock;

apps/files/tests/js/fileactionsmenuSpec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ describe('OCA.Files.FileActionsMenu tests', function() {
110110
expect($action.find('img').length).toEqual(0);
111111
expect($action.find('.no-icon').length).toEqual(1);
112112
});
113+
it('does render default actions', function() {
114+
expect(menu.$el.find('a[data-action=Testdefault]').length).toEqual(1);
115+
});
113116
it('does not render inline actions', function() {
114117
expect(menu.$el.find('a[data-action=Testinline]').length).toEqual(0);
115118
});

apps/files/tests/js/filelistSpec.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,6 +2351,67 @@ describe('OCA.Files.FileList tests', function() {
23512351
expect(context.fileActions).toBeDefined();
23522352
expect(context.dir).toEqual('/subdir');
23532353
});
2354+
it('clicking on a file name will render the app drawer context menu if more than one action applies for this mime type', function() {
2355+
var actionStub = sinon.stub();
2356+
fileList.setFiles(testFiles);
2357+
fileList.fileActions.registerAction({
2358+
mime: 'text/plain',
2359+
name: 'View file',
2360+
type: OCA.Files.FileActions.TYPE_INLINE,
2361+
permissions: OC.PERMISSION_ALL,
2362+
icon: function() {
2363+
return OC.imagePath('core','actions/history');
2364+
},
2365+
actionHandler: actionStub,
2366+
});
2367+
fileList.fileActions.registerAction({
2368+
mime: 'text/plain',
2369+
name: 'Edit file',
2370+
type: OCA.Files.FileActions.TYPE_INLINE,
2371+
permissions: OC.PERMISSION_ALL,
2372+
icon: function() {
2373+
return OC.imagePath('core','actions/history');
2374+
},
2375+
});
2376+
2377+
fileList.fileActions.setDefault('text/plain', 'View file');
2378+
var $tr = fileList.findFileEl('One.txt');
2379+
$tr.find('td.filename .nametext').click();
2380+
expect(actionStub.calledOnce).toEqual(false);
2381+
expect($tr.find('td.filename .fileActionsAppDrawer').length).toEqual(1);
2382+
expect($tr.find('td.filename .fileActionsAppDrawer a').length).toEqual(2);
2383+
var firstAction = $tr.find('td.filename .fileActionsAppDrawer a')[0];
2384+
firstAction.click();
2385+
expect(actionStub.calledOnce).toEqual(true);
2386+
});
2387+
it('clicking on a directory name will never render the app drawer context menu', function() {
2388+
var actionStub = sinon.stub();
2389+
fileList.setFiles(testFiles);
2390+
fileList.fileActions.registerAction({
2391+
mime: 'httpd/unix-directory',
2392+
name: 'View dir',
2393+
type: 'dir',
2394+
permissions: OC.PERMISSION_ALL,
2395+
icon: function() {
2396+
return OC.imagePath('core','actions/history');
2397+
},
2398+
actionHandler: actionStub,
2399+
});
2400+
fileList.fileActions.registerAction({
2401+
mime: 'httpd/unix-directory',
2402+
name: 'Edit dir',
2403+
type: 'dir',
2404+
permissions: OC.PERMISSION_ALL,
2405+
icon: function() {
2406+
return OC.imagePath('core','actions/history');
2407+
},
2408+
});
2409+
2410+
fileList.fileActions.setDefault('httpd/unix-directory', 'View dir');
2411+
var $tr = fileList.findFileEl('somedir');
2412+
$tr.find('td.filename .nametext').click();
2413+
expect(actionStub.calledOnce).toEqual(true);
2414+
});
23542415
it('redisplays actions when new actions have been registered', function() {
23552416
var actionStub = sinon.stub();
23562417
var readyHandler = sinon.stub();

changelog/unreleased/38132

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
Bugfix: Exception for multiple default file actions
1+
Enhancement: Context menu for files in case multiple actions apply
22

3-
The fix adds an exception when requesting a default file action for a
4-
file to which more than one default action applies. This is the case
5-
if your ownCloud uses both the PDF Viewer and the Collabora app, for example.
3+
When triggering the default action for a file which can be opened or edited
4+
with more than one app, a new context menu is displayed. This menu will
5+
ask the user with which app the corresponding file should be opened.
6+
7+
This also solves the problem with some apps which set themselves as
8+
default without asking or even informing the user.
69

710
https://github.com/owncloud/core/pull/38132
811
https://github.com/owncloud/enterprise/issues/4261

0 commit comments

Comments
 (0)
X Tutup