ZeroClipboard.Core.tests.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*global ZeroClipboard */
  2. (function(module, test) {
  3. "use strict";
  4. // Helper functions
  5. var TestUtils = {
  6. getHtmlBridge: function() {
  7. return document.getElementById(ZeroClipboard.config("containerId"));
  8. }
  9. };
  10. var originalConfig, originalFlashDetect;
  11. module("ZeroClipboard.Core.js (built) unit tests", {
  12. setup: function() {
  13. // Store
  14. originalConfig = ZeroClipboard.config();
  15. originalFlashDetect = ZeroClipboard.isFlashUnusable;
  16. // Modify
  17. ZeroClipboard.isFlashUnusable = function() {
  18. return false;
  19. };
  20. },
  21. teardown: function() {
  22. // Restore
  23. ZeroClipboard.destroy();
  24. ZeroClipboard.config(originalConfig);
  25. ZeroClipboard.isFlashUnusable = originalFlashDetect;
  26. }
  27. });
  28. test("`swfPath` finds the expected default URL", function(assert) {
  29. assert.expect(1);
  30. // Assert, act, assert
  31. var rootOrigin = window.location.protocol + "//" + window.location.host + "/";
  32. var indexOfTest = window.location.pathname.toLowerCase().indexOf("/test/");
  33. var rootDir = window.location.pathname.slice(1, indexOfTest + 1);
  34. var rootPath = rootOrigin + rootDir;
  35. //var zcJsUrl = rootPath + "dist/ZeroClipboard.Core.js";
  36. var swfPathBasedOnZeroClipboardJsPath = rootPath + "dist/ZeroClipboard.swf";
  37. // Test that the client has the expected default URL [even if it's not correct]
  38. assert.strictEqual(ZeroClipboard.config("swfPath"), swfPathBasedOnZeroClipboardJsPath);
  39. });
  40. test("`destroy` destroys the bridge", function(assert) {
  41. assert.expect(3);
  42. // Arrange
  43. ZeroClipboard.isFlashUnusable = function() {
  44. return false;
  45. };
  46. // Assert, arrange, assert, act, assert
  47. assert.equal(TestUtils.getHtmlBridge(), null, "The bridge does not exist before creating a client");
  48. ZeroClipboard.create();
  49. assert.notEqual(TestUtils.getHtmlBridge(), null, "The bridge does exist after creating a client");
  50. ZeroClipboard.destroy();
  51. assert.equal(TestUtils.getHtmlBridge(), null, "The bridge does not exist after calling `destroy`");
  52. });
  53. })(QUnit.module, QUnit.test);