aboutsummaryrefslogtreecommitdiffstats
path: root/library/cropperjs/test/specs/options/preview.spec.js
blob: 2d2bc34d4f0a3f3920bb008a3c81cca171a1cc24 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
describe('preview (option)', () => {
  it('should be an empty string be default', () => {
    const image = window.createImage();
    const cropper = new Cropper(image);

    expect(cropper.options.preview).to.be.a('string').that.is.empty;
  });

  it('should support element', (done) => {
    const image = window.createImage();
    const preview = document.createElement('div');

    image.ownerDocument.body.appendChild(preview);

    const cropper = new Cropper(image, {
      preview,

      ready() {
        expect(preview.firstElementChild).to.not.be.null;
        expect(preview.firstElementChild.src).to.equal(image.src);
        done();
      },
    });

    expect(cropper.options.preview).to.equal(preview);
  });

  it('should support array of elements', (done) => {
    const image = window.createImage();
    const previews = document.createElement('ul');
    const preview1 = document.createElement('li');
    const preview2 = document.createElement('li');
    const preview = [preview1, preview2];

    previews.appendChild(preview1);
    previews.appendChild(preview2);
    image.ownerDocument.body.appendChild(previews);

    const cropper = new Cropper(image, {
      preview,

      ready() {
        expect(preview1.firstElementChild).to.not.be.null;
        expect(preview2.firstElementChild).to.not.be.null;
        expect(preview1.firstElementChild.src).to.equal(image.src);
        expect(preview2.firstElementChild.src).to.equal(image.src);
        done();
      },
    });

    expect(cropper.options.preview).to.equal(preview);
  });

  it('should support `NodeList` object', (done) => {
    const image = window.createImage();
    const previews = document.createElement('ul');
    const preview1 = document.createElement('li');
    const preview2 = document.createElement('li');

    previews.appendChild(preview1);
    previews.appendChild(preview2);
    image.ownerDocument.body.appendChild(previews);

    const cropper = new Cropper(image, {
      preview: previews.children,

      ready() {
        expect(preview1.firstElementChild).to.not.be.null;
        expect(preview2.firstElementChild).to.not.be.null;
        expect(preview1.firstElementChild.src).to.equal(image.src);
        expect(preview2.firstElementChild.src).to.equal(image.src);
        done();
      },
    });

    expect(cropper.options.preview).to.equal(previews.children);
  });

  it('should support selector', (done) => {
    const image = window.createImage();
    const previews = document.createElement('ul');
    const preview1 = document.createElement('li');
    const preview2 = document.createElement('li');

    preview1.className = 'preview';
    preview2.className = 'preview';
    previews.appendChild(preview1);
    previews.appendChild(preview2);
    image.ownerDocument.body.appendChild(previews);

    const cropper = new Cropper(image, {
      preview: '.preview',

      ready() {
        expect(preview1.firstElementChild).to.not.be.null;
        expect(preview2.firstElementChild).to.not.be.null;
        expect(preview1.firstElementChild.src).to.equal(image.src);
        expect(preview2.firstElementChild.src).to.equal(image.src);
        done();
      },
    });

    expect(cropper.options.preview).to.equal('.preview');
  });
});