aboutsummaryrefslogtreecommitdiffstats
path: root/library/cropperjs/test/options/viewMode.js
blob: e39ec5fc1545d0d9c1eb4b51967f3cd5770c0c4f (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
QUnit.test('options#viewMode: 0', function (assert) {
  var done = assert.async();
  var util = window.Util;
  var image = util.createImage();

  assert.expect(4);

  return new Cropper(image, {
    // viewMode: 0,

    ready: function () {
      var cropper = this.cropper;
      var canvasData = {
            left: 100,
            top: 100,
            width: 160,
            height: 90
          };
      var changedCanvasData = cropper.setCanvasData(canvasData).getCanvasData();

      assert.strictEqual(changedCanvasData.left, canvasData.left);
      assert.strictEqual(changedCanvasData.top, canvasData.top);
      assert.strictEqual(changedCanvasData.width, canvasData.width);
      assert.strictEqual(changedCanvasData.height, canvasData.height);

      done();
    }
  });
});

QUnit.test('options#viewMode: 1', function (assert) {
  var done = assert.async();
  var util = window.Util;
  var image = util.createImage();

  assert.expect(2);

  return new Cropper(image, {
    viewMode: 1,

    ready: function () {
      var cropper = this.cropper;
      var canvasData = cropper.zoom(-0.5).getCanvasData(); // Zoom out
      var cropBoxData = cropper.getCropBoxData();

      assert.ok(canvasData.width >= cropBoxData.width);
      assert.ok(canvasData.height >= cropBoxData.height);

      done();
    }
  });
});

QUnit.test('options#viewMode: 2', function (assert) {
  var done = assert.async();
  var util = window.Util;
  var image = util.createImage();

  assert.expect(1);

  return new Cropper(image, {
    viewMode: 2,

    ready: function () {
      var cropper = this.cropper;
      var canvasData = cropper.zoom(-0.5).getCanvasData(); // Zoom out
      var containerData = cropper.getContainerData();

      assert.ok(canvasData.width >= containerData.width ||
        canvasData.height >= containerData.height);

      done();
    }
  });
});

QUnit.test('options#viewMode: 3', function (assert) {
  var done = assert.async();
  var util = window.Util;
  var image = util.createImage();

  assert.expect(4);

  return new Cropper(image, {
    viewMode: 3,

    ready: function () {
      var cropper = this.cropper;
      var canvasData = cropper.zoom(-0.5).getCanvasData(); // Zoom out
      var containerData = cropper.getContainerData();

      assert.ok(canvasData.left <= 0);
      assert.ok(canvasData.top <= 0);
      assert.ok(canvasData.width >= containerData.width);
      assert.ok(canvasData.height >= containerData.height);

      done();
    }
  });
});