From f645c6f3a57bf5f53bbb2bde362b2447f725c977 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 11 Jan 2020 10:30:12 +0000 Subject: update cropperjs to the recent version --- .../cropperjs/test/specs/methods/getData.spec.js | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 library/cropperjs/test/specs/methods/getData.spec.js (limited to 'library/cropperjs/test/specs/methods/getData.spec.js') diff --git a/library/cropperjs/test/specs/methods/getData.spec.js b/library/cropperjs/test/specs/methods/getData.spec.js new file mode 100644 index 000000000..13bcd2304 --- /dev/null +++ b/library/cropperjs/test/specs/methods/getData.spec.js @@ -0,0 +1,91 @@ +describe('getData (method)', () => { + const initialData = { + x: 0, + y: 0, + width: 0, + height: 0, + rotate: 0, + scaleX: 1, + scaleY: 1, + }; + + it('should get initial data when it is not ready', () => { + const image = window.createImage(); + const cropper = new Cropper(image); + + expect(cropper.getData()).to.deep.equal(initialData); + }); + + it('should get initial data when it is not cropped', (done) => { + const image = window.createImage(); + const cropper = new Cropper(image, { + autoCrop: false, + + ready() { + expect(cropper.cropped).to.be.false; + expect(cropper.getData()).to.deep.equal(initialData); + done(); + }, + }); + }); + + it('should get data with expected properties', (done) => { + const image = window.createImage(); + const cropper = new Cropper(image, { + ready() { + const data = cropper.getData(); + + expect(data).to.be.an('object').that.has.all.keys(['x', 'y', 'width', 'height', 'rotate', 'scaleX', 'scaleY']); + expect(data.x).to.be.a('number'); + expect(data.y).to.be.a('number'); + expect(data.width).to.be.a('number'); + expect(data.height).to.be.a('number'); + expect(data.rotate).to.be.a('number'); + expect(data.scaleX).to.be.a('number'); + expect(data.scaleY).to.be.a('number'); + done(); + }, + }); + }); + + it('should get data with rounded property values', (done) => { + const image = window.createImage(); + const cropper = new Cropper(image, { + ready() { + const data = cropper.getData(true); + + expect(data.x % 1).to.equal(0); + expect(data.y % 1).to.equal(0); + expect(data.width % 1).to.equal(0); + expect(data.height % 1).to.equal(0); + done(); + }, + }); + }); + + it('should not exceed the natural width/height after rounded', (done) => { + const image = window.createImage(); + const cropper = new Cropper(image, { + viewMode: 1, + + ready() { + const imageData = cropper.getImageData(); + const left = 155.5; + const top = 155.5; + + cropper.setData({ + left, + top, + width: imageData.naturalWidth - left, + height: imageData.naturalHeight - top, + }); + + const roundedData = cropper.getData(true); + + expect(roundedData.x + roundedData.width).to.be.at.most(imageData.naturalWidth); + expect(roundedData.y + roundedData.height).to.be.at.most(imageData.naturalHeight); + done(); + }, + }); + }); +}); -- cgit v1.2.3