diff options
Diffstat (limited to 'library/cropperjs/test')
68 files changed, 2358 insertions, 0 deletions
diff --git a/library/cropperjs/test/css/main.css b/library/cropperjs/test/css/main.css new file mode 100644 index 000000000..6a86d123c --- /dev/null +++ b/library/cropperjs/test/css/main.css @@ -0,0 +1,9 @@ +.container { + max-width: 640px; + max-height: 360px; + margin: 20px auto; +} + +.container > img { + max-width: 100%; +} diff --git a/library/cropperjs/test/events/crop.js b/library/cropperjs/test/events/crop.js new file mode 100644 index 000000000..1f769cf60 --- /dev/null +++ b/library/cropperjs/test/events/crop.js @@ -0,0 +1,21 @@ +QUnit.test('events#crop', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(7); + + image.addEventListener('crop', function (e) { + assert.ok(util.isNumber(e.detail.x)); + assert.ok(util.isNumber(e.detail.y)); + assert.ok(util.isNumber(e.detail.width)); + assert.ok(util.isNumber(e.detail.height)); + assert.ok(util.isNumber(e.detail.rotate)); + assert.ok(util.isNumber(e.detail.scaleX)); + assert.ok(util.isNumber(e.detail.scaleY)); + + done(); + }); + + return new Cropper(image); +}); diff --git a/library/cropperjs/test/events/cropend.js b/library/cropperjs/test/events/cropend.js new file mode 100644 index 000000000..1f18fb435 --- /dev/null +++ b/library/cropperjs/test/events/cropend.js @@ -0,0 +1,24 @@ +QUnit.test('events#cropend', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + image.addEventListener('ready', function () { + var PointerEvent = window.PointerEvent; + var cropper = this.cropper; + + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerdown' : 'mousedown'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointermove' : 'mousemove'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerup' : 'mouseup'); + + done(); + }); + + image.addEventListener('cropend', function (e) { + assert.strictEqual(e.detail.action, 'crop'); + }); + + return new Cropper(image); +}); diff --git a/library/cropperjs/test/events/cropmove.js b/library/cropperjs/test/events/cropmove.js new file mode 100644 index 000000000..c695b7fdd --- /dev/null +++ b/library/cropperjs/test/events/cropmove.js @@ -0,0 +1,24 @@ +QUnit.test('events#cropmove', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + image.addEventListener('ready', function () { + var PointerEvent = window.PointerEvent; + var cropper = this.cropper; + + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerdown' : 'mousedown'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointermove' : 'mousemove'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerup' : 'mouseup'); + + done(); + }); + + image.addEventListener('cropmove', function (e) { + assert.strictEqual(e.detail.action, 'crop'); + }); + + return new Cropper(image); +}); diff --git a/library/cropperjs/test/events/cropstart.js b/library/cropperjs/test/events/cropstart.js new file mode 100644 index 000000000..7d9b597a0 --- /dev/null +++ b/library/cropperjs/test/events/cropstart.js @@ -0,0 +1,56 @@ +QUnit.test('events#cropstart', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + image.addEventListener('ready', function () { + var PointerEvent = window.PointerEvent; + var cropper = this.cropper; + + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerdown' : 'mousedown'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerup' : 'mouseup'); + + done(); + }); + + image.addEventListener('cropstart', function (e) { + assert.strictEqual(e.detail.action, 'crop'); + }); + + return new Cropper(image); +}); + +QUnit.test('events#cropstart: default prevented', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(0); + + image.addEventListener('ready', function () { + var PointerEvent = window.PointerEvent; + var cropper = this.cropper; + + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerdown' : 'mousedown'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointermove' : 'mousemove'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerup' : 'mouseup'); + + done(); + }); + + image.addEventListener('cropstart', function (e) { + e.preventDefault(); + }); + + image.addEventListener('cropmove', function () { + assert.ok(false); + }); + + image.addEventListener('cropend', function () { + assert.ok(false); + }); + + return new Cropper(image); +}); diff --git a/library/cropperjs/test/events/ready.js b/library/cropperjs/test/events/ready.js new file mode 100644 index 000000000..fbec2ff0c --- /dev/null +++ b/library/cropperjs/test/events/ready.js @@ -0,0 +1,15 @@ +QUnit.test('events#ready', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + image.addEventListener('ready', function () { + assert.ok(true); + + done(); + }); + + return new Cropper(image); +}); diff --git a/library/cropperjs/test/events/zoom.js b/library/cropperjs/test/events/zoom.js new file mode 100644 index 000000000..99fda34b5 --- /dev/null +++ b/library/cropperjs/test/events/zoom.js @@ -0,0 +1,46 @@ +QUnit.test('events#zoom', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(3); + + image.addEventListener('ready', function () { + var cropper = this.cropper; + + cropper.zoom(0.1); + + done(); + }); + + image.addEventListener('zoom', function (e) { + assert.ok(e.detail.ratio > 0); + assert.ok(e.detail.oldRatio > 0); + assert.ok(e.detail.ratio > e.detail.oldRatio); + }); + + return new Cropper(image); +}); + +QUnit.test('events#zoom: default prevented', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + image.addEventListener('ready', function () { + var cropper = this.cropper; + var canvasData = cropper.getCanvasData(); + + assert.deepEqual(cropper.zoom(0.1).getCanvasData(), canvasData); + + done(); + }); + + image.addEventListener('zoom', function (e) { + e.preventDefault(); + }); + + return new Cropper(image); +}); diff --git a/library/cropperjs/test/index.html b/library/cropperjs/test/index.html new file mode 100644 index 000000000..bdcaf6b21 --- /dev/null +++ b/library/cropperjs/test/index.html @@ -0,0 +1,90 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <meta http-equiv="x-ua-compatible" content="ie=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> + <title>Cropper.js</title> + <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.4.0.css"> + <link rel="stylesheet" href="../dist/cropper.css"> + <link rel="stylesheet" href="css/main.css"> +</head> +<body> + <div id="qunit"></div> + <div id="qunit-fixture"></div> + <script src="https://code.jquery.com/qunit/qunit-2.4.0.js"></script> + <script src="../dist/cropper.js"></script> + <script src="js/main.js"></script> + + <!-- Options --> + <script src="options/viewMode.js"></script> + <script src="options/dragMode.js"></script> + <script src="options/aspectRatio.js"></script> + <script src="options/data.js"></script> + <!-- <script src="options/checkCrossOrigin.js"></script> --> + <script src="options/checkOrientation.js"></script> + <script src="options/modal.js"></script> + <script src="options/guides.js"></script> + <script src="options/center.js"></script> + <script src="options/highlight.js"></script> + <script src="options/background.js"></script> + <script src="options/autoCrop.js"></script> + <script src="options/movable.js"></script> + <script src="options/rotatable.js"></script> + <script src="options/scalable.js"></script> + <script src="options/zoomable.js"></script> + <script src="options/zoomOnWheel.js"></script> + <script src="options/cropBoxMovable.js"></script> + <script src="options/cropBoxResizable.js"></script> + <script src="options/toggleDragModeOnDblclick.js"></script> + <script src="options/minCanvasWidth.js"></script> + <script src="options/minCanvasHeight.js"></script> + <script src="options/minCropBoxWidth.js"></script> + <script src="options/minCropBoxHeight.js"></script> + <script src="options/minContainerWidth.js"></script> + <script src="options/minContainerHeight.js"></script> + <script src="options/ready.js"></script> + <script src="options/cropstart.js"></script> + <script src="options/cropmove.js"></script> + <script src="options/cropend.js"></script> + <script src="options/crop.js"></script> + <script src="options/zoom.js"></script> + + <!-- Methods --> + <script src="methods/crop.js"></script> + <script src="methods/reset.js"></script> + <script src="methods/clear.js"></script> + <script src="methods/replace.js"></script> + <script src="methods/enable.js"></script> + <script src="methods/disable.js"></script> + <script src="methods/destroy.js"></script> + <script src="methods/move.js"></script> + <script src="methods/moveTo.js"></script> + <script src="methods/zoom.js"></script> + <script src="methods/zoomTo.js"></script> + <script src="methods/rotate.js"></script> + <script src="methods/rotateTo.js"></script> + <script src="methods/scale.js"></script> + <script src="methods/scaleX.js"></script> + <script src="methods/scaleY.js"></script> + <script src="methods/getData.js"></script> + <script src="methods/setData.js"></script> + <script src="methods/getContainerData.js"></script> + <script src="methods/getImageData.js"></script> + <script src="methods/getCanvasData.js"></script> + <script src="methods/setCanvasData.js"></script> + <script src="methods/getCropBoxData.js"></script> + <script src="methods/setCropBoxData.js"></script> + <script src="methods/getCroppedCanvas.js"></script> + <script src="methods/setAspectRatio.js"></script> + <script src="methods/setDragMode.js"></script> + + <!-- Events --> + <script src="events/ready.js"></script> + <script src="events/cropstart.js"></script> + <script src="events/cropmove.js"></script> + <script src="events/cropend.js"></script> + <script src="events/crop.js"></script> + <script src="events/zoom.js"></script> +</body> +</html> diff --git a/library/cropperjs/test/js/main.js b/library/cropperjs/test/js/main.js new file mode 100644 index 000000000..79fda799f --- /dev/null +++ b/library/cropperjs/test/js/main.js @@ -0,0 +1,74 @@ +window.Util = { + isNumber: function (n) { + return typeof n === 'number' && !isNaN(n); + }, + isFunction: function (fn) { + return typeof fn === 'function'; + }, + hasClass: function (element, className) { + return element.classList.contains(className); + }, + getByClass: function (element, className) { + return element.getElementsByClassName ? + element.getElementsByClassName(className) : + element.querySelectorAll('.' + className); + }, + createImage: function (attrs) { + var container = document.createElement('div'); + var image = new Image(); + var attr; + + if (typeof attrs !== 'object') { + attrs = {}; + } + + if (!attrs.src) { + attrs.src = '../docs/images/picture.jpg'; + } + + for (attr in attrs) { + if (attrs.hasOwnProperty(attr)) { + image[attr] = attrs[attr]; + } + } + + container.className = 'container'; + container.appendChild(image); + document.body.appendChild(container); + + return image; + }, + dispatchEvent: function (element, type, data) { + var event; + + if (element.dispatchEvent) { + // Event and CustomEvent on IE9-11 are global objects, not constructors + if (typeof Event === 'function' && typeof CustomEvent === 'function') { + if (!data) { + event = new Event(type, { + bubbles: true, + cancelable: true + }); + } else { + event = new CustomEvent(type, { + detail: data, + bubbles: true, + cancelable: true + }); + } + } else if (!data) { + event = document.createEvent('Event'); + event.initEvent(type, true, true); + } else { + event = document.createEvent('CustomEvent'); + event.initCustomEvent(type, true, true, data); + } + + // IE9+ + return element.dispatchEvent(event); + } else if (element.fireEvent) { + // IE6-10 (native events only) + return element.fireEvent('on' + type); + } + } +}; diff --git a/library/cropperjs/test/methods/clear.js b/library/cropperjs/test/methods/clear.js new file mode 100644 index 000000000..6510ebad2 --- /dev/null +++ b/library/cropperjs/test/methods/clear.js @@ -0,0 +1,29 @@ +QUnit.test('methods#clear', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(4); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + + cropper.clear(); + assert.notOk(cropper.cropped); + assert.deepEqual(cropper.getData(), { + x: 0, + y: 0, + width: 0, + height: 0, + rotate: 0, + scaleX: 1, + scaleY: 1 + }); + assert.deepEqual(cropper.getCropBoxData(), {}); + assert.ok(util.hasClass(cropper.cropBox, 'cropper-hidden')); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/crop.js b/library/cropperjs/test/methods/crop.js new file mode 100644 index 000000000..e4ae679f1 --- /dev/null +++ b/library/cropperjs/test/methods/crop.js @@ -0,0 +1,24 @@ +QUnit.test('methods#crop', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(4); + + return new Cropper(image, { + autoCrop: false, + + ready: function () { + var cropper = this.cropper; + + assert.notOk(cropper.cropped); + assert.ok(util.hasClass(cropper.cropBox, 'cropper-hidden')); + + cropper.crop(); + assert.ok(cropper.cropped); + assert.notOk(util.hasClass(cropper.cropBox, 'cropper-hidden')); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/destroy.js b/library/cropperjs/test/methods/destroy.js new file mode 100644 index 000000000..cb65e0696 --- /dev/null +++ b/library/cropperjs/test/methods/destroy.js @@ -0,0 +1,22 @@ +QUnit.test('methods#destroy', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(4); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + + assert.ok(typeof cropper === 'object'); + assert.ok(util.hasClass(image, 'cropper-hidden')); + + cropper.destroy(); + assert.ok(typeof this.cropper === 'undefined'); + assert.notOk(util.hasClass(image, 'cropper-hidden')); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/disable.js b/library/cropperjs/test/methods/disable.js new file mode 100644 index 000000000..c87f7aa91 --- /dev/null +++ b/library/cropperjs/test/methods/disable.js @@ -0,0 +1,60 @@ +QUnit.test('methods#disable', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(11); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var options = cropper.options; + var cropBoxData; + var canvasData; + var imageData; + var action; + + cropper.disable(); + assert.ok(cropper.disabled); + assert.ok(util.hasClass(cropper.cropper, 'cropper-disabled')); + + cropBoxData = cropper.getCropBoxData(); + cropper.clear(); + assert.deepEqual(cropper.getCropBoxData(), cropBoxData); + + imageData = cropper.getImageData(); + cropper.move(10, 10); + assert.deepEqual(cropper.getImageData(), imageData); + + cropper.zoom(0.5); + assert.strictEqual(cropper.getImageData().ratio, imageData.ratio); + + cropper.rotate(15); + assert.strictEqual(cropper.getImageData().rotate, imageData.rotate); + + cropper.scale(-1); + assert.strictEqual(cropper.getImageData().scaleX, imageData.scaleX); + + canvasData = cropper.getCanvasData(); + cropper.setCanvasData({ + width: canvasData.width - 160 + }); + assert.deepEqual(cropper.getCanvasData(), canvasData); + + cropBoxData = cropper.getCropBoxData(); + cropper.setCropBoxData({ + height: cropBoxData.height - 90 + }); + assert.deepEqual(cropper.getCropBoxData(), cropBoxData); + + cropper.setAspectRatio(0.618); + assert.ok(isNaN(options.aspectRatio)); + + action = cropper.dragBox.dataset.action; + cropper.setDragMode('none'); + assert.strictEqual(cropper.dragBox.dataset.action, action); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/enable.js b/library/cropperjs/test/methods/enable.js new file mode 100644 index 000000000..ebd5b9529 --- /dev/null +++ b/library/cropperjs/test/methods/enable.js @@ -0,0 +1,23 @@ +QUnit.test('methods#enable', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(4); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + + cropper.disable(); + assert.ok(cropper.disabled); + assert.ok(util.hasClass(cropper.cropper, 'cropper-disabled')); + + cropper.enable(); + assert.notOk(cropper.disabled); + assert.notOk(util.hasClass(cropper.cropper, 'cropper-disabled')); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/getCanvasData.js b/library/cropperjs/test/methods/getCanvasData.js new file mode 100644 index 000000000..60d96af4e --- /dev/null +++ b/library/cropperjs/test/methods/getCanvasData.js @@ -0,0 +1,23 @@ +QUnit.test('methods#getCanvasData', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(6); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.getCanvasData(); + + assert.ok(util.isNumber(canvasData.left)); + assert.ok(util.isNumber(canvasData.top)); + assert.ok(util.isNumber(canvasData.width)); + assert.ok(util.isNumber(canvasData.height)); + assert.ok(util.isNumber(canvasData.naturalWidth)); + assert.ok(util.isNumber(canvasData.naturalHeight)); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/getContainerData.js b/library/cropperjs/test/methods/getContainerData.js new file mode 100644 index 000000000..094421ba0 --- /dev/null +++ b/library/cropperjs/test/methods/getContainerData.js @@ -0,0 +1,19 @@ +QUnit.test('methods#getContainerData', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var containerData = cropper.getContainerData(); + + assert.ok(util.isNumber(containerData.width)); + assert.ok(util.isNumber(containerData.height)); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/getCropBoxData.js b/library/cropperjs/test/methods/getCropBoxData.js new file mode 100644 index 000000000..844c7953e --- /dev/null +++ b/library/cropperjs/test/methods/getCropBoxData.js @@ -0,0 +1,21 @@ +QUnit.test('methods#getCropBoxData', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(4); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var cropBoxData = cropper.getCropBoxData(); + + assert.ok(util.isNumber(cropBoxData.left)); + assert.ok(util.isNumber(cropBoxData.top)); + assert.ok(util.isNumber(cropBoxData.width)); + assert.ok(util.isNumber(cropBoxData.height)); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/getCroppedCanvas.js b/library/cropperjs/test/methods/getCroppedCanvas.js new file mode 100644 index 000000000..4117497a5 --- /dev/null +++ b/library/cropperjs/test/methods/getCroppedCanvas.js @@ -0,0 +1,33 @@ +QUnit.test('methods#getCroppedCanvas', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(7); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var canvas = cropper.getCroppedCanvas({ + width: 160, + height: 90 + }); + var pixelData; + + assert.ok(canvas instanceof HTMLCanvasElement); + assert.strictEqual(canvas.width, 160); + assert.strictEqual(canvas.height, 90); + + canvas = cropper.rotate(90).getCroppedCanvas({ + fillColor: '#010101' + }); + pixelData = canvas.getContext('2d').getImageData(0, 0, 1, 1).data; + assert.strictEqual(pixelData[0], 1, 'red is 1'); + assert.strictEqual(pixelData[1], 1, 'green is 1'); + assert.strictEqual(pixelData[2], 1, 'blue is 1'); + assert.strictEqual(pixelData[3], 255, 'color is opaque'); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/getData.js b/library/cropperjs/test/methods/getData.js new file mode 100644 index 000000000..9c519eb7f --- /dev/null +++ b/library/cropperjs/test/methods/getData.js @@ -0,0 +1,46 @@ +QUnit.test('methods#getData', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(7); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var data = cropper.getData(); + + assert.ok(util.isNumber(data.x)); + assert.ok(util.isNumber(data.y)); + assert.ok(util.isNumber(data.width)); + assert.ok(util.isNumber(data.height)); + assert.ok(util.isNumber(data.rotate)); + assert.ok(util.isNumber(data.scaleX)); + assert.ok(util.isNumber(data.scaleY)); + + done(); + } + }); +}); + +QUnit.test('methods#getData: rounded', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(4); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var data = cropper.getData(true); + + assert.ok(data.x % 1 === 0); + assert.ok(data.y % 1 === 0); + assert.ok(data.width % 1 === 0); + assert.ok(data.height % 1 === 0); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/getImageData.js b/library/cropperjs/test/methods/getImageData.js new file mode 100644 index 000000000..bd6e1941d --- /dev/null +++ b/library/cropperjs/test/methods/getImageData.js @@ -0,0 +1,31 @@ +QUnit.test('methods#getImageData', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(10); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var imageData = cropper.getImageData(); + + assert.ok(util.isNumber(imageData.naturalWidth)); + assert.ok(util.isNumber(imageData.naturalHeight)); + assert.ok(util.isNumber(imageData.aspectRatio)); + assert.ok(util.isNumber(imageData.left)); + assert.ok(util.isNumber(imageData.top)); + assert.ok(util.isNumber(imageData.width)); + assert.ok(util.isNumber(imageData.height)); + + imageData = cropper.rotateTo(45).getImageData(); + assert.strictEqual(imageData.rotate, 45); + + imageData = cropper.scale(-1, -1).getImageData(); + assert.strictEqual(imageData.scaleX, -1); + assert.strictEqual(imageData.scaleY, -1); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/move.js b/library/cropperjs/test/methods/move.js new file mode 100644 index 000000000..c2ead8412 --- /dev/null +++ b/library/cropperjs/test/methods/move.js @@ -0,0 +1,20 @@ +QUnit.test('methods#move', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.getCanvasData(); + var changedCanvasData = cropper.move(1, 1).getCanvasData(); + + assert.strictEqual(changedCanvasData.left, canvasData.left + 1); + assert.strictEqual(changedCanvasData.top, canvasData.top + 1); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/moveTo.js b/library/cropperjs/test/methods/moveTo.js new file mode 100644 index 000000000..e8bf0eebd --- /dev/null +++ b/library/cropperjs/test/methods/moveTo.js @@ -0,0 +1,19 @@ +QUnit.test('methods#moveTo', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.moveTo(0, 0).getCanvasData(); + + assert.strictEqual(canvasData.left, 0); + assert.strictEqual(canvasData.top, 0); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/replace.js b/library/cropperjs/test/methods/replace.js new file mode 100644 index 000000000..3fc8fe0b6 --- /dev/null +++ b/library/cropperjs/test/methods/replace.js @@ -0,0 +1,23 @@ +QUnit.test('methods#replace', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + + cropper.options.ready = function () { + assert.notOk(cropper.cropped); + cropper.crop(); + assert.ok(cropper.cropped); + done(); + }; + + cropper.options.autoCrop = false; + cropper.replace('../docs/images/picture-2.jpg'); + } + }); +}); diff --git a/library/cropperjs/test/methods/reset.js b/library/cropperjs/test/methods/reset.js new file mode 100644 index 000000000..3e047394c --- /dev/null +++ b/library/cropperjs/test/methods/reset.js @@ -0,0 +1,35 @@ +QUnit.test('methods#reset', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(4); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.getCanvasData(); + var cropBoxData = cropper.getCropBoxData(); + + cropper.setCanvasData({ + top: canvasData.top + 10, + width: canvasData.width - 10 + }); + + assert.notDeepEqual(cropper.getCanvasData(), canvasData); + + cropper.setCropBoxData({ + left: cropBoxData.left + 10, + height: cropBoxData.height - 10 + }); + + assert.notDeepEqual(cropper.getCropBoxData(), cropBoxData); + + cropper.reset(); + assert.deepEqual(cropper.getCanvasData(), canvasData); + assert.deepEqual(cropper.getCropBoxData(), cropBoxData); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/rotate.js b/library/cropperjs/test/methods/rotate.js new file mode 100644 index 000000000..749096f0b --- /dev/null +++ b/library/cropperjs/test/methods/rotate.js @@ -0,0 +1,19 @@ +QUnit.test('methods#rotate', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(3); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + + assert.strictEqual(cropper.rotate(360).getImageData().rotate, 0); + assert.strictEqual(cropper.rotate(90).getImageData().rotate, 90); + assert.strictEqual(cropper.rotate(-180).getImageData().rotate, -90); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/rotateTo.js b/library/cropperjs/test/methods/rotateTo.js new file mode 100644 index 000000000..323431e76 --- /dev/null +++ b/library/cropperjs/test/methods/rotateTo.js @@ -0,0 +1,20 @@ +QUnit.test('methods#rotateTo', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(4); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + + assert.strictEqual(cropper.rotateTo(360).getImageData().rotate, 0); + assert.strictEqual(cropper.rotateTo(90).getImageData().rotate, 90); + assert.strictEqual(cropper.rotateTo(0).getImageData().rotate, 0); + assert.strictEqual(cropper.rotateTo(-180).getImageData().rotate, -180); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/scale.js b/library/cropperjs/test/methods/scale.js new file mode 100644 index 000000000..be1caa589 --- /dev/null +++ b/library/cropperjs/test/methods/scale.js @@ -0,0 +1,19 @@ +QUnit.test('methods#scale', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var imageData = cropper.scale(-1, -1).getImageData(); + + assert.strictEqual(imageData.scaleX, -1); + assert.strictEqual(imageData.scaleY, -1); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/scaleX.js b/library/cropperjs/test/methods/scaleX.js new file mode 100644 index 000000000..c799df58d --- /dev/null +++ b/library/cropperjs/test/methods/scaleX.js @@ -0,0 +1,18 @@ +QUnit.test('methods#scaleX', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var imageData = cropper.scaleX(-1).getImageData(); + + assert.strictEqual(imageData.scaleX, -1); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/scaleY.js b/library/cropperjs/test/methods/scaleY.js new file mode 100644 index 000000000..026b93a1f --- /dev/null +++ b/library/cropperjs/test/methods/scaleY.js @@ -0,0 +1,18 @@ +QUnit.test('methods#scaleY', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var imageData = cropper.scaleY(-1).getImageData(); + + assert.strictEqual(imageData.scaleY, -1); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/setAspectRatio.js b/library/cropperjs/test/methods/setAspectRatio.js new file mode 100644 index 000000000..ddf46798d --- /dev/null +++ b/library/cropperjs/test/methods/setAspectRatio.js @@ -0,0 +1,20 @@ +QUnit.test('methods#setAspectRatio', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var options = cropper.options; + + assert.ok(isNaN(options.aspectRatio)); + cropper.setAspectRatio(1); + assert.strictEqual(options.aspectRatio, 1); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/setCanvasData.js b/library/cropperjs/test/methods/setCanvasData.js new file mode 100644 index 000000000..e8f6511dc --- /dev/null +++ b/library/cropperjs/test/methods/setCanvasData.js @@ -0,0 +1,34 @@ +QUnit.test('methods#setCanvasData', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(6); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.getCanvasData(); + var changedCanvasData = cropper.setCanvasData({ + left: 16, + top: 9 + }).getCanvasData(); + + assert.notStrictEqual(changedCanvasData.left, canvasData.left); + assert.notStrictEqual(changedCanvasData.top, canvasData.top); + assert.strictEqual(changedCanvasData.width, canvasData.width); + assert.strictEqual(changedCanvasData.height, canvasData.height); + + canvasData = cropper.getCanvasData(); + changedCanvasData = cropper.setCanvasData({ + width: 320, + height: 180 + }).getCanvasData(); + + assert.notStrictEqual(changedCanvasData.width, canvasData.width); + assert.notStrictEqual(changedCanvasData.height, canvasData.height); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/setCropBoxData.js b/library/cropperjs/test/methods/setCropBoxData.js new file mode 100644 index 000000000..e78767cfc --- /dev/null +++ b/library/cropperjs/test/methods/setCropBoxData.js @@ -0,0 +1,36 @@ +QUnit.test('methods#setCropBoxData', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(8); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var cropBoxData = cropper.getCropBoxData(); + var changedCropBoxData = cropper.setCropBoxData({ + left: 16, + top: 9 + }).getCropBoxData(); + + assert.notStrictEqual(changedCropBoxData.left, cropBoxData.left); + assert.notStrictEqual(changedCropBoxData.top, cropBoxData.top); + assert.strictEqual(changedCropBoxData.width, cropBoxData.width); + assert.strictEqual(changedCropBoxData.height, cropBoxData.height); + + cropBoxData = cropper.getCropBoxData(); + changedCropBoxData = cropper.setCropBoxData({ + width: 320, + height: 180 + }).getCropBoxData(); + + assert.strictEqual(changedCropBoxData.left, cropBoxData.left); + assert.strictEqual(changedCropBoxData.top, cropBoxData.top); + assert.notStrictEqual(changedCropBoxData.width, cropBoxData.width); + assert.notStrictEqual(changedCropBoxData.height, cropBoxData.height); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/setData.js b/library/cropperjs/test/methods/setData.js new file mode 100644 index 000000000..4e1360f09 --- /dev/null +++ b/library/cropperjs/test/methods/setData.js @@ -0,0 +1,36 @@ +QUnit.test('methods#setData', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(8); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var data = cropper.getData(); + var changedData = cropper.setData({ + x: 16, + y: 9 + }).getData(); + + assert.notStrictEqual(changedData.x, data.x); + assert.notStrictEqual(changedData.y, data.y); + assert.strictEqual(changedData.width, data.width); + assert.strictEqual(changedData.height, data.height); + + data = cropper.getData(); + changedData = cropper.setData({ + width: 320, + height: 180 + }).getData(); + + assert.strictEqual(changedData.x, data.x); + assert.strictEqual(changedData.y, data.y); + assert.notStrictEqual(changedData.width, data.width); + assert.notStrictEqual(changedData.height, data.height); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/setDragMode.js b/library/cropperjs/test/methods/setDragMode.js new file mode 100644 index 000000000..1b611af9b --- /dev/null +++ b/library/cropperjs/test/methods/setDragMode.js @@ -0,0 +1,27 @@ +QUnit.test('methods#setDragMode', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(4); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var dragBox = cropper.dragBox; + + assert.strictEqual(dragBox.dataset.action, 'crop'); + + cropper.setDragMode('move'); + assert.strictEqual(dragBox.dataset.action, 'move'); + + cropper.setDragMode('crop'); + assert.strictEqual(dragBox.dataset.action, 'crop'); + + cropper.setDragMode('none'); + assert.strictEqual(dragBox.dataset.action, 'none'); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/zoom.js b/library/cropperjs/test/methods/zoom.js new file mode 100644 index 000000000..70a1a763a --- /dev/null +++ b/library/cropperjs/test/methods/zoom.js @@ -0,0 +1,20 @@ +QUnit.test('methods#zoom', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.getCanvasData(); + var changedCanvasData = cropper.zoom(0.1).getCanvasData(); + + assert.ok(changedCanvasData.width > canvasData.width); + assert.ok(changedCanvasData.height > canvasData.height); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/methods/zoomTo.js b/library/cropperjs/test/methods/zoomTo.js new file mode 100644 index 000000000..dd9e81760 --- /dev/null +++ b/library/cropperjs/test/methods/zoomTo.js @@ -0,0 +1,21 @@ +QUnit.test('methods#zoomTo', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(3); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var imageData = cropper.zoomTo(1).getImageData(); + var canvasData = cropper.getCanvasData(); + + assert.strictEqual(imageData.width, imageData.naturalWidth); + assert.strictEqual(canvasData.width, canvasData.naturalWidth); + assert.strictEqual(canvasData.naturalWidth, imageData.naturalWidth); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/aspectRatio.js b/library/cropperjs/test/options/aspectRatio.js new file mode 100644 index 000000000..d7ba89401 --- /dev/null +++ b/library/cropperjs/test/options/aspectRatio.js @@ -0,0 +1,39 @@ +QUnit.test('options#aspectRatio: NaN', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + // aspectRatio: NaN, + + ready: function () { + var cropper = this.cropper; + + assert.ok(isNaN(cropper.options.aspectRatio)); + + done(); + } + }); +}); + +QUnit.test('options#aspectRatio: 1', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + aspectRatio: 1, + + ready: function () { + var cropper = this.cropper; + + assert.strictEqual(cropper.options.aspectRatio, 1); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/autoCrop.js b/library/cropperjs/test/options/autoCrop.js new file mode 100644 index 000000000..f010966eb --- /dev/null +++ b/library/cropperjs/test/options/autoCrop.js @@ -0,0 +1,39 @@ +QUnit.test('options#autoCrop: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + // autoCrop: true, + + ready: function () { + var cropper = this.cropper; + + assert.ok(cropper.cropped); + + done(); + } + }); +}); + +QUnit.test('options#autoCrop: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + autoCrop: false, + + ready: function () { + var cropper = this.cropper; + + assert.notOk(cropper.cropped); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/background.js b/library/cropperjs/test/options/background.js new file mode 100644 index 000000000..21dbb8b12 --- /dev/null +++ b/library/cropperjs/test/options/background.js @@ -0,0 +1,40 @@ +QUnit.test('options#background: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + // background: true, + + ready: function () { + var cropper = this.cropper; + + assert.ok(util.hasClass(cropper.cropper, 'cropper-bg')); + + done(); + } + }); +}); + +QUnit.test('options#background: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + background: false, + + ready: function () { + var cropper = this.cropper; + + assert.notOk(util.hasClass(cropper.cropper, 'cropper-bg')); + + done(); + } + }); + +}); diff --git a/library/cropperjs/test/options/center.js b/library/cropperjs/test/options/center.js new file mode 100644 index 000000000..5d45eb021 --- /dev/null +++ b/library/cropperjs/test/options/center.js @@ -0,0 +1,41 @@ +QUnit.test('options#center: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + // center: true, + + ready: function () { + var cropper = this.cropper; + var center = util.getByClass(cropper.cropBox, 'cropper-center'); + + assert.notOk(util.hasClass(center[0], 'cropper-hidden')); + + done(); + } + }); +}); + +QUnit.test('options#center: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + center: false, + + ready: function () { + var cropper = this.cropper; + var center = util.getByClass(cropper.cropBox, 'cropper-center'); + + assert.ok(util.hasClass(center[0], 'cropper-hidden')); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/checkCrossOrigin.js b/library/cropperjs/test/options/checkCrossOrigin.js new file mode 100644 index 000000000..86fde8f6f --- /dev/null +++ b/library/cropperjs/test/options/checkCrossOrigin.js @@ -0,0 +1,67 @@ +QUnit.test('options#checkCrossOrigin: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage({ + src: 'https://fengyuanchen.github.io/cropperjs/images/picture.jpg' + }); + + assert.expect(2); + + return new Cropper(image, { + // checkCrossOrigin: true, + + ready: function () { + var cropper = this.cropper; + + assert.strictEqual(cropper.image.crossOrigin, 'anonymous'); + assert.ok(cropper.image.src.indexOf('timestamp') >= 0); + + done(); + } + }); +}); + +QUnit.test('options#checkCrossOrigin: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage({ + src: 'https://fengyuanchen.github.io/cropperjs/images/picture.jpg' + }); + + assert.expect(2); + + return new Cropper(image, { + checkCrossOrigin: false, + + ready: function () { + var cropper = this.cropper; + + assert.notStrictEqual(cropper.image.crossOrigin, 'anonymous'); + assert.ok(cropper.image.src.indexOf('timestamp') < 0); + + done(); + } + }); +}); + +QUnit.test('options#checkCrossOrigin: exists crossOrigin attribute', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage({ + src: 'https://fengyuanchen.github.io/cropperjs/images/picture.jpg', + crossOrigin: 'anonymous' + }); + + assert.expect(2); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + + assert.strictEqual(cropper.image.crossOrigin, 'anonymous'); + assert.ok(cropper.image.src.indexOf('timestamp') < 0); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/checkOrientation.js b/library/cropperjs/test/options/checkOrientation.js new file mode 100644 index 000000000..0fe548404 --- /dev/null +++ b/library/cropperjs/test/options/checkOrientation.js @@ -0,0 +1,43 @@ +QUnit.test('options#checkOrientation: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage({ + src: '../docs/images/picture-3.jpg' + }); + + assert.expect(1); + + return new Cropper(image, { + // checkOrientation: true, + + ready: function () { + var cropper = this.cropper; + + assert.notStrictEqual(cropper.getData().rotate, 0); + + done(); + } + }); +}); + +QUnit.test('options#checkOrientation: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage({ + src: '../docs/images/picture-3.jpg' + }); + + assert.expect(1); + + return new Cropper(image, { + checkOrientation: false, + + ready: function () { + var cropper = this.cropper; + + assert.strictEqual(cropper.getData().rotate, 0); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/crop.js b/library/cropperjs/test/options/crop.js new file mode 100644 index 000000000..a4b48585e --- /dev/null +++ b/library/cropperjs/test/options/crop.js @@ -0,0 +1,21 @@ +QUnit.test('options#crop', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(7); + + return new Cropper(image, { + crop: function (e) { + assert.ok(util.isNumber(e.detail.x)); + assert.ok(util.isNumber(e.detail.y)); + assert.ok(util.isNumber(e.detail.width)); + assert.ok(util.isNumber(e.detail.height)); + assert.ok(util.isNumber(e.detail.rotate)); + assert.ok(util.isNumber(e.detail.scaleX)); + assert.ok(util.isNumber(e.detail.scaleY)); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/cropBoxMovable.js b/library/cropperjs/test/options/cropBoxMovable.js new file mode 100644 index 000000000..d5d3e1d7d --- /dev/null +++ b/library/cropperjs/test/options/cropBoxMovable.js @@ -0,0 +1,41 @@ +QUnit.test('options#cropBoxMovable: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + // cropBoxMovable: true, + + ready: function () { + var cropper = this.cropper; + var face = util.getByClass(cropper.cropBox, 'cropper-face'); + + assert.strictEqual(face[0].dataset.action, 'all'); + + done(); + } + }); +}); + +QUnit.test('options#cropBoxMovable: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + cropBoxMovable: false, + + ready: function () { + var cropper = this.cropper; + var face = util.getByClass(cropper.cropBox, 'cropper-face'); + + assert.strictEqual(face[0].dataset.action, cropper.options.dragMode); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/cropBoxResizable.js b/library/cropperjs/test/options/cropBoxResizable.js new file mode 100644 index 000000000..37093642b --- /dev/null +++ b/library/cropperjs/test/options/cropBoxResizable.js @@ -0,0 +1,65 @@ +QUnit.test('options#cropBoxResizable: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(12); + + return new Cropper(image, { + // cropBoxResizable: true, + + ready: function () { + var cropper = this.cropper; + var line = util.getByClass(cropper.cropBox, 'cropper-line'); + var point = util.getByClass(cropper.cropBox, 'cropper-point'); + + assert.notOk(util.hasClass(line[0], 'cropper-hidden')); + assert.notOk(util.hasClass(line[1], 'cropper-hidden')); + assert.notOk(util.hasClass(line[2], 'cropper-hidden')); + assert.notOk(util.hasClass(line[3], 'cropper-hidden')); + assert.notOk(util.hasClass(point[0], 'cropper-hidden')); + assert.notOk(util.hasClass(point[1], 'cropper-hidden')); + assert.notOk(util.hasClass(point[2], 'cropper-hidden')); + assert.notOk(util.hasClass(point[3], 'cropper-hidden')); + assert.notOk(util.hasClass(point[4], 'cropper-hidden')); + assert.notOk(util.hasClass(point[5], 'cropper-hidden')); + assert.notOk(util.hasClass(point[6], 'cropper-hidden')); + assert.notOk(util.hasClass(point[7], 'cropper-hidden')); + + done(); + } + }); +}); + +QUnit.test('options#cropBoxResizable: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(12); + + return new Cropper(image, { + cropBoxResizable: false, + + ready: function () { + var cropper = this.cropper; + var line = util.getByClass(cropper.cropBox, 'cropper-line'); + var point = util.getByClass(cropper.cropBox, 'cropper-point'); + + assert.ok(util.hasClass(line[0], 'cropper-hidden')); + assert.ok(util.hasClass(line[1], 'cropper-hidden')); + assert.ok(util.hasClass(line[2], 'cropper-hidden')); + assert.ok(util.hasClass(line[3], 'cropper-hidden')); + assert.ok(util.hasClass(point[0], 'cropper-hidden')); + assert.ok(util.hasClass(point[1], 'cropper-hidden')); + assert.ok(util.hasClass(point[2], 'cropper-hidden')); + assert.ok(util.hasClass(point[3], 'cropper-hidden')); + assert.ok(util.hasClass(point[4], 'cropper-hidden')); + assert.ok(util.hasClass(point[5], 'cropper-hidden')); + assert.ok(util.hasClass(point[6], 'cropper-hidden')); + assert.ok(util.hasClass(point[7], 'cropper-hidden')); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/cropend.js b/library/cropperjs/test/options/cropend.js new file mode 100644 index 000000000..abfe815c0 --- /dev/null +++ b/library/cropperjs/test/options/cropend.js @@ -0,0 +1,24 @@ +QUnit.test('options#cropend', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + ready: function () { + var PointerEvent = window.PointerEvent; + var cropper = this.cropper; + + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerdown' : 'mousedown'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointermove' : 'mousemove'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerup' : 'mouseup'); + + done(); + }, + + cropend: function (e) { + assert.strictEqual(e.detail.action, 'crop'); + } + }); +}); diff --git a/library/cropperjs/test/options/cropmove.js b/library/cropperjs/test/options/cropmove.js new file mode 100644 index 000000000..fa20f4011 --- /dev/null +++ b/library/cropperjs/test/options/cropmove.js @@ -0,0 +1,24 @@ +QUnit.test('options#cropmove', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + ready: function () { + var PointerEvent = window.PointerEvent; + var cropper = this.cropper; + + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerdown' : 'mousedown'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointermove' : 'mousemove'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerup' : 'mouseup'); + + done(); + }, + + cropmove: function (e) { + assert.strictEqual(e.detail.action, 'crop'); + } + }); +}); diff --git a/library/cropperjs/test/options/cropstart.js b/library/cropperjs/test/options/cropstart.js new file mode 100644 index 000000000..f547269cd --- /dev/null +++ b/library/cropperjs/test/options/cropstart.js @@ -0,0 +1,56 @@ +QUnit.test('options#cropstart', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + ready: function () { + var PointerEvent = window.PointerEvent; + var cropper = this.cropper; + + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerdown' : 'mousedown'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerup' : 'mouseup'); + + done(); + }, + + cropstart: function (e) { + assert.strictEqual(e.detail.action, 'crop'); + } + }); +}); + +QUnit.test('options#cropstart: default prevented', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(0); + + return new Cropper(image, { + ready: function () { + var PointerEvent = window.PointerEvent; + var cropper = this.cropper; + + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerdown' : 'mousedown'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointermove' : 'mousemove'); + util.dispatchEvent(cropper.dragBox, PointerEvent ? 'pointerup' : 'mouseup'); + + done(); + }, + + cropstart: function (e) { + e.preventDefault(); + }, + + cropmove: function () { + assert.ok(false); + }, + + cropend: function () { + assert.ok(false); + } + }); +}); diff --git a/library/cropperjs/test/options/data.js b/library/cropperjs/test/options/data.js new file mode 100644 index 000000000..e9da6a4dd --- /dev/null +++ b/library/cropperjs/test/options/data.js @@ -0,0 +1,35 @@ +QUnit.test('options#data', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + var initialData = { + x: 360, + y: 450, + width: 640, + height: 360, + rotate: 45, + scaleX: -1, + scaleY: -1 + }; + + assert.expect(7); + + return new Cropper(image, { + data: initialData, + + ready: function () { + var cropper = this.cropper; + var data = cropper.getData(true); + + assert.strictEqual(data.x, initialData.x); + assert.strictEqual(data.y, initialData.y); + assert.strictEqual(data.width, initialData.width); + assert.strictEqual(data.height, initialData.height); + assert.strictEqual(data.rotate, initialData.rotate); + assert.strictEqual(data.scaleX, initialData.scaleX); + assert.strictEqual(data.scaleY, initialData.scaleY); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/dragMode.js b/library/cropperjs/test/options/dragMode.js new file mode 100644 index 000000000..57f31ff13 --- /dev/null +++ b/library/cropperjs/test/options/dragMode.js @@ -0,0 +1,60 @@ +QUnit.test('options#dragMode: crop', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + // dragMode: 'crop', + + ready: function () { + var cropper = this.cropper; + + assert.strictEqual(cropper.dragBox.dataset.action, 'crop'); + + done(); + } + }); +}); + +QUnit.test('options#dragMode: move', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + dragMode: 'move', + + ready: function () { + var cropper = this.cropper; + + assert.strictEqual(cropper.dragBox.dataset.action, 'move'); + + done(); + } + }); +}); + + +QUnit.test('options#dragMode: none', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + dragMode: 'none', + + ready: function () { + var cropper = this.cropper; + + assert.strictEqual(cropper.dragBox.dataset.action, 'none'); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/guides.js b/library/cropperjs/test/options/guides.js new file mode 100644 index 000000000..298c3ad3a --- /dev/null +++ b/library/cropperjs/test/options/guides.js @@ -0,0 +1,43 @@ +QUnit.test('options#guides: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + // guides: true, + + ready: function () { + var cropper = this.cropper; + var dashed = util.getByClass(cropper.cropBox, 'cropper-dashed'); + + assert.notOk(util.hasClass(dashed[0], 'cropper-hidden')); + assert.notOk(util.hasClass(dashed[1], 'cropper-hidden')); + + done(); + } + }); +}); + +QUnit.test('options#guides: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + guides: false, + + ready: function () { + var cropper = this.cropper; + var dashed = util.getByClass(cropper.cropBox, 'cropper-dashed'); + + assert.ok(util.hasClass(dashed[0], 'cropper-hidden')); + assert.ok(util.hasClass(dashed[1], 'cropper-hidden')); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/highlight.js b/library/cropperjs/test/options/highlight.js new file mode 100644 index 000000000..a1db4687f --- /dev/null +++ b/library/cropperjs/test/options/highlight.js @@ -0,0 +1,41 @@ +QUnit.test('options#highlight: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + // highlight: true, + + ready: function () { + var cropper = this.cropper; + var face = util.getByClass(cropper.cropBox, 'cropper-face'); + + assert.notOk(util.hasClass(face[0], 'cropper-invisible')); + + done(); + } + }); +}); + +QUnit.test('options#highlight: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + highlight: false, + + ready: function () { + var cropper = this.cropper; + var face = util.getByClass(cropper.cropBox, 'cropper-face'); + + assert.ok(util.hasClass(face[0], 'cropper-invisible')); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/minCanvasHeight.js b/library/cropperjs/test/options/minCanvasHeight.js new file mode 100644 index 000000000..c9745a9b1 --- /dev/null +++ b/library/cropperjs/test/options/minCanvasHeight.js @@ -0,0 +1,23 @@ +QUnit.test('options#minCanvasHeight', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + var minCanvasHeight = 270; + + assert.expect(1); + + return new Cropper(image, { + minCanvasHeight: minCanvasHeight, + + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.setCanvasData({ + height: 180 + }).getCanvasData(); + + assert.strictEqual(Math.round(canvasData.height), minCanvasHeight); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/minCanvasWidth.js b/library/cropperjs/test/options/minCanvasWidth.js new file mode 100644 index 000000000..61601e4f9 --- /dev/null +++ b/library/cropperjs/test/options/minCanvasWidth.js @@ -0,0 +1,23 @@ +QUnit.test('options#minCanvasWidth', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + var minCanvasWidth = 480; + + assert.expect(1); + + return new Cropper(image, { + minCanvasWidth: minCanvasWidth, + + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.setCanvasData({ + width: 320 + }).getCanvasData(); + + assert.strictEqual(Math.round(canvasData.width), minCanvasWidth); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/minContainerHeight.js b/library/cropperjs/test/options/minContainerHeight.js new file mode 100644 index 000000000..85d7a70ef --- /dev/null +++ b/library/cropperjs/test/options/minContainerHeight.js @@ -0,0 +1,21 @@ +QUnit.test('options#minContainerHeight', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + var minContainerHeight = 361; + + assert.expect(1); + + return new Cropper(image, { + minContainerHeight: minContainerHeight, + + ready: function () { + var cropper = this.cropper; + var containerData = cropper.getContainerData(); + + assert.strictEqual(Math.round(containerData.height), minContainerHeight); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/minContainerWidth.js b/library/cropperjs/test/options/minContainerWidth.js new file mode 100644 index 000000000..2119cc96e --- /dev/null +++ b/library/cropperjs/test/options/minContainerWidth.js @@ -0,0 +1,21 @@ +QUnit.test('options#minContainerWidth', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + var minContainerWidth = 641; + + assert.expect(1); + + return new Cropper(image, { + minContainerWidth: minContainerWidth, + + ready: function () { + var cropper = this.cropper; + var containerData = cropper.getContainerData(); + + assert.strictEqual(Math.round(containerData.width), minContainerWidth); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/minCropBoxHeight.js b/library/cropperjs/test/options/minCropBoxHeight.js new file mode 100644 index 000000000..ccf50aefe --- /dev/null +++ b/library/cropperjs/test/options/minCropBoxHeight.js @@ -0,0 +1,23 @@ +QUnit.test('options#minCropBoxHeight', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + var minCropBoxHeight = 150; + + assert.expect(1); + + return new Cropper(image, { + minCropBoxHeight: minCropBoxHeight, + + ready: function () { + var cropper = this.cropper; + var cropBoxData = cropper.setCropBoxData({ + height: 100 + }).getCropBoxData(); + + assert.strictEqual(Math.round(cropBoxData.height), minCropBoxHeight); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/minCropBoxWidth.js b/library/cropperjs/test/options/minCropBoxWidth.js new file mode 100644 index 000000000..acde5c366 --- /dev/null +++ b/library/cropperjs/test/options/minCropBoxWidth.js @@ -0,0 +1,23 @@ +QUnit.test('options#minCropBoxWidth', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + var minCropBoxWidth = 300; + + assert.expect(1); + + return new Cropper(image, { + minCropBoxWidth: minCropBoxWidth, + + ready: function () { + var cropper = this.cropper; + var cropBoxData = cropper.setCropBoxData({ + width: 200 + }).getCropBoxData(); + + assert.strictEqual(Math.round(cropBoxData.width), minCropBoxWidth); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/modal.js b/library/cropperjs/test/options/modal.js new file mode 100644 index 000000000..7284cb264 --- /dev/null +++ b/library/cropperjs/test/options/modal.js @@ -0,0 +1,39 @@ +QUnit.test('options#modal: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + // modal: true, + + ready: function () { + var cropper = this.cropper; + + assert.ok(util.hasClass(cropper.dragBox, 'cropper-modal')); + + done(); + } + }); +}); + +QUnit.test('options#modal: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + modal: false, + + ready: function () { + var cropper = this.cropper; + + assert.notOk(util.hasClass(cropper.dragBox, 'cropper-modal')); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/movable.js b/library/cropperjs/test/options/movable.js new file mode 100644 index 000000000..0e2c53506 --- /dev/null +++ b/library/cropperjs/test/options/movable.js @@ -0,0 +1,45 @@ +QUnit.test('options#movable: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + // movable: true, + + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.getCanvasData(); + var changedCanvasData = cropper.move(10, 10).getCanvasData(); + + assert.strictEqual(changedCanvasData.left, canvasData.left + 10); + assert.strictEqual(changedCanvasData.top, canvasData.top + 10); + + done(); + } + }); +}); + +QUnit.test('options#movable: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + movable: false, + + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.getCanvasData(); + var changedCanvasData = cropper.move(10, 10).getCanvasData(); + + assert.strictEqual(changedCanvasData.left, canvasData.left); + assert.strictEqual(changedCanvasData.top, canvasData.top); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/ready.js b/library/cropperjs/test/options/ready.js new file mode 100644 index 000000000..e09e8369c --- /dev/null +++ b/library/cropperjs/test/options/ready.js @@ -0,0 +1,15 @@ +QUnit.test('options#ready', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + ready: function () { + assert.ok(true); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/rotatable.js b/library/cropperjs/test/options/rotatable.js new file mode 100644 index 000000000..992e9362f --- /dev/null +++ b/library/cropperjs/test/options/rotatable.js @@ -0,0 +1,39 @@ +QUnit.test('options#rotatable: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + // rotatable: true, + + ready: function () { + var cropper = this.cropper; + + assert.strictEqual(cropper.rotate(90).getImageData().rotate, 90); + + done(); + } + }); +}); + +QUnit.test('options#rotatable: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + rotatable: false, + + ready: function () { + var cropper = this.cropper; + + assert.strictEqual(cropper.rotate(90).getImageData().rotate, undefined); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/scalable.js b/library/cropperjs/test/options/scalable.js new file mode 100644 index 000000000..c523eaf63 --- /dev/null +++ b/library/cropperjs/test/options/scalable.js @@ -0,0 +1,43 @@ +QUnit.test('options#scalable: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + // scalable: true, + + ready: function () { + var cropper = this.cropper; + var imageData = cropper.scale(-1, -1).getImageData(); + + assert.strictEqual(imageData.scaleX, -1); + assert.strictEqual(imageData.scaleY, -1); + + done(); + } + }); +}); + +QUnit.test('options#scalable: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + scalable: false, + + ready: function () { + var cropper = this.cropper; + var imageData = cropper.scale(-1, -1).getImageData(); + + assert.strictEqual(imageData.scaleX, undefined); + assert.strictEqual(imageData.scaleY, undefined); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/toggleDragModeOnDblclick.js b/library/cropperjs/test/options/toggleDragModeOnDblclick.js new file mode 100644 index 000000000..df64327b2 --- /dev/null +++ b/library/cropperjs/test/options/toggleDragModeOnDblclick.js @@ -0,0 +1,45 @@ +QUnit.test('options#toggleDragModeOnDblclick: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + // toggleDragModeOnDblclick: true, + + ready: function () { + var cropper = this.cropper; + var dragBox = cropper.dragBox; + + util.dispatchEvent(dragBox, 'dblclick'); + assert.ok(util.hasClass(dragBox, 'cropper-move')); + assert.strictEqual(dragBox.dataset.action, 'move'); + + done(); + } + }); +}); + +QUnit.test('options#toggleDragModeOnDblclick: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + toggleDragModeOnDblclick: false, + + ready: function () { + var cropper = this.cropper; + var dragBox = cropper.dragBox; + + util.dispatchEvent(dragBox, 'dblclick'); + assert.ok(util.hasClass(dragBox, 'cropper-crop')); + assert.strictEqual(dragBox.dataset.action, 'crop'); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/viewMode.js b/library/cropperjs/test/options/viewMode.js new file mode 100644 index 000000000..e39ec5fc1 --- /dev/null +++ b/library/cropperjs/test/options/viewMode.js @@ -0,0 +1,100 @@ +QUnit.test('options#viewMode: 0', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(4); + + return new Cropper(image, { + // viewMode: 0, + + ready: function () { + var cropper = this.cropper; + var canvasData = { + left: 100, + top: 100, + width: 160, + height: 90 + }; + var changedCanvasData = cropper.setCanvasData(canvasData).getCanvasData(); + + assert.strictEqual(changedCanvasData.left, canvasData.left); + assert.strictEqual(changedCanvasData.top, canvasData.top); + assert.strictEqual(changedCanvasData.width, canvasData.width); + assert.strictEqual(changedCanvasData.height, canvasData.height); + + done(); + } + }); +}); + +QUnit.test('options#viewMode: 1', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + viewMode: 1, + + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.zoom(-0.5).getCanvasData(); // Zoom out + var cropBoxData = cropper.getCropBoxData(); + + assert.ok(canvasData.width >= cropBoxData.width); + assert.ok(canvasData.height >= cropBoxData.height); + + done(); + } + }); +}); + +QUnit.test('options#viewMode: 2', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + viewMode: 2, + + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.zoom(-0.5).getCanvasData(); // Zoom out + var containerData = cropper.getContainerData(); + + assert.ok(canvasData.width >= containerData.width || + canvasData.height >= containerData.height); + + done(); + } + }); +}); + +QUnit.test('options#viewMode: 3', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(4); + + return new Cropper(image, { + viewMode: 3, + + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.zoom(-0.5).getCanvasData(); // Zoom out + var containerData = cropper.getContainerData(); + + assert.ok(canvasData.left <= 0); + assert.ok(canvasData.top <= 0); + assert.ok(canvasData.width >= containerData.width); + assert.ok(canvasData.height >= containerData.height); + + done(); + } + }); +}); diff --git a/library/cropperjs/test/options/zoom.js b/library/cropperjs/test/options/zoom.js new file mode 100644 index 000000000..51ebc76ad --- /dev/null +++ b/library/cropperjs/test/options/zoom.js @@ -0,0 +1,46 @@ +QUnit.test('options#zoom', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(3); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + + cropper.zoom(0.1); + + done(); + }, + + zoom: function (e) { + assert.ok(e.detail.ratio > 0); + assert.ok(e.detail.oldRatio > 0); + assert.ok(e.detail.ratio > e.detail.oldRatio); + } + }); +}); + +QUnit.test('options#zoom: default prevented', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.getCanvasData(); + + assert.deepEqual(cropper.zoom(0.1).getCanvasData(), canvasData); + + done(); + }, + + zoom: function (e) { + e.preventDefault(); + } + }); +}); diff --git a/library/cropperjs/test/options/zoomOnWheel.js b/library/cropperjs/test/options/zoomOnWheel.js new file mode 100644 index 000000000..1a1bf6dce --- /dev/null +++ b/library/cropperjs/test/options/zoomOnWheel.js @@ -0,0 +1,47 @@ +QUnit.test('options#zoomOnWheel: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(1); + + return new Cropper(image, { + // zoomOnWheel: true, + + ready: function () { + var cropper = this.cropper; + + util.dispatchEvent(cropper.cropper, 'wheel'); + + done(); + }, + + zoom: function () { + assert.ok(true); + } + }); +}); + +QUnit.test('options#zoomOnWheel: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(0); + + return new Cropper(image, { + zoomOnWheel: false, + + ready: function () { + var cropper = this.cropper; + + util.dispatchEvent(cropper.cropper, 'wheel'); + + done(); + }, + + zoom: function () { + assert.ok(false); + } + }); +}); diff --git a/library/cropperjs/test/options/zoomable.js b/library/cropperjs/test/options/zoomable.js new file mode 100644 index 000000000..9f8ec6fce --- /dev/null +++ b/library/cropperjs/test/options/zoomable.js @@ -0,0 +1,51 @@ +QUnit.test('options#zoomable: true', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(3); + + return new Cropper(image, { + // zoomable: true, + + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.getCanvasData(); + var changedCanvasData = cropper.zoom(0.1).getCanvasData(); + + assert.ok(changedCanvasData.width > canvasData.width); + assert.ok(changedCanvasData.height > canvasData.height); + + done(); + }, + zoom: function () { + assert.ok(true); + } + }); +}); + +QUnit.test('options#zoomable: false', function (assert) { + var done = assert.async(); + var util = window.Util; + var image = util.createImage(); + + assert.expect(2); + + return new Cropper(image, { + zoomable: false, + + ready: function () { + var cropper = this.cropper; + var canvasData = cropper.getCanvasData(); + var changedCanvasData = cropper.zoom(0.1).getCanvasData(); + + assert.ok(changedCanvasData.width === canvasData.width); + assert.ok(changedCanvasData.height === canvasData.height); + + done(); + }, + zoom: function () { + assert.ok(false); + } + }); +}); |