aboutsummaryrefslogtreecommitdiffstats
path: root/library/cropperjs/test/specs/methods/crop.spec.js
blob: b760e759240770c328b2f9bec0be53b34f7ea7e6 (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
47
48
49
50
describe('crop (method)', () => {
  it('should match the expected behaviors by default', (done) => {
    const image = window.createImage();
    const cropper = new Cropper(image, {
      autoCrop: false,

      ready() {
        expect(cropper.cropped).to.be.false;
        expect(window.getComputedStyle(cropper.cropBox).display).to.equal('none');
        cropper.crop();
        expect(cropper.cropped).to.be.true;
        expect(window.getComputedStyle(cropper.cropBox).display).to.not.equal('none');
        done();
      },
    });
  });

  it('should trigger the `crop` event', (done) => {
    const image = window.createImage();

    image.addEventListener('crop', () => {
      done();
    });

    const cropper = new Cropper(image, {
      autoCrop: false,

      ready() {
        cropper.crop();
      },
    });
  });

  it('should not crop again when it is already cropped', (done) => {
    const image = window.createImage();
    let count = 0;
    const cropper = new Cropper(image, {
      crop() {
        count += 1;

        if (count > 1) {
          expect.fail(1, 0);
        } else {
          cropper.crop();
          done();
        }
      },
    });
  });
});