Update v1.0.6

This commit is contained in:
Bhanu Slathia
2016-02-16 23:22:09 +05:30
parent 62d04a0372
commit c710c20b9e
7620 changed files with 244752 additions and 1070312 deletions

View File

@@ -0,0 +1,67 @@
/*global ZeroClipboard */
(function(module, test) {
"use strict";
// Helper functions
var TestUtils = {
getHtmlBridge: function() {
return document.getElementById(ZeroClipboard.config("containerId"));
}
};
var originalConfig, originalFlashDetect;
module("ZeroClipboard.Core.js (built) unit tests", {
setup: function() {
// Store
originalConfig = ZeroClipboard.config();
originalFlashDetect = ZeroClipboard.isFlashUnusable;
// Modify
ZeroClipboard.isFlashUnusable = function() {
return false;
};
},
teardown: function() {
// Restore
ZeroClipboard.destroy();
ZeroClipboard.config(originalConfig);
ZeroClipboard.isFlashUnusable = originalFlashDetect;
}
});
test("`swfPath` finds the expected default URL", function(assert) {
assert.expect(1);
// Assert, act, assert
var rootOrigin = window.location.protocol + "//" + window.location.host + "/";
var indexOfTest = window.location.pathname.toLowerCase().indexOf("/test/");
var rootDir = window.location.pathname.slice(1, indexOfTest + 1);
var rootPath = rootOrigin + rootDir;
//var zcJsUrl = rootPath + "dist/ZeroClipboard.Core.js";
var swfPathBasedOnZeroClipboardJsPath = rootPath + "dist/ZeroClipboard.swf";
// Test that the client has the expected default URL [even if it's not correct]
assert.strictEqual(ZeroClipboard.config("swfPath"), swfPathBasedOnZeroClipboardJsPath);
});
test("`destroy` destroys the bridge", function(assert) {
assert.expect(3);
// Arrange
ZeroClipboard.isFlashUnusable = function() {
return false;
};
// Assert, arrange, assert, act, assert
assert.equal(TestUtils.getHtmlBridge(), null, "The bridge does not exist before creating a client");
ZeroClipboard.create();
assert.notEqual(TestUtils.getHtmlBridge(), null, "The bridge does exist after creating a client");
ZeroClipboard.destroy();
assert.equal(TestUtils.getHtmlBridge(), null, "The bridge does not exist after calling `destroy`");
});
})(QUnit.module, QUnit.test);

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ZeroClipboard.Core.js unit tests</title>
<link rel="stylesheet" href="../../node_modules/qunitjs/qunit/qunit.css">
<script src="../../node_modules/qunitjs/qunit/qunit.js"></script>
<script>
// Polyfill in future functionality: https://github.com/jquery/qunit/issues/490
if (!QUnit.assert.expect) {
QUnit.assert.expect = QUnit.expect;
}
// Require `expect` calls
QUnit.config.requireExpects = true;
// Prevent against Firefox/Firebug failing the global pollution check
var getInterface = null;
// Prevent against failing the global pollution check in all browsers other than IE
if (typeof window.ActiveXObject === "undefined") {
window.ActiveXObject = null;
}
// Prevent against Flash's ExternalInterface failing the global pollution check (seems to be only in IE < 11)
var __flash__arrayToXML = null,
__flash__argumentsToXML = null,
__flash__objectToXML = null,
__flash__escapeXML = null,
__flash__toXML = null,
__flash__addCallback = null,
__flash__removeCallback = null,
__flash__request = null;
</script>
<script src="../../dist/ZeroClipboard.Core.js"></script>
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="ZeroClipboard.Core.tests.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>

View File

@@ -0,0 +1,228 @@
/*global ZeroClipboard */
(function(module, test) {
"use strict";
var originalConfig, originalFlashDetect;
// Helper functions
var TestUtils = {
getHtmlBridge: function() {
return document.getElementById(ZeroClipboard.config("containerId"));
}
};
module("ZeroClipboard.js (built) unit tests - Core", {
setup: function() {
// Store
originalConfig = ZeroClipboard.config();
originalFlashDetect = ZeroClipboard.isFlashUnusable;
// Modify
ZeroClipboard.isFlashUnusable = function() {
return false;
};
ZeroClipboard.config({ swfPath: originalConfig.swfPath.replace(/\/(?:src|test)\/.*$/i, "/dist/ZeroClipboard.swf") });
},
teardown: function() {
// Restore
ZeroClipboard.destroy();
ZeroClipboard.config(originalConfig);
ZeroClipboard.isFlashUnusable = originalFlashDetect;
}
});
test("`swfPath` finds the expected default URL", function(assert) {
assert.expect(1);
// Assert, act, assert
var rootOrigin = window.location.protocol + "//" + window.location.host + "/";
var indexOfTest = window.location.pathname.toLowerCase().indexOf("/test/");
var rootDir = window.location.pathname.slice(1, indexOfTest + 1);
var rootPath = rootOrigin + rootDir;
//var zcJsUrl = rootPath + "dist/ZeroClipboard.js";
var swfPathBasedOnZeroClipboardJsPath = rootPath + "dist/ZeroClipboard.swf";
// Test that the client has the expected default URL [even if it's not correct]
assert.strictEqual(ZeroClipboard.config("swfPath"), swfPathBasedOnZeroClipboardJsPath);
});
test("`destroy` destroys the bridge", function(assert) {
assert.expect(3);
// Arrange
ZeroClipboard.isFlashUnusable = function() {
return false;
};
// Assert, arrange, assert, act, assert
assert.equal(TestUtils.getHtmlBridge(), null, "The bridge does not exist before creating a client");
/*jshint nonew:false */
new ZeroClipboard();
assert.notEqual(TestUtils.getHtmlBridge(), null, "The bridge does exist after creating a client");
ZeroClipboard.destroy();
assert.equal(TestUtils.getHtmlBridge(), null, "The bridge does not exist after calling `destroy`");
});
module("ZeroClipboard.js (built) unit tests - Client", {
setup: function() {
// Store
originalConfig = ZeroClipboard.config();
originalFlashDetect = ZeroClipboard.isFlashUnusable;
// Modify
ZeroClipboard.isFlashUnusable = function() {
return false;
};
ZeroClipboard.config({ swfPath: originalConfig.swfPath.replace(/\/(?:src|test)\/.*$/i, "/dist/ZeroClipboard.swf") });
},
teardown: function() {
// Restore
ZeroClipboard.destroy();
ZeroClipboard.config(originalConfig);
ZeroClipboard.isFlashUnusable = originalFlashDetect;
}
});
test("`ZeroClipboard` exists", function(assert) {
assert.expect(1);
// Arrange -> N/A
// Act -> N/A
// Assert
assert.ok(ZeroClipboard);
});
test("Client is created properly", function(assert) {
assert.expect(2);
// Arrange & Act
var client = new ZeroClipboard();
// Assert
assert.ok(client);
assert.ok(client.id);
});
test("Client without selector doesn't have elements", function(assert) {
assert.expect(2);
// Arrange & Act
var client = new ZeroClipboard();
// Assert
assert.ok(client);
assert.deepEqual(client.elements(), []);
});
test("Object has a title", function(assert) {
assert.expect(1);
// Arrange
var client = new ZeroClipboard();
var currentEl = document.getElementById("d_clip_button");
// Act
client.clip(currentEl);
ZeroClipboard.activate(currentEl);
// Assert
assert.strictEqual(TestUtils.getHtmlBridge().getAttribute("title"), "Click me to copy to clipboard.");
// Revert
ZeroClipboard.deactivate();
});
test("Object has no title", function(assert) {
assert.expect(1);
// Arrange
var client = new ZeroClipboard();
var currentEl = document.getElementById("d_clip_button_no_title");
// Act
client.clip(currentEl);
ZeroClipboard.activate(currentEl);
// Assert
assert.ok(!TestUtils.getHtmlBridge().getAttribute("title"));
});
test("Object doesn't have data-clipboard-text", function(assert) {
assert.expect(1);
// Arrange
var client = new ZeroClipboard();
var currentEl = document.getElementById("d_clip_button_no_text");
// Act
client.clip(currentEl);
ZeroClipboard.activate(currentEl);
// Assert
assert.ok(!TestUtils.getHtmlBridge().getAttribute("data-clipboard-text"));
});
test("New client is not the same client (no singleton) but does share the same bridge", function(assert) {
assert.expect(6);
// Assert, arrange, assert, act, assert
var containerClass = "." + ZeroClipboard.config("containerClass");
assert.strictEqual($(containerClass).length, 0);
var client1 = new ZeroClipboard();
assert.ok(client1.id);
assert.strictEqual($(containerClass).length, 1);
var client2 = new ZeroClipboard();
assert.strictEqual($(containerClass).length, 1);
assert.notEqual(client2.id, client1.id);
assert.notEqual(client2, client1);
});
test("Calculations based on borderWidth never return NaN", function(assert) {
assert.expect(4);
// Arrange
var client = new ZeroClipboard();
var currentEl = document.getElementById("d_clip_button");
// Act
client.clip(currentEl);
ZeroClipboard.activate(currentEl);
// Assert
var htmlBridge = TestUtils.getHtmlBridge();
assert.strictEqual(/^-?[0-9\.]+px$/.test(htmlBridge.style.top), true);
assert.strictEqual(/^-?[0-9\.]+px$/.test(htmlBridge.style.left), true);
assert.strictEqual(/^-?[0-9\.]+px$/.test(htmlBridge.style.width), true);
assert.strictEqual(/^-?[0-9\.]+px$/.test(htmlBridge.style.height), true);
});
test("No more client singleton!", function(assert) {
assert.expect(7);
// Arrange
ZeroClipboard.isFlashUnusable = function() {
return false;
};
// Assert, arrange, assert, act, assert
assert.ok(!ZeroClipboard.prototype._singleton, "The client singleton does not exist on the prototype before creating a client");
var client1 = new ZeroClipboard();
assert.ok(!ZeroClipboard.prototype._singleton, "The client singleton does not exist on the prototype after creating a client");
assert.ok(!client1._singleton, "The client singleton does not exist on the client instance after creating a client");
var client2 = new ZeroClipboard();
assert.ok(!ZeroClipboard.prototype._singleton, "The client singleton does not exist on the prototype after creating a second client");
assert.ok(!client1._singleton, "The client singleton does not exist on the first client instance after creating a second client");
assert.ok(!client2._singleton, "The client singleton does not exist on the second client instance after creating a second client");
ZeroClipboard.destroy();
assert.ok(!ZeroClipboard.prototype._singleton, "The client singleton does not exist on the prototype after calling `destroy`");
});
})(QUnit.module, QUnit.test);

View File

@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ZeroClipboard.js unit tests</title>
<link rel="stylesheet" href="../../node_modules/qunitjs/qunit/qunit.css">
<script src="../../node_modules/qunitjs/qunit/qunit.js"></script>
<script>
// Polyfill in future functionality: https://github.com/jquery/qunit/issues/490
if (!QUnit.assert.expect) {
QUnit.assert.expect = QUnit.expect;
}
// Require `expect` calls
QUnit.config.requireExpects = true;
// Prevent against Firefox/Firebug failing the global pollution check
var getInterface = null;
// Prevent against failing the global pollution check in all browsers other than IE
if (typeof window.ActiveXObject === "undefined") {
window.ActiveXObject = null;
}
// Prevent against Flash's ExternalInterface failing the global pollution check (seems to be only in IE < 11)
var __flash__arrayToXML = null,
__flash__argumentsToXML = null,
__flash__objectToXML = null,
__flash__escapeXML = null,
__flash__toXML = null,
__flash__addCallback = null,
__flash__removeCallback = null,
__flash__request = null;
</script>
<script src="../../dist/ZeroClipboard.js"></script>
<script src="../../node_modules/jquery/dist/jquery.js"></script>
<script src="ZeroClipboard.tests.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<p>
<button id="d_clip_button" class="my_clip_button" title="Click me to copy to clipboard." data-clipboard-text="Copy me!"><b>Copy To Clipboard...</b></button>
</p>
<p>
<button id="d_clip_button_no_title" class="my_clip_button" data-clipboard-text="Copy me!"><b>Copy To Clipboard...</b></button>
</p>
<p>
<button id="d_clip_button_no_text" class="my_clip_button"><b>Copy To Clipboard...</b></button>
</p>
<p>
<button id="d_clip_button_input_text" class="my_clip_button" data-clipboard-target="clipboard_text"><b>Copy To Clipboard...</b></button>
</p>
<p>
<button id="d_clip_button_textarea_text" class="my_clip_button" data-clipboard-target="clipboard_textarea"><b>Copy To Clipboard...</b></button>
</p>
<button id="d_clip_button_pre_text" class="my_clip_button" data-clipboard-target="clipboard_pre"><b>Copy To Clipboard...</b></button>
<input type="text" id="clipboard_text" value="Clipboard Text"/>
<textarea id="clipboard_textarea">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</textarea>
<pre id="clipboard_pre">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</pre>
</div>
</body>
</html>