mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 23:36:41 +00:00
[Menu] Listen to element directly
Add listener to menu element directly instead of using ng-click to aid in testing (and for consistency with related listeners.) WTD-1506.
This commit is contained in:
parent
87aa0cfce2
commit
2d5ec97dc3
@ -31,7 +31,6 @@ define(
|
||||
|
||||
var MENU_TEMPLATE = "<mct-representation key=\"'context-menu'\" " +
|
||||
"mct-object=\"domainObject\" " +
|
||||
"ng-click=\"dismiss()\" " +
|
||||
"ng-class=\"menuClass\" " +
|
||||
"ng-style=\"menuStyle\">" +
|
||||
"</mct-representation>",
|
||||
@ -87,7 +86,6 @@ define(
|
||||
"go-up": goUp,
|
||||
"context-menu-holder": true
|
||||
};
|
||||
scope.dismiss = dismiss;
|
||||
|
||||
// Create the context menu
|
||||
menu = $compile(MENU_TEMPLATE)(scope);
|
||||
@ -103,6 +101,7 @@ define(
|
||||
// Dismiss the menu when body is clicked elsewhere
|
||||
// ('mousedown' because 'click' breaks left-click context menus)
|
||||
body.on('mousedown', dismiss);
|
||||
menu.on('click', dismiss);
|
||||
|
||||
// Don't launch browser's context menu
|
||||
actionContext.event.preventDefault();
|
||||
|
@ -69,7 +69,7 @@ define(
|
||||
mockCompiledTemplate.andReturn(mockMenu);
|
||||
mockDocument.find.andReturn(mockBody);
|
||||
mockRootScope.$new.andReturn(mockScope);
|
||||
|
||||
|
||||
mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent};
|
||||
|
||||
action = new ContextMenuAction(
|
||||
@ -118,9 +118,9 @@ define(
|
||||
it("removes a menu when body is clicked", function () {
|
||||
// Show the menu
|
||||
action.perform();
|
||||
|
||||
|
||||
// Verify precondition
|
||||
expect(mockBody.off).not.toHaveBeenCalled();
|
||||
expect(mockBody.remove).not.toHaveBeenCalled();
|
||||
|
||||
// Find and fire body's mousedown listener
|
||||
mockBody.on.calls.forEach(function (call) {
|
||||
@ -133,8 +133,29 @@ define(
|
||||
expect(mockMenu.remove).toHaveBeenCalled();
|
||||
|
||||
// Listener should have been detached from body
|
||||
expect(mockBody.off).toHaveBeenCalled();
|
||||
expect(mockBody.off).toHaveBeenCalledWith(
|
||||
'mousedown',
|
||||
jasmine.any(Function)
|
||||
);
|
||||
});
|
||||
|
||||
it("removes a menu when it is clicked", function () {
|
||||
// Show the menu
|
||||
action.perform();
|
||||
|
||||
// Verify precondition
|
||||
expect(mockMenu.remove).not.toHaveBeenCalled();
|
||||
|
||||
// Find and fire body's mousedown listener
|
||||
mockMenu.on.calls.forEach(function (call) {
|
||||
if (call.args[0] === 'click') {
|
||||
call.args[1]();
|
||||
}
|
||||
});
|
||||
|
||||
// Menu should have been removed
|
||||
expect(mockMenu.remove).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user