summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJesús Macias <jmacias@solidgear.es>2015-11-24 08:16:49 +0100
committerJesús Macias <jmacias@solidgear.es>2015-11-24 08:16:49 +0100
commite4a2da6c3dbe5ac0f36c128b33632097a86a023c (patch)
tree1ce65d65a2f0791b865d673f02e9b8f9c0fdabe7 /apps
parent5580b562a36c682c4baea89c7026af5596f714bc (diff)
parent5b9a693fbc73b5bed59197af0f9961605cea11ec (diff)
downloadnextcloud-server-e4a2da6c3dbe5ac0f36c128b33632097a86a023c.tar.gz
nextcloud-server-e4a2da6c3dbe5ac0f36c128b33632097a86a023c.zip
Merge branch 'issue_20427' of github.com:owncloud/core into issue_20427
Diffstat (limited to 'apps')
-rw-r--r--apps/files_external/tests/js/statusmanagerSpec.js205
1 files changed, 205 insertions, 0 deletions
diff --git a/apps/files_external/tests/js/statusmanagerSpec.js b/apps/files_external/tests/js/statusmanagerSpec.js
new file mode 100644
index 00000000000..975d71627bf
--- /dev/null
+++ b/apps/files_external/tests/js/statusmanagerSpec.js
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+describe('OCA.External.StatusManager tests', function() {
+ var notificationStub;
+ var fileList;
+ var statusManager;
+ var oldAppWebRoots;
+
+ beforeEach(function() {
+ notificationStub = sinon.stub(OC.Notification, 'showTemporary');
+ var $content = $('<div id="content"></div>');
+ $('#testArea').append($content);
+ // dummy file list
+ var $div = $(
+ '<div id="listContainer">' +
+ '<input id="dir" type="hidden" name="dir" value="/">' +
+ '<table id="filestable">' +
+ '<thead></thead>' +
+ '<tbody id="fileList"></tbody>' +
+ '</table>' +
+ '</div>');
+ $('#content').append($div);
+
+ var fileActions = new OCA.Files.FileActions();
+ fileList = new OCA.Files.FileList(
+ $div, {
+ fileActions : fileActions
+ }
+ );
+
+ fileList.add({
+ id: 1,
+ type: 'folder',
+ name: 'testmount',
+ mountType: 'external-root',
+ path: '/',
+ mimetype: 'httpd/unix-directory',
+ size: 12,
+ permissions: OC.PERMISSION_ALL,
+ etag: 'abc'
+ });
+
+ statusManager = OCA.External.StatusManager;
+
+ oldAppWebRoots = _.extend({}, OC.appswebroots);
+ OC.appswebroots['files_external'] = OC.webroot + '/apps/files_external';
+ });
+ afterEach(function() {
+ statusManager.mountStatus = null;
+ statusManager.mountPointList = null;
+
+ notificationStub.restore();
+ OC.appswebroots = oldAppWebRoots;
+ });
+
+ describe('getMountStatusForMount', function() {
+ beforeEach(function() {
+ statusManager.mountStatus = [];
+ });
+
+ it('retrieves mount status and passes it to callback', function() {
+ var mountData = {
+ id: 123,
+ type: 'smb',
+ mount_point: 'testmount',
+ location: 3
+ };
+
+ var callbackStub = sinon.stub();
+ statusManager.getMountStatusForMount(mountData, callbackStub);
+
+ expect(fakeServer.requests.length).toEqual(1);
+
+ var mountStatus = {
+ type: 'smb',
+ status: 0
+ };
+
+ var jsonData = JSON.stringify(mountStatus);
+ var request = fakeServer.requests[0];
+
+ expect(request.url).toEqual(OC.webroot + '/index.php/apps/files_external/globalstorages/123');
+
+ fakeServer.requests[0].respond(
+ 200,
+ {'Content-Type': 'application/json'},
+ jsonData
+ );
+
+
+ expect(callbackStub.calledOnce).toEqual(true);
+ expect(callbackStub.getCall(0).args[0]).toEqual(mountData);
+ expect(callbackStub.getCall(0).args[1]).toEqual(mountStatus);
+
+ // second call does not send request but returns known data
+ statusManager.getMountStatusForMount(mountData, callbackStub);
+
+ expect(fakeServer.requests.length).toEqual(1);
+
+ expect(callbackStub.calledTwice).toEqual(true);
+ expect(callbackStub.getCall(1).args[0]).toEqual(mountData);
+ expect(callbackStub.getCall(1).args[1]).toEqual(mountStatus);
+ });
+ // TODO: case where status is not 0
+ // TODO: error case
+ });
+ describe('getMountPointList', function() {
+ // TODO
+ });
+ describe('processMountList', function() {
+ var getActiveViewStub;
+ var getCurrentAppContainerStub;
+
+ beforeEach(function() {
+ getActiveViewStub = sinon.stub(OCA.Files.App, 'getActiveView');
+ getActiveViewStub.returns('files');
+ getCurrentAppContainerStub = sinon.stub(OCA.Files.App, 'getCurrentAppContainer');
+ getCurrentAppContainerStub.returns($('#testArea'));
+ });
+ afterEach(function() {
+ getActiveViewStub.restore();
+ getCurrentAppContainerStub.restore();
+ });
+
+ it('updates file list element with status', function() {
+ var mountList = [{
+ id: 123,
+ mount_point: 'testmount',
+ backend: 'smb',
+ backendText: 'SMB',
+ type: 'system',
+ status: 0,
+ location: ''
+ }];
+ statusManager.processMountList(mountList);
+
+ var $tr = fileList.findFileEl('testmount');
+ expect($tr.attr('data-external-backend')).toEqual('smb');
+ expect($tr.attr('data-icon')).toEqual(
+ OC.imagePath('windows_network_drive', 'folder-windows')
+ );
+ // TODO: thumbnail URL
+ /*
+ expect(OC.TestUtil.getImageUrl($tr.find('.thumbnail'))).toEqual(
+ OC.imagePath('windows_network_drive', 'folder-windows')
+ );
+ */
+ // TODO: check CSS class
+
+ });
+ });
+ describe('processMountStatus', function() {
+ // TODO
+ });
+ describe('launchFullConnectivityCheckOneByOne', function() {
+ var getMountPointListStub;
+ var getMountStatusStub;
+ var processMountStatusStub;
+ var processMountListStub;
+
+ beforeEach(function() {
+ getMountPointListStub = sinon.stub(statusManager, 'getMountPointList');
+ getMountStatusStub = sinon.stub(statusManager, 'getMountStatus');
+ processMountStatusStub = sinon.stub(statusManager, 'processMountStatus');
+ processMountListStub = sinon.stub(statusManager, 'processMountList');
+ });
+ afterEach(function() {
+ getMountPointListStub.restore();
+ getMountStatusStub.restore();
+ processMountStatusStub.restore();
+ processMountListStub.restore();
+ });
+ it('retrieves mount points then processes them', function() {
+ statusManager.launchFullConnectivityCheck();
+
+ expect(getMountPointListStub.calledOnce).toEqual(true);
+ var mountList = [{
+ id: 123,
+ mount_point: 'testmount',
+ backend: 'smb',
+ backendText: 'SMB',
+ type: 'system',
+ status: 0,
+ location: ''
+ }];
+ getMountPointListStub.yield(mountList);
+
+ expect(processMountListStub.calledOnce).toEqual(true);
+ expect(processMountListStub.calledWith(mountList)).toEqual(true);
+
+ // TODO: continue checking getMountStatus, etc
+ });
+ });
+ describe('recheckConnectivityForOne', function() {
+ // TODO
+ });
+});