Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "fileActions.currentFile" not set before using it #7624

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,11 +683,14 @@
// the details to be shown.
event.preventDefault();
var filename = $tr.attr('data-file');
this.fileActions.currentFile = $tr.find('td');
var mime = this.fileActions.getCurrentMimeType();
var type = this.fileActions.getCurrentType();
var permissions = this.fileActions.getCurrentPermissions();
var action = this.fileActions.get(mime, type, permissions)['Details'];
if (action) {
// also set on global object for legacy apps
window.FileActions.currentFile = this.fileActions.currentFile;
action(filename, {
$file: $tr,
fileList: this,
Expand Down
24 changes: 24 additions & 0 deletions apps/files/tests/js/filelistSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,30 @@ describe('OCA.Files.FileList tests', function() {
expect(context.fileActions).toBeDefined();
expect(context.dir).toEqual('/subdir');
});
it('Clicking on an empty space of the file row will trigger the "Details" action', function() {
var detailsActionStub = sinon.stub();
fileList.setFiles(testFiles);
// Override the "Details" action set internally by the FileList for
// easier testing.
fileList.fileActions.registerAction({
mime: 'all',
name: 'Details',
permissions: OC.PERMISSION_NONE,
actionHandler: detailsActionStub
});
// Ensure that the action works even if fileActions.currentFile is
// not set.
fileList.fileActions.currentFile = null;
var $tr = fileList.findFileEl('One.txt');
$tr.find('td.filename a.name').click();
expect(detailsActionStub.calledOnce).toEqual(true);
expect(detailsActionStub.getCall(0).args[0]).toEqual('One.txt');
var context = detailsActionStub.getCall(0).args[1];
expect(context.$file.is($tr)).toEqual(true);
expect(context.fileList).toBe(fileList);
expect(context.fileActions).toBe(fileList.fileActions);
expect(context.dir).toEqual('/subdir');
});
it('redisplays actions when new actions have been registered', function() {
var actionStub = sinon.stub();
var readyHandler = sinon.stub();
Expand Down