Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Commit

Permalink
test(dragSelect): add tests for the dragSelect directive
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Lewis committed May 12, 2016
1 parent 4354a52 commit b9918cb
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions test/unit/directives/mwlDragSelect.spec.js
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;
});

});

});

0 comments on commit b9918cb

Please sign in to comment.