diff options
author | Mario <mario@mariovavti.com> | 2018-03-09 11:12:18 +0100 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2018-03-09 11:12:18 +0100 |
commit | 4baf5eab16d809977a44e7911ddcab0ff8383897 (patch) | |
tree | 393f618c4cfc20f53264ecd8a26a08de0823d35d /library/cropperjs/test/options | |
parent | 577da0eb9eb1f90a4cf7a70cfb3582cfb49007ac (diff) | |
parent | 7361af85b5488fc8bd1744389a3a332dc74276b0 (diff) | |
download | volse-hubzilla-3.2.tar.gz volse-hubzilla-3.2.tar.bz2 volse-hubzilla-3.2.zip |
Merge branch '3.2RC'3.2
Diffstat (limited to 'library/cropperjs/test/options')
32 files changed, 1283 insertions, 0 deletions
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); + } + }); +}); |