mirror of
https://github.com/nasa/openmct.git
synced 2025-06-05 17:01:41 +00:00
[Context Menu] Update specs
Update specs to reflect refactoring-out of popup elements performed in the context of adding time conductor, WTD-1515.
This commit is contained in:
parent
fd927d4c03
commit
13095b4135
@ -84,8 +84,10 @@ define(
|
|||||||
|
|
||||||
// Remove the context menu
|
// Remove the context menu
|
||||||
function dismiss() {
|
function dismiss() {
|
||||||
popup.dismiss();
|
if (popup) {
|
||||||
popup = undefined;
|
popup.dismiss();
|
||||||
|
popup = undefined;
|
||||||
|
}
|
||||||
scope.$destroy();
|
scope.$destroy();
|
||||||
body.off("mousedown", dismiss);
|
body.off("mousedown", dismiss);
|
||||||
dismissExistingMenu = undefined;
|
dismissExistingMenu = undefined;
|
||||||
|
@ -41,13 +41,14 @@ define(
|
|||||||
mockMenu,
|
mockMenu,
|
||||||
mockDocument,
|
mockDocument,
|
||||||
mockBody,
|
mockBody,
|
||||||
mockWindow,
|
mockPopupService,
|
||||||
mockRootScope,
|
mockRootScope,
|
||||||
mockAgentService,
|
mockAgentService,
|
||||||
mockScope,
|
mockScope,
|
||||||
mockElement,
|
mockElement,
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
mockEvent,
|
mockEvent,
|
||||||
|
mockPopup,
|
||||||
mockActionContext,
|
mockActionContext,
|
||||||
action;
|
action;
|
||||||
|
|
||||||
@ -57,36 +58,47 @@ define(
|
|||||||
mockMenu = jasmine.createSpyObj("menu", JQLITE_FUNCTIONS);
|
mockMenu = jasmine.createSpyObj("menu", JQLITE_FUNCTIONS);
|
||||||
mockDocument = jasmine.createSpyObj("$document", JQLITE_FUNCTIONS);
|
mockDocument = jasmine.createSpyObj("$document", JQLITE_FUNCTIONS);
|
||||||
mockBody = jasmine.createSpyObj("body", JQLITE_FUNCTIONS);
|
mockBody = jasmine.createSpyObj("body", JQLITE_FUNCTIONS);
|
||||||
mockWindow = { innerWidth: MENU_DIMENSIONS[0] * 4, innerHeight: MENU_DIMENSIONS[1] * 4 };
|
mockPopupService =
|
||||||
|
jasmine.createSpyObj("popupService", ["display"]);
|
||||||
|
mockPopup = jasmine.createSpyObj("popup", [
|
||||||
|
"dismiss",
|
||||||
|
"goesLeft",
|
||||||
|
"goesUp"
|
||||||
|
]);
|
||||||
mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]);
|
mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]);
|
||||||
mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
|
mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
|
||||||
mockScope = {};
|
mockScope = jasmine.createSpyObj("scope", ["$destroy"]);
|
||||||
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
|
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
|
||||||
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
||||||
mockEvent = jasmine.createSpyObj("event", ["preventDefault", "stopPropagation"]);
|
mockEvent = jasmine.createSpyObj("event", ["preventDefault", "stopPropagation"]);
|
||||||
mockEvent.pageX = 0;
|
mockEvent.pageX = 123;
|
||||||
mockEvent.pageY = 0;
|
mockEvent.pageY = 321;
|
||||||
|
|
||||||
mockCompile.andReturn(mockCompiledTemplate);
|
mockCompile.andReturn(mockCompiledTemplate);
|
||||||
mockCompiledTemplate.andReturn(mockMenu);
|
mockCompiledTemplate.andReturn(mockMenu);
|
||||||
mockDocument.find.andReturn(mockBody);
|
mockDocument.find.andReturn(mockBody);
|
||||||
mockRootScope.$new.andReturn(mockScope);
|
mockRootScope.$new.andReturn(mockScope);
|
||||||
|
mockPopupService.display.andReturn(mockPopup);
|
||||||
|
|
||||||
mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent};
|
mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent};
|
||||||
|
|
||||||
action = new ContextMenuAction(
|
action = new ContextMenuAction(
|
||||||
mockCompile,
|
mockCompile,
|
||||||
mockDocument,
|
mockDocument,
|
||||||
mockWindow,
|
|
||||||
mockRootScope,
|
mockRootScope,
|
||||||
|
mockPopupService,
|
||||||
mockAgentService,
|
mockAgentService,
|
||||||
mockActionContext
|
mockActionContext
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(" adds a menu to the DOM when perform is called", function () {
|
it("displays a popup when performed", function () {
|
||||||
action.perform();
|
action.perform();
|
||||||
expect(mockBody.append).toHaveBeenCalledWith(mockMenu);
|
expect(mockPopupService.display).toHaveBeenCalledWith(
|
||||||
|
mockMenu,
|
||||||
|
[ mockEvent.pageX, mockEvent.pageY ],
|
||||||
|
jasmine.any(Object)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prevents the default context menu behavior", function () {
|
it("prevents the default context menu behavior", function () {
|
||||||
@ -94,29 +106,22 @@ define(
|
|||||||
expect(mockEvent.preventDefault).toHaveBeenCalled();
|
expect(mockEvent.preventDefault).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("positions menus where clicked", function () {
|
it("adds classes to menus based on position", function () {
|
||||||
mockEvent.pageX = 10;
|
var booleans = [ false, true ];
|
||||||
mockEvent.pageY = 5;
|
|
||||||
action.perform();
|
booleans.forEach(function (goLeft) {
|
||||||
expect(mockScope.menuStyle.left).toEqual("10px");
|
booleans.forEach(function (goUp) {
|
||||||
expect(mockScope.menuStyle.top).toEqual("5px");
|
mockPopup.goesLeft.andReturn(goLeft);
|
||||||
expect(mockScope.menuStyle.right).toBeUndefined();
|
mockPopup.goesUp.andReturn(goUp);
|
||||||
expect(mockScope.menuStyle.bottom).toBeUndefined();
|
action.perform();
|
||||||
expect(mockScope.menuClass['go-up']).toBeFalsy();
|
expect(!!mockScope.menuClass['go-up'])
|
||||||
expect(mockScope.menuClass['go-left']).toBeFalsy();
|
.toEqual(goUp);
|
||||||
|
expect(!!mockScope.menuClass['go-left'])
|
||||||
|
.toEqual(goLeft);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("repositions menus near the screen edge", function () {
|
|
||||||
mockEvent.pageX = mockWindow.innerWidth - 10;
|
|
||||||
mockEvent.pageY = mockWindow.innerHeight - 5;
|
|
||||||
action.perform();
|
|
||||||
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 () {
|
it("removes a menu when body is clicked", function () {
|
||||||
// Show the menu
|
// Show the menu
|
||||||
@ -133,7 +138,7 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Menu should have been removed
|
// Menu should have been removed
|
||||||
expect(mockMenu.remove).toHaveBeenCalled();
|
expect(mockPopup.dismiss).toHaveBeenCalled();
|
||||||
|
|
||||||
// Listener should have been detached from body
|
// Listener should have been detached from body
|
||||||
expect(mockBody.off).toHaveBeenCalledWith(
|
expect(mockBody.off).toHaveBeenCalledWith(
|
||||||
@ -149,7 +154,7 @@ define(
|
|||||||
// Verify precondition
|
// Verify precondition
|
||||||
expect(mockMenu.remove).not.toHaveBeenCalled();
|
expect(mockMenu.remove).not.toHaveBeenCalled();
|
||||||
|
|
||||||
// Find and fire body's mousedown listener
|
// Find and fire menu's click listener
|
||||||
mockMenu.on.calls.forEach(function (call) {
|
mockMenu.on.calls.forEach(function (call) {
|
||||||
if (call.args[0] === 'click') {
|
if (call.args[0] === 'click') {
|
||||||
call.args[1]();
|
call.args[1]();
|
||||||
@ -157,7 +162,7 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Menu should have been removed
|
// Menu should have been removed
|
||||||
expect(mockMenu.remove).toHaveBeenCalled();
|
expect(mockPopup.dismiss).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps a menu when menu is clicked", function () {
|
it("keeps a menu when menu is clicked", function () {
|
||||||
@ -171,7 +176,7 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Menu should have been removed
|
// Menu should have been removed
|
||||||
expect(mockMenu.remove).not.toHaveBeenCalled();
|
expect(mockPopup.dismiss).not.toHaveBeenCalled();
|
||||||
|
|
||||||
// Listener should have been detached from body
|
// Listener should have been detached from body
|
||||||
expect(mockBody.off).not.toHaveBeenCalled();
|
expect(mockBody.off).not.toHaveBeenCalled();
|
||||||
@ -182,8 +187,8 @@ define(
|
|||||||
action = new ContextMenuAction(
|
action = new ContextMenuAction(
|
||||||
mockCompile,
|
mockCompile,
|
||||||
mockDocument,
|
mockDocument,
|
||||||
mockWindow,
|
|
||||||
mockRootScope,
|
mockRootScope,
|
||||||
|
mockPopupService,
|
||||||
mockAgentService,
|
mockAgentService,
|
||||||
mockActionContext
|
mockActionContext
|
||||||
);
|
);
|
||||||
@ -194,6 +199,8 @@ define(
|
|||||||
call.args[1](mockEvent);
|
call.args[1](mockEvent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(mockPopup.dismiss).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user