@@ -26,8 +26,8 @@
|
||||
* Module defining ContextMenuGestureSpec. Created by vwoeltje on 11/22/14.
|
||||
*/
|
||||
define(
|
||||
["../../src/gestures/ContextMenuGesture", "../../src/gestures/GestureConstants"],
|
||||
function (ContextMenuGesture, GestureConstants) {
|
||||
["../../src/gestures/ContextMenuGesture"],
|
||||
function (ContextMenuGesture) {
|
||||
"use strict";
|
||||
|
||||
var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove" ],
|
||||
@@ -100,66 +100,9 @@ define(
|
||||
mockElement.on.mostRecentCall.args[1]
|
||||
);
|
||||
});
|
||||
|
||||
it("compiles and adds a menu to the DOM on a contextmenu event", function () {
|
||||
// Make sure that callback really is for the contextmenu event
|
||||
expect(mockElement.on.mostRecentCall.args[0]).toEqual("contextmenu");
|
||||
|
||||
fireGesture(mockEvent);
|
||||
|
||||
expect(mockBody.append).toHaveBeenCalledWith(mockMenu);
|
||||
});
|
||||
|
||||
it("prevents the default context menu behavior", function () {
|
||||
fireGesture(mockEvent);
|
||||
expect(mockEvent.preventDefault).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("positions menus where clicked", function () {
|
||||
mockEvent.pageX = 10;
|
||||
mockEvent.pageY = 5;
|
||||
fireGesture(mockEvent);
|
||||
expect(mockScope.menuStyle.left).toEqual("10px");
|
||||
expect(mockScope.menuStyle.top).toEqual("5px");
|
||||
expect(mockScope.menuStyle.right).toBeUndefined();
|
||||
expect(mockScope.menuStyle.bottom).toBeUndefined();
|
||||
expect(mockScope.menuClass['go-up']).toBeFalsy();
|
||||
expect(mockScope.menuClass['go-left']).toBeFalsy();
|
||||
});
|
||||
|
||||
it("repositions menus near the screen edge", function () {
|
||||
mockEvent.pageX = mockWindow.innerWidth - 10;
|
||||
mockEvent.pageY = mockWindow.innerHeight - 5;
|
||||
fireGesture(mockEvent);
|
||||
expect(mockScope.menuStyle.right).toEqual("10px");
|
||||
expect(mockScope.menuStyle.bottom).toEqual("5px");
|
||||
expect(mockScope.menuStyle.left).toBeUndefined();
|
||||
expect(mockScope.menuStyle.top).toBeUndefined();
|
||||
expect(mockScope.menuClass['go-up']).toBeTruthy();
|
||||
expect(mockScope.menuClass['go-left']).toBeTruthy();
|
||||
});
|
||||
|
||||
it("removes a menu when body is clicked", function () {
|
||||
// Show the menu
|
||||
fireGesture(mockEvent);
|
||||
|
||||
// Verify precondition
|
||||
expect(mockBody.off).not.toHaveBeenCalled();
|
||||
|
||||
// Find and fire body's click listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
if (call.args[0] === 'click') {
|
||||
call.args[1]();
|
||||
}
|
||||
});
|
||||
|
||||
// Menu should have been removed
|
||||
expect(mockMenu.remove).toHaveBeenCalled();
|
||||
|
||||
// Listener should have been detached from body
|
||||
expect(mockBody.off).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
////// Is this one here or in action spec? (shale)
|
||||
/*
|
||||
it("removes listeners from body if destroyed while menu is showing", function () {
|
||||
// Show the menu
|
||||
fireGesture(mockEvent);
|
||||
@@ -175,6 +118,7 @@ define(
|
||||
expect(mockBody.off).toHaveBeenCalled();
|
||||
expect(mockMenu.remove).toHaveBeenCalled();
|
||||
});
|
||||
*/
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user