aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-07-04 12:53:03 +0200
committerVincent Petry <pvince81@owncloud.com>2014-07-04 12:56:04 +0200
commit07118f599e575c03d3025888963f5edb39769fb3 (patch)
treec6ce8388e58e166c71a1ea6e02ac2f95bd3d140e /apps/files/tests
parente4a3f8d3c44f3238071d03f793cd2c5395062b5e (diff)
downloadnextcloud-server-07118f599e575c03d3025888963f5edb39769fb3.tar.gz
nextcloud-server-07118f599e575c03d3025888963f5edb39769fb3.zip
Fix FileActions merging override
When merging FileActions, the register() functio needs to correctly override the previously merged action handler without affecting the original one.
Diffstat (limited to 'apps/files/tests')
-rw-r--r--apps/files/tests/js/fileactionsSpec.js150
1 files changed, 150 insertions, 0 deletions
diff --git a/apps/files/tests/js/fileactionsSpec.js b/apps/files/tests/js/fileactionsSpec.js
index f464800730a..f087239de9d 100644
--- a/apps/files/tests/js/fileactionsSpec.js
+++ b/apps/files/tests/js/fileactionsSpec.js
@@ -193,6 +193,156 @@ describe('OCA.Files.FileActions tests', function() {
context = actionStub.getCall(0).args[1];
expect(context.dir).toEqual('/somepath');
});
+ describe('merging', function() {
+ var $tr;
+ beforeEach(function() {
+ var fileData = {
+ id: 18,
+ type: 'file',
+ name: 'testName.txt',
+ path: '/anotherpath/there',
+ mimetype: 'text/plain',
+ size: '1234',
+ etag: 'a01234c',
+ mtime: '123456'
+ };
+ $tr = fileList.add(fileData);
+ });
+ afterEach(function() {
+ $tr = null;
+ });
+ it('copies all actions to target file actions', function() {
+ var actions1 = new OCA.Files.FileActions();
+ var actions2 = new OCA.Files.FileActions();
+ var actionStub1 = sinon.stub();
+ var actionStub2 = sinon.stub();
+ actions1.register(
+ 'all',
+ 'Test',
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ actionStub1
+ );
+ actions2.register(
+ 'all',
+ 'Test2',
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ actionStub2
+ );
+ actions2.merge(actions1);
+
+ actions2.display($tr.find('td.filename'), true, fileList);
+
+ expect($tr.find('.action-test').length).toEqual(1);
+ expect($tr.find('.action-test2').length).toEqual(1);
+
+ $tr.find('.action-test').click();
+ expect(actionStub1.calledOnce).toEqual(true);
+ expect(actionStub2.notCalled).toEqual(true);
+
+ actionStub1.reset();
+
+ $tr.find('.action-test2').click();
+ expect(actionStub1.notCalled).toEqual(true);
+ expect(actionStub2.calledOnce).toEqual(true);
+ });
+ it('overrides existing actions on merge', function() {
+ var actions1 = new OCA.Files.FileActions();
+ var actions2 = new OCA.Files.FileActions();
+ var actionStub1 = sinon.stub();
+ var actionStub2 = sinon.stub();
+ actions1.register(
+ 'all',
+ 'Test',
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ actionStub1
+ );
+ actions2.register(
+ 'all',
+ 'Test', // override
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ actionStub2
+ );
+ actions1.merge(actions2);
+
+ actions1.display($tr.find('td.filename'), true, fileList);
+
+ expect($tr.find('.action-test').length).toEqual(1);
+
+ $tr.find('.action-test').click();
+ expect(actionStub1.notCalled).toEqual(true);
+ expect(actionStub2.calledOnce).toEqual(true);
+ });
+ it('overrides existing action when calling register after merge', function() {
+ var actions1 = new OCA.Files.FileActions();
+ var actions2 = new OCA.Files.FileActions();
+ var actionStub1 = sinon.stub();
+ var actionStub2 = sinon.stub();
+ actions1.register(
+ 'all',
+ 'Test',
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ actionStub1
+ );
+
+ actions1.merge(actions2);
+
+ // late override
+ actions1.register(
+ 'all',
+ 'Test', // override
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ actionStub2
+ );
+
+ actions1.display($tr.find('td.filename'), true, fileList);
+
+ expect($tr.find('.action-test').length).toEqual(1);
+
+ $tr.find('.action-test').click();
+ expect(actionStub1.notCalled).toEqual(true);
+ expect(actionStub2.calledOnce).toEqual(true);
+ });
+ it('leaves original file actions untouched (clean copy)', function() {
+ var actions1 = new OCA.Files.FileActions();
+ var actions2 = new OCA.Files.FileActions();
+ var actionStub1 = sinon.stub();
+ var actionStub2 = sinon.stub();
+ actions1.register(
+ 'all',
+ 'Test',
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ actionStub1
+ );
+
+ // copy the Test action to actions2
+ actions2.merge(actions1);
+
+ // late override
+ actions2.register(
+ 'all',
+ 'Test', // override
+ OC.PERMISSION_READ,
+ OC.imagePath('core', 'actions/test'),
+ actionStub2
+ );
+
+ // check if original actions still call the correct handler
+ actions1.display($tr.find('td.filename'), true, fileList);
+
+ expect($tr.find('.action-test').length).toEqual(1);
+
+ $tr.find('.action-test').click();
+ expect(actionStub1.calledOnce).toEqual(true);
+ expect(actionStub2.notCalled).toEqual(true);
+ });
+ });
describe('events', function() {
var clock;
beforeEach(function() {