aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests
diff options
context:
space:
mode:
authorVincent Petry <vincent@nextcloud.com>2023-01-16 15:08:19 +0100
committerGitHub <noreply@github.com>2023-01-16 15:08:19 +0100
commitbfcb2690a4cb43bb75a53dacfa95626694640aaf (patch)
tree7d547a9580c71949520ece51f22915d54da01d9d /apps/files_external/tests
parentf0b9b6ebaa315972ce7cbeb5a18919dc1ca9c97e (diff)
parent4f35cd5ebf0856811c7a85d1109a49bc0cf4993a (diff)
downloadnextcloud-server-bfcb2690a4cb43bb75a53dacfa95626694640aaf.tar.gz
nextcloud-server-bfcb2690a4cb43bb75a53dacfa95626694640aaf.zip
Merge pull request #36087 from nextcloud/enh/noid/improve-applicable-ext-storage
Improve saving applicable users in ext storage
Diffstat (limited to 'apps/files_external/tests')
-rw-r--r--apps/files_external/tests/js/settingsSpec.js71
1 files changed, 67 insertions, 4 deletions
diff --git a/apps/files_external/tests/js/settingsSpec.js b/apps/files_external/tests/js/settingsSpec.js
index 18997941111..4032f6f6a37 100644
--- a/apps/files_external/tests/js/settingsSpec.js
+++ b/apps/files_external/tests/js/settingsSpec.js
@@ -35,12 +35,13 @@ describe('OCA.Files_External.Settings tests', function() {
beforeEach(function() {
clock = sinon.useFakeTimers();
+ select2ApplicableUsers = [];
select2Stub = sinon.stub($.fn, 'select2').callsFake(function(args) {
if (args === 'val') {
return select2ApplicableUsers;
}
return {
- on: function() {}
+ on: function() { return this; }
};
});
@@ -63,6 +64,7 @@ describe('OCA.Files_External.Settings tests', function() {
'<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">'+
@@ -172,6 +174,7 @@ describe('OCA.Files_External.Settings tests', function() {
function selectBackend(backendName) {
view.$el.find('.selectBackend:first').val(backendName).trigger('change');
+ view.$el.find('.applicableToAllUsers').prop('checked', true).trigger('change');
}
beforeEach(function() {
@@ -255,6 +258,59 @@ describe('OCA.Files_External.Settings tests', function() {
// TODO: respond and check data-id
});
+ 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
+ });
+
+ // TODO: respond and check data-id
+ });
+ 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}));
@@ -279,6 +335,16 @@ describe('OCA.Files_External.Settings tests', function() {
});
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({
@@ -399,9 +465,6 @@ describe('OCA.Files_External.Settings tests', function() {
});
});
});
- describe('applicable user list', function() {
- // TODO: test select2 retrieval logic
- });
describe('allow user mounts section', function() {
// TODO: test allowUserMounting section
});