summaryrefslogtreecommitdiffstats
path: root/apps/files/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-08-12 17:30:20 +0200
committerVincent Petry <pvince81@owncloud.com>2015-08-12 17:30:20 +0200
commitc964eff17b1a7feeab794f6035a7beff8143ac85 (patch)
tree0434d46c76dc42c0b8ba9323d7aff600fa320428 /apps/files/tests
parent997577cf7a5edc076c4039a7fc7c1c08c050a996 (diff)
downloadnextcloud-server-c964eff17b1a7feeab794f6035a7beff8143ac85.tar.gz
nextcloud-server-c964eff17b1a7feeab794f6035a7beff8143ac85.zip
Make file actions work from sidebar
The favorite icon in the sidebar now triggers the file action and also updates itself according to the model's state when triggered from the file row. The thumbnail triggers the default action. Currently only one FileInfoModel is used for the selection and state synchronization between views. FileList reload now auto-closes the sidebar.
Diffstat (limited to 'apps/files/tests')
-rw-r--r--apps/files/tests/js/detailsviewSpec.js2
-rw-r--r--apps/files/tests/js/fileactionsSpec.js32
-rw-r--r--apps/files/tests/js/filelistSpec.js14
-rw-r--r--apps/files/tests/js/mainfileinfodetailviewSpec.js129
4 files changed, 144 insertions, 33 deletions
diff --git a/apps/files/tests/js/detailsviewSpec.js b/apps/files/tests/js/detailsviewSpec.js
index db1e24fd68e..4261aa53c94 100644
--- a/apps/files/tests/js/detailsviewSpec.js
+++ b/apps/files/tests/js/detailsviewSpec.js
@@ -26,7 +26,7 @@ describe('OCA.Files.DetailsView tests', function() {
detailsView = new OCA.Files.DetailsView();
});
afterEach(function() {
- detailsView.destroy();
+ detailsView.remove();
detailsView = undefined;
});
it('renders itself empty when nothing registered', function() {
diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js
index 236cff6cafd..1254843e66a 100644
--- a/apps/files/tests/js/fileactionsSpec.js
+++ b/apps/files/tests/js/fileactionsSpec.js
@@ -27,6 +27,7 @@ describe('OCA.Files.FileActions tests', function() {
var $body = $('#testArea');
$body.append('<input type="hidden" id="dir" value="/subdir"></input>');
$body.append('<input type="hidden" id="permissions" value="31"></input>');
+ $body.append('<table id="filestable"><tbody id="fileList"></tbody></table>');
// dummy files table
fileActions = new OCA.Files.FileActions();
fileActions.registerAction({
@@ -152,9 +153,10 @@ describe('OCA.Files.FileActions tests', function() {
});
});
describe('action handler', function() {
- var actionStub, $tr;
+ var actionStub, $tr, clock;
beforeEach(function() {
+ clock = sinon.useFakeTimers();
var fileData = {
id: 18,
type: 'file',
@@ -175,6 +177,12 @@ describe('OCA.Files.FileActions tests', function() {
});
$tr = fileList.add(fileData);
});
+ afterEach(function() {
+ OC.hideMenus();
+ // jump past animations
+ clock.tick(1000);
+ clock.restore();
+ });
it('passes context to action handler', function() {
$tr.find('.action-test').click();
expect(actionStub.calledOnce).toEqual(true);
@@ -184,6 +192,7 @@ describe('OCA.Files.FileActions tests', function() {
expect(context.fileList).toBeDefined();
expect(context.fileActions).toBeDefined();
expect(context.dir).toEqual('/subdir');
+ expect(context.fileInfoModel.get('name')).toEqual('testName.txt');
// when data-path is defined
actionStub.reset();
@@ -192,6 +201,22 @@ describe('OCA.Files.FileActions tests', function() {
context = actionStub.getCall(0).args[1];
expect(context.dir).toEqual('/somepath');
});
+ it('also triggers action handler when calling triggerAction()', function() {
+ var model = new OCA.Files.FileInfoModel({
+ id: 1,
+ name: 'Test.txt',
+ path: '/subdir',
+ mime: 'text/plain',
+ permissions: 31
+ });
+ fileActions.triggerAction('Test', model, fileList);
+
+ expect(actionStub.calledOnce).toEqual(true);
+ expect(actionStub.getCall(0).args[0]).toEqual('Test.txt');
+ expect(actionStub.getCall(0).args[1].fileList).toEqual(fileList);
+ expect(actionStub.getCall(0).args[1].fileActions).toEqual(fileActions);
+ expect(actionStub.getCall(0).args[1].fileInfoModel).toEqual(model);
+ });
describe('actions menu', function() {
it('shows actions menu inside row when clicking the menu trigger', function() {
expect($tr.find('td.filename .fileActionsMenu').length).toEqual(0);
@@ -203,12 +228,13 @@ describe('OCA.Files.FileActions tests', function() {
expect($tr.hasClass('mouseOver')).toEqual(true);
});
it('cleans up after hiding', function() {
- var clock = sinon.useFakeTimers();
+ var slideUpStub = sinon.stub($.fn, 'slideUp');
$tr.find('.action-menu').click();
expect($tr.find('.fileActionsMenu').length).toEqual(1);
OC.hideMenus();
// sliding animation
- clock.tick(500);
+ expect(slideUpStub.calledOnce).toEqual(true);
+ slideUpStub.getCall(0).args[1]();
expect($tr.hasClass('mouseOver')).toEqual(false);
expect($tr.find('.fileActionsMenu').length).toEqual(0);
});
diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js
index 57e16626403..38073389382 100644
--- a/apps/files/tests/js/filelistSpec.js
+++ b/apps/files/tests/js/filelistSpec.js
@@ -1912,6 +1912,20 @@ describe('OCA.Files.FileList tests', function() {
expect($tr.hasClass('highlighted')).toEqual(false);
expect(fileList._detailsView.getFileInfo()).toEqual(null);
});
+ it('returns the currently selected model instance when calling getModelForFile', function() {
+ var $tr = fileList.findFileEl('One.txt');
+ $tr.find('td.filename>a.name').click();
+
+ var model1 = fileList.getModelForFile('One.txt');
+ var model2 = fileList.getModelForFile('One.txt');
+ model1.set('test', true);
+
+ // it's the same model
+ expect(model2).toEqual(model1);
+
+ var model3 = fileList.getModelForFile($tr);
+ expect(model3).toEqual(model1);
+ });
});
describe('File actions', function() {
it('Clicking on a file name will trigger default action', function() {
diff --git a/apps/files/tests/js/mainfileinfodetailviewSpec.js b/apps/files/tests/js/mainfileinfodetailviewSpec.js
index 10ad38097c6..ca7384f6207 100644
--- a/apps/files/tests/js/mainfileinfodetailviewSpec.js
+++ b/apps/files/tests/js/mainfileinfodetailviewSpec.js
@@ -20,32 +20,37 @@
*/
describe('OCA.Files.MainFileInfoDetailView tests', function() {
- var view, tooltipStub, previewStub, fncLazyLoadPreview, fileListMock;
+ var view, tooltipStub, fileListMock, fileActions, fileList, testFileInfo;
beforeEach(function() {
tooltipStub = sinon.stub($.fn, 'tooltip');
fileListMock = sinon.mock(OCA.Files.FileList.prototype);
- view = new OCA.Files.MainFileInfoDetailView();
+ fileActions = new OCA.Files.FileActions();
+ fileList = new OCA.Files.FileList($('<table></table>'), {
+ fileActions: fileActions
+ });
+ view = new OCA.Files.MainFileInfoDetailView({
+ fileList: fileList,
+ fileActions: fileActions
+ });
+ testFileInfo = new OCA.Files.FileInfoModel({
+ id: 5,
+ name: 'One.txt',
+ mimetype: 'text/plain',
+ permissions: 31,
+ path: '/subdir',
+ size: 123456789,
+ mtime: Date.UTC(2015, 6, 17, 1, 2, 0, 0)
+ });
});
afterEach(function() {
- view.destroy();
+ view.remove();
view = undefined;
tooltipStub.restore();
fileListMock.restore();
});
describe('rendering', function() {
- var testFileInfo;
- beforeEach(function() {
- view = new OCA.Files.MainFileInfoDetailView();
- testFileInfo = {
- id: 5,
- name: 'One.txt',
- path: '/subdir',
- size: 123456789,
- mtime: Date.UTC(2015, 6, 17, 1, 2, 0, 0)
- };
- });
it('displays basic info', function() {
var clock = sinon.useFakeTimers(Date.UTC(2015, 6, 17, 1, 2, 0, 3));
var dateExpected = OC.Util.formatDate(Date(Date.UTC(2015, 6, 17, 1, 2, 0, 0)));
@@ -59,39 +64,34 @@ describe('OCA.Files.MainFileInfoDetailView tests', function() {
clock.restore();
});
it('displays favorite icon', function() {
- view.setFileInfo(_.extend(testFileInfo, {
- tags: [OC.TAG_FAVORITE]
- }));
+ testFileInfo.set('tags', [OC.TAG_FAVORITE]);
+ view.setFileInfo(testFileInfo);
expect(view.$el.find('.favorite img').attr('src'))
.toEqual(OC.imagePath('core', 'actions/starred'));
- view.setFileInfo(_.extend(testFileInfo, {
- tags: []
- }));
+ testFileInfo.set('tags', []);
+ view.setFileInfo(testFileInfo);
expect(view.$el.find('.favorite img').attr('src'))
.toEqual(OC.imagePath('core', 'actions/star'));
});
it('displays mime icon', function() {
// File
- view.setFileInfo(_.extend(testFileInfo, {
- mimetype: 'text/calendar'
- }));
+ testFileInfo.set('mimetype', 'text/calendar');
+ view.setFileInfo(testFileInfo);
expect(view.$el.find('.thumbnail').css('background-image'))
.toContain('filetypes/text-calendar.svg');
// Folder
- view.setFileInfo(_.extend(testFileInfo, {
- mimetype: 'httpd/unix-directory'
- }));
+ testFileInfo.set('mimetype', 'httpd/unix-directory');
+ view.setFileInfo(testFileInfo);
expect(view.$el.find('.thumbnail').css('background-image'))
.toContain('filetypes/folder.svg');
});
it('displays thumbnail', function() {
- view.setFileInfo(_.extend(testFileInfo, {
- mimetype: 'text/plain'
- }));
+ testFileInfo.set('mimetype', 'test/plain');
+ view.setFileInfo(testFileInfo);
var expectation = fileListMock.expects('lazyLoadPreview');
expectation.once();
@@ -100,5 +100,76 @@ describe('OCA.Files.MainFileInfoDetailView tests', function() {
fileListMock.verify();
});
+ it('rerenders when changes are made on the model', function() {
+ view.setFileInfo(testFileInfo);
+
+ testFileInfo.set('tags', [OC.TAG_FAVORITE]);
+
+ expect(view.$el.find('.favorite img').attr('src'))
+ .toEqual(OC.imagePath('core', 'actions/starred'));
+
+ testFileInfo.set('tags', []);
+
+ expect(view.$el.find('.favorite img').attr('src'))
+ .toEqual(OC.imagePath('core', 'actions/star'));
+ });
+ it('unbinds change listener from model', function() {
+ view.setFileInfo(testFileInfo);
+ view.setFileInfo(new OCA.Files.FileInfoModel({
+ id: 999,
+ name: 'test.txt',
+ path: '/'
+ }));
+
+ // set value on old model
+ testFileInfo.set('tags', [OC.TAG_FAVORITE]);
+
+ // no change
+ expect(view.$el.find('.favorite img').attr('src'))
+ .toEqual(OC.imagePath('core', 'actions/star'));
+ });
+ });
+ describe('events', function() {
+ it('triggers default action when clicking on the thumbnail', function() {
+ var actionHandler = sinon.stub();
+
+ fileActions.registerAction({
+ name: 'Something',
+ mime: 'all',
+ permissions: OC.PERMISSION_READ,
+ actionHandler: actionHandler
+ });
+ fileActions.setDefault('text/plain', 'Something');
+
+ view.setFileInfo(testFileInfo);
+
+ view.$el.find('.thumbnail').click();
+
+ expect(actionHandler.calledOnce).toEqual(true);
+ expect(actionHandler.getCall(0).args[0]).toEqual('One.txt');
+ expect(actionHandler.getCall(0).args[1].fileList).toEqual(fileList);
+ expect(actionHandler.getCall(0).args[1].fileActions).toEqual(fileActions);
+ expect(actionHandler.getCall(0).args[1].fileInfoModel).toEqual(testFileInfo);
+ });
+ it('triggers "Favorite" action when clicking on the star', function() {
+ var actionHandler = sinon.stub();
+
+ fileActions.registerAction({
+ name: 'Favorite',
+ mime: 'all',
+ permissions: OC.PERMISSION_READ,
+ actionHandler: actionHandler
+ });
+
+ view.setFileInfo(testFileInfo);
+
+ view.$el.find('.action-favorite').click();
+
+ expect(actionHandler.calledOnce).toEqual(true);
+ expect(actionHandler.getCall(0).args[0]).toEqual('One.txt');
+ expect(actionHandler.getCall(0).args[1].fileList).toEqual(fileList);
+ expect(actionHandler.getCall(0).args[1].fileActions).toEqual(fileActions);
+ expect(actionHandler.getCall(0).args[1].fileInfoModel).toEqual(testFileInfo);
+ });
});
});