This repository has been archived by the owner on Jun 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(dragSelect): add tests for the dragSelect directive
- Loading branch information
Matt Lewis
committed
May 12, 2016
1 parent
4354a52
commit b9918cb
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
'use strict'; | ||
|
||
var angular = require('angular'); | ||
|
||
describe('mwlDragSelect directive', function() { | ||
|
||
beforeEach(angular.mock.module('mwl.calendar')); | ||
|
||
var elm, scope; | ||
beforeEach(angular.mock.inject(function($compile, $rootScope, $document) { | ||
scope = $rootScope.$new(); | ||
scope.onStart = sinon.spy(); | ||
scope.onMove = sinon.spy(); | ||
scope.onEnd = sinon.spy(); | ||
elm = $compile( | ||
'<div mwl-drag-select="isEnabled" on-drag-select-start="onStart()" ' + | ||
'on-drag-select-move="onMove()" on-drag-select-end="onEnd()"></div>' | ||
)(scope); | ||
$document.find('body').append(elm); | ||
scope.$apply(); | ||
})); | ||
|
||
afterEach(function() { | ||
scope.$destroy(); | ||
elm.remove(); | ||
}); | ||
|
||
function triggerEvent(type) { | ||
/* global document */ | ||
var event = document.createEvent('Event'); | ||
event.initEvent(type, true, true); | ||
elm[0].dispatchEvent(event); | ||
} | ||
|
||
describe('isEnabled = true', function() { | ||
|
||
beforeEach(function() { | ||
scope.isEnabled = true; | ||
scope.$apply(); | ||
}); | ||
|
||
it('should call the mousedown callback when the drag select', function() { | ||
triggerEvent('mousedown'); | ||
expect(scope.onStart).to.have.been.calledOnce; | ||
}); | ||
|
||
it('should call the mousemove callback when the drag select', function() { | ||
triggerEvent('mousemove'); | ||
expect(scope.onMove).to.have.been.calledOnce; | ||
}); | ||
|
||
it('should call the mouseup callback when the drag select', function() { | ||
triggerEvent('mouseup'); | ||
expect(scope.onEnd).to.have.been.calledOnce; | ||
}); | ||
|
||
}); | ||
|
||
describe('isEnabled = false', function() { | ||
|
||
beforeEach(function() { | ||
scope.isEnabled = false; | ||
scope.$apply(); | ||
}); | ||
|
||
it('should not call the mousedown callback when the drag select', function() { | ||
triggerEvent('mousedown'); | ||
expect(scope.onStart).not.to.have.been.called; | ||
}); | ||
|
||
it('should not call the mousemove callback when the drag select', function() { | ||
triggerEvent('mousemove'); | ||
expect(scope.onMove).not.to.have.been.called; | ||
}); | ||
|
||
it('should not call the mouseup callback when the drag select', function() { | ||
triggerEvent('mouseup'); | ||
expect(scope.onEnd).not.to.have.been.called; | ||
}); | ||
|
||
}); | ||
|
||
}); |