Skip to content

Commit

Permalink
Fixing lint and test errors and a bug with removing callbacks from CO…
Browse files Browse the repository at this point in the history
…NTEXT_ALL
  • Loading branch information
Jeffrey Heifetz committed Sep 20, 2012
1 parent e863fd3 commit 13f65b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
7 changes: 2 additions & 5 deletions lib/ripple/platform/webworks.bb10/1.0.0/context-menu.js
Expand Up @@ -23,6 +23,7 @@ var _self,
_enabled = true,
_actions = require('./context-menu-actions'),
_customContextItems = {},
_storedCallbacks = {},
defaultContextMenuItems = {
"IMAGE_LINK": ['Open', 'CopyLink', 'CopyImageLink', 'Cancel'],
"IMAGE": ['CopyImageLink', 'SaveImage'],
Expand Down Expand Up @@ -122,10 +123,6 @@ function generateMenuItems(menuItems) {
return items;
}

function safeEval(jsonString) {
return JSON.parse('{"obj":' + jsonString + '}').obj;
}

function addItem(fail, args) {
var contexts = args.contexts,
action = args.action,
Expand Down Expand Up @@ -170,6 +167,7 @@ function removeItem(success, fail, args) {
for (context in contexts) {
if (contexts[context] === CONTEXT_ALL) {
removeItemFromAllContexts(actionId);
delete _storedCallbacks[actionId];
} else {
if (_customContextItems[contexts[context]]) {
delete _customContextItems[contexts[context]][actionId];
Expand All @@ -178,7 +176,6 @@ function removeItem(success, fail, args) {
}
}
_actions.removeCustomItem(actionId);
success();
}

function addCustomItemsForContext(items, context) {
Expand Down
17 changes: 12 additions & 5 deletions test/unit/webworks.bb10/context-menu.js
Expand Up @@ -93,18 +93,14 @@ describe("context menu", function () {
expect(ui.showOverlay).toHaveBeenCalled();
});

it("receives LayoutChanged event", function () {
events.trigger('LayoutChanged', [], true);
expect(ui.showOverlay).toHaveBeenCalled();
});

it("can have custom items added and removed", function () {
contextMenu.addItem([contextMenu.CONTEXT_ALL], goodAction, customMenuCallback);
contextMenu.removeItem([contextMenu.CONTEXT_ALL], goodAction.actionId);
});

it("supports firing custom menu events", function () {
contextMenu.addItem([contextMenu.CONTEXT_ALL], goodAction, customMenuCallback);
expect(customMenuCallback).not.toHaveBeenCalled();
events.trigger('contextmenu.executeMenuAction', [goodAction.actionId], true);
expect(customMenuCallback).toHaveBeenCalled();

Expand Down Expand Up @@ -142,4 +138,15 @@ describe("context menu", function () {
events.trigger('contextmenu.executeMenuAction', [goodAction.actionId], true);
expect(customMenuCallback.callCount).toEqual(1);
});

it("doesn't invoke callback for a removed custom menu item", function () {
var goodAction = {actionId: "Action", label: "Reaction", icon: "inaction.png"};
contextMenu.addItem([contextMenu.CONTEXT_IMAGE_LINK], goodAction, customMenuCallback);
events.trigger('contextmenu.executeMenuAction', [goodAction.actionId], true);
expect(customMenuCallback).wasCalled();

contextMenu.removeItem([contextMenu.CONTEXT_IMAGE_LINK], goodAction.actionId);
events.trigger('contextmenu.executeMenuAction', [goodAction.actionId], true);
expect(customMenuCallback.callCount).toEqual(1);
});
});

0 comments on commit 13f65b2

Please sign in to comment.