You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fileDropSpec.js 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * @copyright Copyright (c) 2017, Artur Neumann (info@individual-it.net)
  3. *
  4. * @author Artur Neumann <info@individual-it.net>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. describe("files Drop tests", function() {
  23. //some testing data
  24. var sharingToken = "fVCiSMhScgWfiuv";
  25. var testFiles = [
  26. { name: 'test.txt', expectedValidationResult: true },
  27. { name: 'testनेपाल.txt', expectedValidationResult: true },
  28. { name: 'test.part', expectedValidationResult: false },
  29. { name: 'test.filepart', expectedValidationResult: false },
  30. { name: '.', expectedValidationResult: false },
  31. { name: '..', expectedValidationResult: false },
  32. ];
  33. //this pre/post positions should not change the result of the file name validation
  34. var prePostPositions = [""," "," "," "];
  35. //use the testFiles and the pre/post positions to generate more testing data
  36. var replicatedTestFiles = [];
  37. prePostPositions.map(function (prePostPosition) {
  38. testFiles.map(function (testFile) {
  39. replicatedTestFiles.push(
  40. {
  41. name: testFile.name + prePostPosition,
  42. expectedValidationResult: testFile.expectedValidationResult
  43. }
  44. );
  45. replicatedTestFiles.push(
  46. {
  47. name: prePostPosition + testFile.name,
  48. expectedValidationResult: testFile.expectedValidationResult
  49. }
  50. );
  51. replicatedTestFiles.push(
  52. {
  53. name: prePostPosition + testFile.name + prePostPosition,
  54. expectedValidationResult: testFile.expectedValidationResult
  55. }
  56. );
  57. });
  58. });
  59. beforeEach (function () {
  60. //fake input for the sharing token
  61. $('#testArea').append(
  62. '<input name="sharingToken" value="" id="sharingToken" type="hidden">'
  63. );
  64. });
  65. replicatedTestFiles.map(function (testFile) {
  66. it("validates the filenames correctly", function() {
  67. data = {
  68. 'submit': function() {},
  69. 'files': [testFile]
  70. }
  71. expect(OCA.FilesSharingDrop.addFileToUpload('',data)).
  72. toBe(
  73. testFile.expectedValidationResult,
  74. 'wrongly validated file named "'+testFile.name+'"'
  75. );
  76. });
  77. if (testFile.expectedValidationResult === true) {
  78. it("should set correct PUT URL, Auth header and submit", function () {
  79. data = {
  80. 'submit': sinon.stub(),
  81. 'files': [testFile]
  82. }
  83. $('#sharingToken').val(sharingToken);
  84. OCA.FilesSharingDrop.addFileToUpload('',data);
  85. expect(data.submit.calledOnce).toEqual(true);
  86. expect(data.url).toContain("/public.php/dav/files/" + sharingToken + '/' + encodeURI(testFile.name));
  87. });
  88. }
  89. });
  90. });