aboutsummaryrefslogtreecommitdiffstats
path: root/library/cropperjs/test/specs/events
diff options
context:
space:
mode:
Diffstat (limited to 'library/cropperjs/test/specs/events')
-rw-r--r--library/cropperjs/test/specs/events/crop.spec.js30
-rw-r--r--library/cropperjs/test/specs/events/cropend.spec.js47
-rw-r--r--library/cropperjs/test/specs/events/cropmove.spec.js71
-rw-r--r--library/cropperjs/test/specs/events/cropstart.spec.js75
-rw-r--r--library/cropperjs/test/specs/events/ready.spec.js26
-rw-r--r--library/cropperjs/test/specs/events/zoom.spec.js56
6 files changed, 305 insertions, 0 deletions
diff --git a/library/cropperjs/test/specs/events/crop.spec.js b/library/cropperjs/test/specs/events/crop.spec.js
new file mode 100644
index 000000000..04ec1fd10
--- /dev/null
+++ b/library/cropperjs/test/specs/events/crop.spec.js
@@ -0,0 +1,30 @@
+describe('crop (event)', () => {
+ it('should trigger the `crop` event', (done) => {
+ const image = window.createImage();
+
+ image.addEventListener('crop', (event) => {
+ expect(event.type).to.equal('crop');
+ done();
+ });
+
+ new Cropper(image);
+ });
+
+ it('should have expected properties in `event.detail`', (done) => {
+ const image = window.createImage();
+
+ image.addEventListener('crop', (event) => {
+ expect(event.detail).to.be.an('object').that.has.all.keys(['x', 'y', 'width', 'height', 'rotate', 'scaleX', 'scaleY']);
+ expect(event.detail.x).to.be.a('number');
+ expect(event.detail.y).to.be.a('number');
+ expect(event.detail.width).to.be.a('number');
+ expect(event.detail.height).to.be.a('number');
+ expect(event.detail.rotate).to.be.a('number');
+ expect(event.detail.scaleX).to.be.a('number');
+ expect(event.detail.scaleY).to.be.a('number');
+ done();
+ });
+
+ new Cropper(image);
+ });
+});
diff --git a/library/cropperjs/test/specs/events/cropend.spec.js b/library/cropperjs/test/specs/events/cropend.spec.js
new file mode 100644
index 000000000..8bdbc92d7
--- /dev/null
+++ b/library/cropperjs/test/specs/events/cropend.spec.js
@@ -0,0 +1,47 @@
+describe('cropend (event)', () => {
+ const POINTER_DOWN = window.PointerEvent ? 'pointerdown' : 'mousedown';
+ const POINTER_MOVE = window.PointerEvent ? 'pointermove' : 'mousemove';
+ const POINTER_UP = window.PointerEvent ? 'pointerup' : 'mouseup';
+
+ it('should trigger the `cropend` event', (done) => {
+ const image = window.createImage();
+ let cropper;
+
+ image.addEventListener('ready', () => {
+ const { dragBox } = cropper;
+
+ dragBox.dispatchEvent(window.createEvent(POINTER_DOWN));
+ dragBox.dispatchEvent(window.createEvent(POINTER_MOVE));
+ dragBox.dispatchEvent(window.createEvent(POINTER_UP));
+ });
+
+ image.addEventListener('cropend', (event) => {
+ expect(event.type).to.equal('cropend');
+ done();
+ });
+
+ cropper = new Cropper(image);
+ });
+
+ it('should have expected properties in `event.detail`', (done) => {
+ const image = window.createImage();
+ let cropper;
+
+ image.addEventListener('ready', () => {
+ const { dragBox } = cropper;
+
+ dragBox.dispatchEvent(window.createEvent(POINTER_DOWN));
+ dragBox.dispatchEvent(window.createEvent(POINTER_MOVE));
+ dragBox.dispatchEvent(window.createEvent(POINTER_UP));
+ });
+
+ image.addEventListener('cropend', (event) => {
+ expect(event.detail).to.be.an('object').that.has.all.keys(['action', 'originalEvent']);
+ expect(event.detail.action).to.equal('crop');
+ expect(event.detail.originalEvent.type).to.equal(POINTER_UP);
+ done();
+ });
+
+ cropper = new Cropper(image);
+ });
+});
diff --git a/library/cropperjs/test/specs/events/cropmove.spec.js b/library/cropperjs/test/specs/events/cropmove.spec.js
new file mode 100644
index 000000000..1349bf3e2
--- /dev/null
+++ b/library/cropperjs/test/specs/events/cropmove.spec.js
@@ -0,0 +1,71 @@
+describe('cropmove (event)', () => {
+ const POINTER_DOWN = window.PointerEvent ? 'pointerdown' : 'mousedown';
+ const POINTER_MOVE = window.PointerEvent ? 'pointermove' : 'mousemove';
+ const POINTER_UP = window.PointerEvent ? 'pointerup' : 'mouseup';
+
+ it('should trigger the `cropmove` event', (done) => {
+ const image = window.createImage();
+ let cropper;
+
+ image.addEventListener('ready', () => {
+ const { dragBox } = cropper;
+
+ dragBox.dispatchEvent(window.createEvent(POINTER_DOWN));
+ dragBox.dispatchEvent(window.createEvent(POINTER_MOVE));
+ dragBox.dispatchEvent(window.createEvent(POINTER_UP));
+ });
+
+ image.addEventListener('cropmove', (event) => {
+ expect(event.detail.action).to.equal('crop');
+ done();
+ });
+
+ cropper = new Cropper(image);
+ });
+
+ it('should have expected properties in `event.detail`', (done) => {
+ const image = window.createImage();
+ let cropper;
+
+ image.addEventListener('ready', () => {
+ const { dragBox } = cropper;
+
+ dragBox.dispatchEvent(window.createEvent(POINTER_DOWN));
+ dragBox.dispatchEvent(window.createEvent(POINTER_MOVE));
+ dragBox.dispatchEvent(window.createEvent(POINTER_UP));
+ });
+
+ image.addEventListener('cropmove', (event) => {
+ expect(event.detail).to.be.an('object').that.has.all.keys(['action', 'originalEvent']);
+ expect(event.detail.action).to.equal('crop');
+ expect(event.detail.originalEvent.type).to.equal(POINTER_MOVE);
+ done();
+ });
+
+ cropper = new Cropper(image);
+ });
+
+ it('should not trigger the `crop` event when default prevented', (done) => {
+ const image = window.createImage();
+ let cropper;
+
+ image.addEventListener('ready', () => {
+ const { dragBox } = cropper;
+
+ image.addEventListener('crop', () => {
+ expect.fail(1, 0);
+ });
+
+ dragBox.dispatchEvent(window.createEvent(POINTER_DOWN));
+ dragBox.dispatchEvent(window.createEvent(POINTER_MOVE));
+ dragBox.dispatchEvent(window.createEvent(POINTER_UP));
+ });
+
+ image.addEventListener('cropmove', (event) => {
+ event.preventDefault();
+ done();
+ });
+
+ cropper = new Cropper(image);
+ });
+});
diff --git a/library/cropperjs/test/specs/events/cropstart.spec.js b/library/cropperjs/test/specs/events/cropstart.spec.js
new file mode 100644
index 000000000..41e21ce62
--- /dev/null
+++ b/library/cropperjs/test/specs/events/cropstart.spec.js
@@ -0,0 +1,75 @@
+describe('cropstart (event)', () => {
+ const POINTER_DOWN = window.PointerEvent ? 'pointerdown' : 'mousedown';
+ const POINTER_MOVE = window.PointerEvent ? 'pointermove' : 'mousemove';
+ const POINTER_UP = window.PointerEvent ? 'pointerup' : 'mouseup';
+
+ it('should trigger the `cropstart` event', (done) => {
+ const image = window.createImage();
+ let cropper;
+
+ image.addEventListener('ready', () => {
+ const { dragBox } = cropper;
+
+ dragBox.dispatchEvent(window.createEvent(POINTER_DOWN));
+ dragBox.dispatchEvent(window.createEvent(POINTER_MOVE));
+ dragBox.dispatchEvent(window.createEvent(POINTER_UP));
+ });
+
+ image.addEventListener('cropstart', (event) => {
+ expect(event.type).to.equal('cropstart');
+ done();
+ });
+
+ cropper = new Cropper(image);
+ });
+
+ it('should have expected properties in `event.detail`', (done) => {
+ const image = window.createImage();
+ let cropper;
+
+ image.addEventListener('ready', () => {
+ const { dragBox } = cropper;
+
+ dragBox.dispatchEvent(window.createEvent(POINTER_DOWN));
+ dragBox.dispatchEvent(window.createEvent(POINTER_MOVE));
+ dragBox.dispatchEvent(window.createEvent(POINTER_UP));
+ });
+
+ image.addEventListener('cropstart', (event) => {
+ expect(event.detail).to.be.an('object').that.has.all.keys(['action', 'originalEvent']);
+ expect(event.detail.action).to.equal('crop');
+ expect(event.detail.originalEvent.type).to.equal(POINTER_DOWN);
+ done();
+ });
+
+ cropper = new Cropper(image);
+ });
+
+ it('should not trigger the `cropmove` and `cropend` events when default prevented', (done) => {
+ const image = window.createImage();
+ let cropper;
+
+ image.addEventListener('ready', () => {
+ const { dragBox } = cropper;
+
+ dragBox.dispatchEvent(window.createEvent(POINTER_DOWN));
+ dragBox.dispatchEvent(window.createEvent(POINTER_MOVE));
+ dragBox.dispatchEvent(window.createEvent(POINTER_UP));
+ });
+
+ image.addEventListener('cropstart', (event) => {
+ event.preventDefault();
+ done();
+ });
+
+ image.addEventListener('cropmove', () => {
+ expect.fail(1, 0);
+ });
+
+ image.addEventListener('cropend', () => {
+ expect.fail(1, 0);
+ });
+
+ cropper = new Cropper(image);
+ });
+});
diff --git a/library/cropperjs/test/specs/events/ready.spec.js b/library/cropperjs/test/specs/events/ready.spec.js
new file mode 100644
index 000000000..fd88314f0
--- /dev/null
+++ b/library/cropperjs/test/specs/events/ready.spec.js
@@ -0,0 +1,26 @@
+describe('ready (event)', () => {
+ it('should trigger the `ready` event', (done) => {
+ const image = window.createImage();
+
+ image.addEventListener('ready', (event) => {
+ expect(event.type).to.equal('ready');
+ done();
+ });
+
+ new Cropper(image);
+ });
+
+ it('should trigger the `crop` event even though default prevented', (done) => {
+ const image = window.createImage();
+
+ image.addEventListener('ready', (event) => {
+ event.preventDefault();
+ });
+
+ image.addEventListener('crop', () => {
+ done();
+ });
+
+ new Cropper(image);
+ });
+});
diff --git a/library/cropperjs/test/specs/events/zoom.spec.js b/library/cropperjs/test/specs/events/zoom.spec.js
new file mode 100644
index 000000000..c827067b7
--- /dev/null
+++ b/library/cropperjs/test/specs/events/zoom.spec.js
@@ -0,0 +1,56 @@
+describe('zoom (event)', () => {
+ it('should trigger the `zoom` event', (done) => {
+ const image = window.createImage();
+ let cropper;
+
+ image.addEventListener('ready', () => {
+ cropper.zoom(0.1);
+ });
+
+ image.addEventListener('zoom', (event) => {
+ expect(event.type).to.equal('zoom');
+ done();
+ });
+
+ cropper = new Cropper(image);
+ });
+
+ it('should have correct properties in `event.detail`', (done) => {
+ const image = window.createImage();
+ let cropper;
+
+ image.addEventListener('ready', () => {
+ cropper.zoom(0.1);
+ });
+
+ image.addEventListener('zoom', (event) => {
+ expect(event.detail).to.be.an('object').that.has.all.keys(['ratio', 'oldRatio', 'originalEvent']);
+ expect(event.detail.ratio).to.be.a('number');
+ expect(event.detail.oldRatio).to.be.a('number');
+ expect(event.detail.ratio).to.be.above(0);
+ expect(event.detail.oldRatio).to.be.above(0);
+ expect(event.detail.ratio).to.be.above(event.detail.oldRatio);
+ done();
+ });
+
+ cropper = new Cropper(image);
+ });
+
+ it('should not change the canvas sizes when default prevented', (done) => {
+ const image = window.createImage();
+ let cropper;
+
+ image.addEventListener('ready', () => {
+ const canvasData = cropper.getCanvasData();
+
+ expect(cropper.zoom(0.1).getCanvasData()).to.deep.equal(canvasData);
+ done();
+ });
+
+ image.addEventListener('zoom', (event) => {
+ event.preventDefault();
+ });
+
+ cropper = new Cropper(image);
+ });
+});