123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- describe('OCA.Files_External.Settings tests', function() {
- var clock;
- var select2Stub;
- var select2ApplicableUsers;
- beforeEach(function() {
- clock = sinon.useFakeTimers();
- select2ApplicableUsers = [];
- select2Stub = sinon.stub($.fn, 'select2').callsFake(function(args) {
- if (args === 'val') {
- return select2ApplicableUsers;
- }
- return {
- on: function() { return this; }
- };
- });
-
- $('#testArea').append(
- '<table id="externalStorage" data-admin="true">' +
- '<thead></thead>' +
- '<tbody>' +
- '<tr id="addMountPoint" data-id="">' +
- '<td class="status"></td>' +
- '<td class="mountPoint"><input type="text" name="mountPoint"/></td>' +
- '<td class="backend">' +
- '<select class="selectBackend">' +
- '<option disable selected>Add storage</option>' +
- '<option value="\\OC\\TestBackend">Test Backend</option>' +
- '<option value="\\OC\\AnotherTestBackend">Another Test Backend</option>' +
- '<option value="\\OC\\InputsTestBackend">Inputs test backend</option>' +
- '</select>' +
- '</td>' +
- '<td class="authentication"></td>' +
- '<td class="configuration"></td>' +
- '<td class="applicable">' +
- '<input type="checkbox" class="applicableToAllUsers">' +
- '<input type="hidden" class="applicableUsers">' +
- '</td>' +
- '<td class="mountOptionsToggle">'+
- '<div class="icon-more" title="Advanced settings" deluminate_imagetype="unknown"></div>'+
- '<input type="hidden" class="mountOptions"/>'+
- '</td>'+
- '<td class="save">'+
- '<div class="icon-checkmark" title="Save" deluminate_imagetype="unknown"></div>'+
- '</td>'+
- '</tr>' +
- '</tbody>' +
- '</table>'
- );
-
-
- $('#externalStorage .selectBackend:first').data('configurations', {
- '\\OC\\TestBackend': {
- 'identifier': '\\OC\\TestBackend',
- 'name': 'Test Backend',
- 'configuration': {
- 'field1': {
- 'value': 'Display Name 1'
- },
- 'field2': {
- 'value': 'Display Name 2',
- 'flags': 1
- }
- },
- 'authSchemes': {
- 'builtin': true,
- },
- 'priority': 11
- },
- '\\OC\\AnotherTestBackend': {
- 'identifier': '\\OC\\AnotherTestBackend',
- 'name': 'Another Test Backend',
- 'configuration': {
- 'field1': {
- 'value': 'Display Name 1'
- },
- 'field2': {
- 'value': 'Display Name 2',
- 'flags': 1
- }
- },
- 'authSchemes': {
- 'builtin': true,
- },
- 'priority': 12
- },
- '\\OC\\InputsTestBackend': {
- 'identifier': '\\OC\\InputsTestBackend',
- 'name': 'Inputs test backend',
- 'configuration': {
- 'field_text': {
- 'value': 'Text field'
- },
- 'field_password': {
- 'value': ',Password field',
- 'type': 2
- },
- 'field_bool': {
- 'value': 'Boolean field',
- 'type': 1
- },
- 'field_hidden': {
- 'value': 'Hidden field',
- 'type': 3
- },
- 'field_text_optional': {
- 'value': 'Text field optional',
- 'flags': 1
- },
- 'field_password_optional': {
- 'value': 'Password field optional',
- 'flags': 1,
- 'type': 2
- }
- },
- 'authSchemes': {
- 'builtin': true,
- },
- 'priority': 13
- }
- }
- );
- $('#externalStorage #addMountPoint .authentication:first').data('mechanisms', {
- 'mechanism1': {
- 'identifier': 'mechanism1',
- 'name': 'Mechanism 1',
- 'configuration': {
- },
- 'scheme': 'builtin',
- 'visibility': 3
- },
- });
- });
- afterEach(function() {
- select2Stub.restore();
- clock.restore();
- });
- describe('storage configuration', function() {
- var view;
- function selectBackend(backendName) {
- view.$el.find('.selectBackend:first').val(backendName).trigger('change');
- view.$el.find('.applicableToAllUsers').prop('checked', true).trigger('change');
- }
- beforeEach(function() {
- var $el = $('#externalStorage');
- view = new OCA.Files_External.Settings.MountConfigListView($el, {encryptionEnabled: false});
- });
- afterEach(function() {
- view = null;
- });
- describe('selecting backend', function() {
- it('populates the row and creates a new empty one', function() {
- selectBackend('\\OC\\TestBackend');
- var $firstRow = view.$el.find('tr:first');
- expect($firstRow.find('.backend').text()).toEqual('Test Backend');
- expect($firstRow.find('.selectBackend').length).toEqual(0);
-
-
- expect($firstRow.find('[name=mountPoint]').val()).toEqual('TestBackend');
-
-
- var $emptyRow = $firstRow.next('tr');
- expect($emptyRow.length).toEqual(1);
- expect($emptyRow.find('.selectBackend').length).toEqual(1);
- expect($emptyRow.find('.applicable select').length).toEqual(0);
-
- });
- it('shows row even if selection row is hidden', function() {
- selectBackend('\\OC\\TestBackend');
- view.$el.find('tr#addMountPoint').hide();
- expect(view.$el.find('tr:first').is(':visible')).toBe(true);
- expect(view.$el.find('tr#addMountPoint').is(':visible')).toBe(false);
- });
-
-
- });
- describe('saving storages', function() {
- var $tr;
- beforeEach(function() {
- selectBackend('\\OC\\TestBackend');
- $tr = view.$el.find('tr:first');
- });
- it('saves storage after clicking the save button', function() {
- var $field1 = $tr.find('input[data-parameter=field1]');
- expect($field1.length).toEqual(1);
- $field1.val('test');
- $field1.trigger(new $.Event('keyup', {keyCode: 97}));
- var $mountOptionsField = $tr.find('input.mountOptions');
- expect($mountOptionsField.length).toEqual(1);
- $mountOptionsField.val(JSON.stringify({previews:true}));
- var $saveButton = $tr.find('td.save .icon-checkmark');
- $saveButton.click();
- expect(fakeServer.requests.length).toEqual(1);
- var request = fakeServer.requests[0];
- expect(request.url).toEqual(OC.getRootPath() + '/index.php/apps/files_external/globalstorages');
- expect(JSON.parse(request.requestBody)).toEqual({
- backend: '\\OC\\TestBackend',
- authMechanism: 'mechanism1',
- backendOptions: {
- 'field1': 'test',
- 'field2': ''
- },
- mountPoint: 'TestBackend',
- priority: 11,
- applicableUsers: [],
- applicableGroups: [],
- mountOptions: {
- 'previews': true
- },
- testOnly: true
- });
-
- });
- it('saves storage with applicable users', function() {
- var $field1 = $tr.find('input[data-parameter=field1]');
- expect($field1.length).toEqual(1);
- $field1.val('test');
- $field1.trigger(new $.Event('keyup', {keyCode: 97}));
- $tr.find('.applicableToAllUsers').prop('checked', false).trigger('change');
- select2ApplicableUsers = ['user1', 'user2', 'group1(group)', 'group2(group)'];
- var $saveButton = $tr.find('td.save .icon-checkmark');
- $saveButton.click();
- expect(fakeServer.requests.length).toEqual(1);
- var request = fakeServer.requests[0];
- expect(request.url).toEqual(OC.getRootPath() + '/index.php/apps/files_external/globalstorages');
- expect(JSON.parse(request.requestBody)).toEqual({
- backend: '\\OC\\TestBackend',
- authMechanism: 'mechanism1',
- backendOptions: {
- 'field1': 'test',
- 'field2': ''
- },
- mountPoint: 'TestBackend',
- priority: 11,
- applicableUsers: ['user1', 'user2'],
- applicableGroups: ['group1', 'group2'],
- mountOptions: {
- encrypt: true,
- previews: true,
- enable_sharing: false,
- filesystem_check_changes: 1,
- encoding_compatibility: false,
- readonly: false,
- },
- testOnly: true
- });
-
- });
- it('does not saves storage without applicable users and unchecked all users checkbox', function() {
- var $field1 = $tr.find('input[data-parameter=field1]');
- expect($field1.length).toEqual(1);
- $field1.val('test');
- $field1.trigger(new $.Event('keyup', {keyCode: 97}));
- $tr.find('.applicableToAllUsers').prop('checked', false).trigger('change');
- var $saveButton = $tr.find('td.save .icon-checkmark');
- $saveButton.click();
- expect(fakeServer.requests.length).toEqual(0);
- });
- it('saves storage after closing mount options popovermenu', function() {
- $tr.find('.mountOptionsToggle .icon-more').click();
- $tr.find('[name=previews]').trigger(new $.Event('keyup', {keyCode: 97}));
- $tr.find('input[data-parameter=field1]').val('test');
-
- expect(fakeServer.requests.length).toEqual(0);
- $('body').mouseup();
-
- expect(fakeServer.requests.length).toEqual(1);
- });
-
- });
- describe('validate storage configuration', function() {
- var $tr;
- beforeEach(function() {
- selectBackend('\\OC\\InputsTestBackend');
- $tr = view.$el.find('tr:first');
- });
- it('lists missing fields in storage errors', function() {
- $tr.find('.applicableToAllUsers').prop('checked', false).trigger('change');
- var storage = view.getStorageConfig($tr);
- expect(storage.errors).toEqual({
- backendOptions: ['field_text', 'field_password'],
- requiredApplicable: true,
- });
- });
- it('does not list applicable when all users checkbox is ticked', function() {
- var storage = view.getStorageConfig($tr);
- expect(storage.errors).toEqual({
- backendOptions: ['field_text', 'field_password']
- });
- });
- it('highlights missing non-optional fields', function() {
- _.each([
- 'field_text',
- 'field_password'
- ], function(param) {
- expect($tr.find('input[data-parameter='+param+']').hasClass('warning-input')).toBe(true);
- });
- _.each([
- 'field_bool',
- 'field_hidden',
- 'field_text_optional',
- 'field_password_optional'
- ], function(param) {
- expect($tr.find('input[data-parameter='+param+']').hasClass('warning-input')).toBe(false);
- });
- });
- it('validates correct storage', function() {
- $tr.find('[name=mountPoint]').val('mountpoint');
- $tr.find('input[data-parameter=field_text]').val('foo');
- $tr.find('input[data-parameter=field_password]').val('bar');
- $tr.find('input[data-parameter=field_text_optional]').val('foobar');
-
- $tr.find('input[data-parameter=field_hidden]').val('baz');
- var storage = view.getStorageConfig($tr);
- expect(storage.validate()).toBe(true);
- });
- it('checks missing mount point', function() {
- $tr.find('[name=mountPoint]').val('');
- $tr.find('input[data-parameter=field_text]').val('foo');
- $tr.find('input[data-parameter=field_password]').val('bar');
- var storage = view.getStorageConfig($tr);
- expect(storage.validate()).toBe(false);
- });
- });
- describe('update storage', function() {
-
- });
- describe('delete storage', function() {
-
- });
- describe('recheck storages', function() {
-
- });
- describe('mount options popovermenu', function() {
- var $tr;
- var $td;
- beforeEach(function() {
- selectBackend('\\OC\\TestBackend');
- $tr = view.$el.find('tr:first');
- $td = $tr.find('.mountOptionsToggle');
- });
- it('shows popovermenu when clicking on toggle button, hides when clicking outside', function() {
- $td.find('.icon-more').click();
- expect($td.find('.popovermenu.open').length).toEqual(1);
- $('body').mouseup();
- expect($td.find('.popovermenu.open').length).toEqual(0);
- });
- it('doesnt show the encryption option when encryption is disabled', function () {
- view._encryptionEnabled = false;
- $td.find('.icon-more').click();
- expect($td.find('.popovermenu [name=encrypt]:visible').length).toEqual(0);
- $('body').mouseup();
- expect($td.find('.popovermenu.open').length).toEqual(0);
- });
- it('reads config from mountOptions field', function() {
- $tr.find('input.mountOptions').val(JSON.stringify({previews:false}));
- $td.find('.icon-more').click();
- expect($td.find('.popovermenu [name=previews]').prop('checked')).toEqual(false);
- $('body').mouseup();
- $tr.find('input.mountOptions').val(JSON.stringify({previews:true}));
- $td.find('.icon-more').click();
- expect($td.find('.popovermenu [name=previews]').prop('checked')).toEqual(true);
- });
- it('writes config into mountOptions field', function() {
- $td.find('.icon-more').click();
-
- var $field = $td.find('.popovermenu [name=previews]');
- expect($field.prop('checked')).toEqual(true);
- $td.find('.popovermenu [name=filesystem_check_changes]').val(0);
- $('body').mouseup();
- expect(JSON.parse($tr.find('input.mountOptions').val())).toEqual({
- encrypt: true,
- previews: true,
- enable_sharing: false,
- filesystem_check_changes: 0,
- encoding_compatibility: false,
- readonly: false
- });
- });
- });
- });
- describe('allow user mounts section', function() {
-
- });
- });
|