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 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. describe("files Drop tests", function() {
  6. //some testing data
  7. var sharingToken = "fVCiSMhScgWfiuv";
  8. var testFiles = [
  9. { name: 'test.txt', expectedValidationResult: true },
  10. { name: 'testनेपाल.txt', expectedValidationResult: true },
  11. { name: 'test.part', expectedValidationResult: false },
  12. { name: 'test.filepart', expectedValidationResult: false },
  13. { name: '.', expectedValidationResult: false },
  14. { name: '..', expectedValidationResult: false },
  15. ];
  16. //this pre/post positions should not change the result of the file name validation
  17. var prePostPositions = [""," "," "," "];
  18. //use the testFiles and the pre/post positions to generate more testing data
  19. var replicatedTestFiles = [];
  20. prePostPositions.map(function (prePostPosition) {
  21. testFiles.map(function (testFile) {
  22. replicatedTestFiles.push(
  23. {
  24. name: testFile.name + prePostPosition,
  25. expectedValidationResult: testFile.expectedValidationResult
  26. }
  27. );
  28. replicatedTestFiles.push(
  29. {
  30. name: prePostPosition + testFile.name,
  31. expectedValidationResult: testFile.expectedValidationResult
  32. }
  33. );
  34. replicatedTestFiles.push(
  35. {
  36. name: prePostPosition + testFile.name + prePostPosition,
  37. expectedValidationResult: testFile.expectedValidationResult
  38. }
  39. );
  40. });
  41. });
  42. beforeEach (function () {
  43. //fake input for the sharing token
  44. $('#testArea').append(
  45. '<input name="sharingToken" value="" id="sharingToken" type="hidden">'
  46. );
  47. });
  48. replicatedTestFiles.map(function (testFile) {
  49. it("validates the filenames correctly", function() {
  50. data = {
  51. 'submit': function() {},
  52. 'files': [testFile]
  53. }
  54. expect(OCA.FilesSharingDrop.addFileToUpload('',data)).
  55. toBe(
  56. testFile.expectedValidationResult,
  57. 'wrongly validated file named "'+testFile.name+'"'
  58. );
  59. });
  60. if (testFile.expectedValidationResult === true) {
  61. it("should set correct PUT URL, Auth header and submit", function () {
  62. data = {
  63. 'submit': sinon.stub(),
  64. 'files': [testFile]
  65. }
  66. $('#sharingToken').val(sharingToken);
  67. OCA.FilesSharingDrop.addFileToUpload('',data);
  68. expect(data.submit.calledOnce).toEqual(true);
  69. expect(data.url).toContain("/public.php/dav/files/" + sharingToken + '/' + encodeURI(testFile.name));
  70. });
  71. }
  72. });
  73. });