aboutsummaryrefslogtreecommitdiffstats
path: root/library/cropperjs/test/specs/options/restore.spec.js
blob: 3a011edc8b6516d573040f164f0205744c21533e (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
describe('restore (option)', () => {
  it('should restore the cropped area after resize the window be default', (done) => {
    const image = window.createImage();
    const cropper = new Cropper(image, {
      ready() {
        const data = cropper.zoomTo(1).getData(true);
        const containerData = cropper.getContainerData();

        image.parentElement.style.width = `${containerData.width - 10}px`;
        image.parentElement.style.height = `${containerData.height - 10}px`;
        window.dispatchEvent(window.createEvent('resize'));
        expect(cropper.getData(true)).to.deep.equal(data);
        done();
      },
    });

    expect(cropper.options.restore).to.be.true;
  });

  it('should not be restore', (done) => {
    const image = window.createImage();
    const cropper = new Cropper(image, {
      restore: false,

      ready() {
        const data = cropper.zoomTo(1).getData(true);
        const containerData = cropper.getContainerData();

        image.parentElement.style.width = `${containerData.width / 2}px`;
        window.dispatchEvent(window.createEvent('resize'));
        expect(cropper.getData(true)).to.not.deep.equal(data);
        done();
      },
    });

    expect(cropper.options.restore).to.be.false;
  });
});