fileDropSpec.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/webdav/" + encodeURI(testFile.name));
  87. expect(data.headers['Authorization']).toEqual('Basic ' + btoa(sharingToken+":"));
  88. });
  89. }
  90. });
  91. });