[Gestures] Tests

MCTPinch tests nearly complete.
Does not check scope destroy, however does
run through the touch firings.
This commit is contained in:
Shivam Dave 2015-09-04 14:53:14 -07:00
parent 820960f879
commit 8101fd7a20
2 changed files with 60 additions and 3 deletions

View File

@ -22,15 +22,71 @@
/*global define,Promise,describe,it,expect,xit,beforeEach,waitsFor,jasmine*/
define(
["../src/directives/MCTPinch"],
["../../src/directives/MCTPinch"],
function (MCTPinch) {
"use strict";
describe("The MCT Pinch directive", function () {
var mockScope;
var mockScope,
mockElement,
mockAgentService,
mctPinch,
mockEvent,
mockTouches,
mockChangedTouches,
mockTarget,
mockTouchEvent;
beforeEach(function () {
mockScope = jasmine.createSpyObj("$scope", [ "$emit", "$on" ]);
mockElement = jasmine.createSpyObj("element", [ "on", "off" ]);
mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
mockEvent = jasmine.createSpyObj("event", [ "touches", "changedTouches", "preventDefault", "target" ]);
mockTouchEvent = jasmine.createSpyObj("event",
[ "clientX", "clientY" ]);
mockTarget = jasmine.createSpyObj("event.target", ["getBoundingClientRect"])
mockAgentService.isMobile.andReturn(true);
mctPinch = new MCTPinch(mockAgentService);
mctPinch.link(mockScope, mockElement);
mockTouches = [mockTouchEvent];
mockChangedTouches = [mockTouchEvent];
mockEvent.touches = mockTouches;
mockEvent.changedTouches = mockChangedTouches;
mockEvent.target = mockTarget;
});
it("Start touch", function() {
// Touch Start
mockElement.on.calls[0].args[1](mockEvent);
// Touch Move
mockElement.on.calls[1].args[1](mockEvent);
// Touch End
mockElement.on.calls[2].args[1](mockEvent);
// Touch Cancel
mockElement.on.calls[3].args[1](mockEvent);
mockTouches = [mockTouchEvent, mockTouchEvent];
mockChangedTouches = [mockTouchEvent, mockTouchEvent];
mockEvent.touches = mockTouches;
mockEvent.changedTouches = mockChangedTouches;
mockEvent.target = mockTarget;
// Touch Start
mockElement.on.calls[0].args[1](mockEvent);
// Touch Move
mockElement.on.calls[1].args[1](mockEvent);
// Touch End
mockElement.on.calls[2].args[1](mockEvent);
// Touch Cancel
mockElement.on.calls[3].args[1](mockEvent);
//console.log(mockScope.on.calls);
});
});
}

View File

@ -1,6 +1,7 @@
[
"controllers/PlotController",
"directives/MCTChart",
"directives/MCTPlot"
"directives/MCTPlot",
"directives/MCTPinch"
]