setAspectRatio.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. $(function () {
  2. 'use strict';
  3. var $image = $(window.createCropperImage());
  4. $image.cropper({
  5. built: function () {
  6. var cropper = $image.data('cropper'),
  7. options = cropper.options;
  8. QUnit.test('methods.setAspectRatio', function (assert) {
  9. var ratios = [0, 1 / 2, 1, 'auto', true, null, { a:1 }, ['auto', 2, 3], [1, 2, 3]];
  10. $.each(ratios, function (i, ratio) {
  11. $image.cropper('setAspectRatio', ratio);
  12. switch (i) {
  13. case 0:
  14. assert.ok(isNaN(options.aspectRatio)); // 0 -> NaN
  15. break;
  16. case 1:
  17. assert.equal(options.aspectRatio, 1 / 2);
  18. break;
  19. case 2:
  20. assert.equal(options.aspectRatio, 1);
  21. break;
  22. case 3:
  23. case 4:
  24. case 5:
  25. case 6:
  26. case 7:
  27. assert.ok(isNaN(options.aspectRatio)); // String/Boolean/Object -> NaN
  28. break;
  29. case 8:
  30. assert.equal(options.aspectRatio, 1);
  31. break;
  32. }
  33. });
  34. });
  35. }
  36. });
  37. });