index.test.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. var _utils = require("../utils");
  3. var _ = require(".");
  4. describe('image func test', function () {
  5. var domain = 'http://otxza7yo2.bkt.clouddn.com';
  6. var key = 'test.png';
  7. test('imageView2', function () {
  8. var m = {
  9. fop: 'imageView2',
  10. mode: 2,
  11. h: 450,
  12. q: 100
  13. };
  14. var url = (0, _.imageView2)(m, key, domain);
  15. expect(url).toBe('http://otxza7yo2.bkt.clouddn.com/' + key + '?' + 'imageView2/' + encodeURIComponent(m.mode) + '/h' + '/' + encodeURIComponent(m.h) + '/q' + '/' + encodeURIComponent(m.q));
  16. });
  17. test('imageMogr2', function () {
  18. var m = {
  19. thumbnail: 1,
  20. strip: true,
  21. gravity: 1,
  22. crop: 1,
  23. quality: 1,
  24. rotate: 1,
  25. format: 1,
  26. blur: 1
  27. };
  28. var url = (0, _.imageMogr2)(m, key, domain);
  29. expect(url).toBe('http://otxza7yo2.bkt.clouddn.com/' + key + '?imageMogr2/' + 'thumbnail/1/strip/gravity/1/quality/1/crop/1/rotate/1/format/1/blur/1');
  30. });
  31. test('watermark', function () {
  32. var m = {
  33. fop: 'watermark',
  34. mode: 1,
  35. image: 'http://www.b1.qiniudn.com/images/logo-2.png',
  36. dissolve: 100,
  37. dx: 100,
  38. dy: 100
  39. };
  40. var url = (0, _.watermark)(m, key, domain);
  41. expect(url).toBe('http://otxza7yo2.bkt.clouddn.com/' + key + '?' + 'watermark/' + m.mode + '/image/' + (0, _utils.urlSafeBase64Encode)(m.image) + '/dissolve/100/dx/100/dy/100');
  42. m.mode = 3;
  43. expect(function () {
  44. (0, _.watermark)(m, key, domain);
  45. }).toThrow('mode is wrong');
  46. });
  47. });