aboutsummaryrefslogtreecommitdiffstats
path: root/library/cropperjs/test/specs/options/zoom.spec.js
blob: 3d11f3a2fd47f12905366388dc1a7ccdcc310200 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
describe('zoom (option)', () => {
  it('should be `null` be default', () => {
    const image = window.createImage();
    const cropper = new Cropper(image);

    expect(cropper.options.zoom).to.be.null;
  });

  it('should execute the `zoom` hook function', (done) => {
    const image = window.createImage();
    const cropper = new Cropper(image, {
      ready() {
        cropper.zoom(0.1);
      },

      zoom(event) {
        expect(event.type).to.equal('zoom');
        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();
      },
    });

    expect(cropper.options.zoom).to.be.a('function');
  });

  it('should not change the canvas sizes when default prevented', (done) => {
    const image = window.createImage();
    const cropper = new Cropper(image, {
      ready() {
        const canvasData = cropper.getCanvasData();

        expect(cropper.zoom(0.1).getCanvasData()).to.deep.equal(canvasData);
        done();
      },

      zoom(event) {
        event.preventDefault();
      },
    });
  });
});