Example #1
0
 it('should not remove the element when false provided', () => {
   CropElement.prototype.destroy.call(_this, false)
   assert(mousedownStub.called, 'mousedown disposable wasnt called')
   assert(mouseupStub.called, 'mouseup disposable wasnt called')
   assert(mousemoveStub.called, 'mousemove disposable wasnt called')
   assert.equal(_this.element.getAttribute('unselectable'), null)
   assert.equal(removeChildStub.callCount, 0, 'element was removed from dom')
 })
Example #2
0
 it('should call start and size on all the things', () => {
   TinyCrop.prototype.startDrag.call(_this, 'anchor')
   assert(_this.start.called, 'start was not called')
   assert(_this._image.drag.called, 'image size not called')
   assert(_this._cropper.drag.called, 'cropper size not called')
   assert(_this._handles[0].drag.called, 'handle size not called')
   assert.equal(_this._image.drag.firstCall.args[0], 'anchor', 'image size not called')
   assert.equal(_this._cropper.drag.firstCall.args[0], 'anchor', 'cropper size not called')
   assert.equal(_this._handles[0].drag.firstCall.args[0], 'anchor', 'handle size not called')
 })
Example #3
0
 it('should call initialize, retrieve bounds and call startSize', () => {
   const img = document.createElement('img')
   _this._image.bounds.returns({})
   TinyCrop.prototype.initialize.call(_this, img)
   assert.equal(_this._image.initialize.callCount, 1, 'image#initialize not called')
   assert.equal(_this._cropper.initialize.callCount, 1, 'cropper#initialize not called')
   assert.equal(_this._handles[0].initialize.callCount, 1, 'handle[0]#initialize not called')
   object(_this._bounds).is({})
   assert.equal(_this._image.startSize.callCount, 1, 'startSize was not called')
 })
Example #4
0
 it('should initialize properly', () => {
   CropElement.prototype.initialize.call(_this, el)
   object(_this.element).is(el)
   assert.equal(_this.element.getAttribute('unselectable'), 'on', 'unselectable wasnt set')
   object(_this._events.dragStart).is({})
   assert(preventDefaultStub.calledOnce, 'prevent default wasnt called')
 })
Example #5
0
 it('should register the event properly', () => {
   _this.off = sinon.stub()
   const stub = sinon.stub()
   const disposable = TinyCrop.prototype.on.call(_this, 'done', stub)
   array(_this._events.done).is([stub])
   disposable()
   assert.equal(_this.off.callCount, 1)
 })
Example #6
0
 it('should remove the element when no parameter provided', () => {
   CropElement.prototype.destroy.call(_this)
   assert(mousedownStub.called, 'mousedown disposable wasnt called')
   assert(mouseupStub.called, 'mouseup disposable wasnt called')
   assert(mousemoveStub.called, 'mousemove disposable wasnt called')
   assert.equal(_this.element.getAttribute('unselectable'), null)
   assert(removeChildStub.calledOnce, 'element was not removed from dom')
 })
Example #7
0
 it('should call cropper.start and attach document mouseup handler', () => {
   attachStub.returns({})
   attachStub.callsArgWith(2, {clientX: 1, clientY: 1})
   TinyCrop.prototype.start.call(_this)
   object(attachStub.firstCall.args[0]).is(document)
   assert.equal(attachStub.firstCall.args[1], 'mouseup')
   assert(_this._cropper.start.called, 'start was not called')
   assert(_this.finish.called, 'finish was not called')
   object(_this._docMouseUp).is({})
 })
Example #8
0
 it('should remove docMouseUp if present - and the rest', () => {
   const docMouseUpStub = sinon.stub()
   _this._docMouseUp = docMouseUpStub
   TinyCrop.prototype.destroy.call(_this)
   assert(docMouseUpStub.called, 'docMouseUp wasnt called')
   assert.equal(_this.docMouseUp, null, 'docMouseUp wasnt nulled')
   object(_this._events.done).is([])
   assert(_this._image.destroy.called, 'image destroy was not called')
   assert(_this._cropper.destroy.called, 'cropper destroy was not called')
   assert(_this._handles[0].destroy.called, 'handle destroy was not called')
 })
Example #9
0
 it('should initialize properly with no parameters', () => {
   const tc = new TinyCrop()
   object(tc._cropDimensions).is({})
   assert.equal(tc.minWidth, 0)
   assert.equal(tc.maxWidth, Infinity)
   assert.equal(tc.minHeight, 0)
   assert.equal(tc.maxHeight, Infinity)
   object(tc._events).is({done: []})
   assert.equal(appendHeadStub.callCount, 1, 'style was not appended')
   assert.equal(cropperStub.callCount, 1, 'cropper was not called once')
   assert.equal(handleStub.callCount, 8, 'cropper was not called')
   assert.equal(imageStub.callCount, 1, 'image stub wasnt called once')
 })
Example #10
0
 it('should be ok if docMouseUp isnt there - and do the rest', () => {
   TinyCrop.prototype.finish.call(_this)
   assert.equal(_this._docMouseUp, null, '_docMouseUp is not null')
   assert(_this._cropper.element.classList.contains('finished'), 'cropper class list doesnt contain finished')
   assert(_this._handles[0].startSize.called, 'handle start size wasnt called')
   assert(_this._handles[0].finish.called, 'handle finish wasnt called')
   assert(_this._cropper.finish.called, 'cropper finish wasnt called')
   assert(_this._cropper.startDrag.called, 'cropper startDrag wasnt called')
   assert(_this._image.finish.called, 'image finish wasnt called')
   assert(_this._image.startSize.called, 'image startSize wasnt called')
   assert(_this._events.done[0].called, 'done event wasnt called')
 })
Example #11
0
 it('should reset cropDimensions and call startSize with anchor', () => {
   TinyCrop.prototype.restart.call(_this, 'anchor')
   object(_this._cropDimensions).is({
     height: 0,
     width: 0,
     bottom: null,
     right: null,
     left: null,
     top: null
   })
   assert(_this.startSize.called, 'startSize wasnt called')
   assert.equal(_this.startSize.firstCall.args[0], 'anchor', 'first argument wasnt right')
 })
Example #12
0
 it('should set dimensions properly - without TRBL', () => {
   Cropper.prototype.update.call(_this, {height: 100, width: 100, top: 10, right: 10, bottom: 10, left: 10})
   assert.equal(_this.element.style.width, '100px')
   assert.equal(_this.element.style.height, '100px')
   assert.equal(_this.element.style.top, '10px')
   assert.equal(_this.element.style.right, '10px')
   assert.equal(_this.element.style.bottom, '10px')
   assert.equal(_this.element.style.left, '10px')
 })
Example #13
0
 it('should remove docMouseUp if attached - and do the rest', () => {
   const docMouseUpStub = sinon.stub()
   _this._docMouseUp = docMouseUpStub
   TinyCrop.prototype.finish.call(_this)
   assert(docMouseUpStub.called, 'mouseup disposable wasnt called')
   assert.equal(_this._docMouseUp, null, '_docMouseUp is not null')
   assert(_this._cropper.element.classList.contains('finished'), 'cropper class list doesnt contain finished')
   assert(_this._handles[0].startSize.called, 'handle start size wasnt called')
   assert(_this._handles[0].finish.called, 'handle finish wasnt called')
   assert(_this._cropper.finish.called, 'cropper finish wasnt called')
   assert(_this._cropper.startDrag.called, 'cropper startDrag wasnt called')
   assert(_this._image.finish.called, 'image finish wasnt called')
   assert(_this._image.startSize.called, 'image startSize wasnt called')
   assert(_this._events.done[0].called, 'done event wasnt called')
 })
Example #14
0
 it('should set all options properly', () => {
   const img = document.createElement('img')
   const tc = new TinyCrop({
     minHeight: 10,
     maxHeight: 20,
     minWidth: 30,
     maxWidth: 40,
     image: img
   })
   object(tc._cropDimensions).is({})
   assert.equal(tc.minHeight, 10)
   assert.equal(tc.maxHeight, 20)
   assert.equal(tc.minWidth, 30)
   assert.equal(tc.maxWidth, 40)
   assert.equal(appendHeadStub.callCount, 1, 'style was not appended')
   assert.equal(cropperStub.callCount, 1, 'cropper was not called once')
   assert.equal(handleStub.callCount, 8, 'cropper was not called')
   assert.equal(imageStub.callCount, 1, 'image stub wasnt called once')
   object(getImageStub.firstCall.args[0]).is(img)
 })
Example #15
0
 it('should set dimensions properly - with TRBL', () => {
   Cropper.prototype.update.call(_this, {height: 100, width: 100})
   assert.equal(_this.element.style.width, '100px')
   assert.equal(_this.element.style.height, '100px')
 })
Example #16
0
 it('should only append css once', () => {
   getElementByIdStub.withArgs('tiny-crop-css').returns({})
   new TinyCrop()
   assert.equal(appendHeadStub.callCount, 0, 'style was appended')
 })
Example #17
0
 it('should throw if provided function isnt a known event handler', () => {
   assert.throws(() => { TinyCrop.prototype.off.call(_this, 'done', sinon.stub()) }, /invalid parameters provided to tinycrop/gi)
 })
Example #18
0
 it('should throw for non-function fn parameter', () => {
   assert.throws(() => { TinyCrop.prototype.off.call(_this, 'done', 'invalid') }, /invalid parameters provided to tinycrop/gi)
 })
Example #19
0
 it('should throw if eventName not a string', () => {
   assert.throws(() => { TinyCrop.prototype.off.call(_this) }, /invalid parameters provided to tinycrop/gi)
 })
Example #20
0
 it('should throw for invalid eventName', () => {
   assert.throws(() => { TinyCrop.prototype.off.call(_this, 'invalid') }, /invalid parameters provided to tinycrop/gi)
 })
Example #21
0
 it('#on should throw if fn is not a function', () => {
   assert.throws(() => { TinyCrop.prototype.on.call(_this, 'done') }, /invalid parameters provided to tinycrop/gi)
 })
Example #22
0
 it('should set up the image element properly', () => {
   CropImage.prototype.destroy.call(_this)
   assert.equal(CropElement.prototype.destroy.callCount, 1)
   assert.equal(CropElement.prototype.destroy.firstCall.args[0], false)
   assert(!_this.element.classList.contains('crop-target'), 'class not set properly')
 })