fileDropSpec.js 3.1 KB

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