Skip to content

Commit

Permalink
test: key binding manager tests for browserOnly and nativeOnly key bi…
Browse files Browse the repository at this point in the history
…ndings
  • Loading branch information
abose committed Jan 17, 2025
1 parent bc8f3ea commit 1aaecf0
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/spec/KeyBindingManager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,58 @@ define(function (require, exports, module) {

expect(KeyBindingManager.getKeymap()).toEqual(expected);
});

it("should handle browserOnly and nativeOnly bindings correctly", function () {
// Test browser-only bindings
let result = KeyBindingManager.addBinding("test.browser", {
key: "F6",
browserOnly: true
});
let keymap = KeyBindingManager.getKeymap();
if(Phoenix.isNativeApp) {
expect(result).toBeNull();
expect(keymap["F6"]).not.toBeDefined();
} else {
expect(result.key).toBe("F6");
expect(keymap["F6"].key).toBe("F6");
}
// Test native-only bindings
result = KeyBindingManager.addBinding("test.native", {
key: "F7",
nativeOnly: true
});
keymap = KeyBindingManager.getKeymap();
if(!Phoenix.isNativeApp) {
expect(result).toBeNull();
expect(keymap["F7"]).not.toBeDefined();
} else {
expect(result.key).toBe("F7");
expect(keymap["F7"].key).toBe("F7");
}
});

it("should handle browserOnly and nativeOnly in multiple bindings", function () {
// Test browser-only bindings
let result = KeyBindingManager.addBinding("test.allPlats", [
{key: "F6", browserOnly: true},
{key: "F7", nativeOnly: true}
]);
let keymap = KeyBindingManager.getKeymap();
expect(result.length).toBe(1);
if (Phoenix.isNativeApp) {
// Native app environment
expect(result[0].key).toBe("F7"); // Only native binding should be added
expect(keymap["F7"]).toBeDefined();
expect(keymap["F7"].key).toBe("F7");
expect(keymap["F6"]).not.toBeDefined(); // Browser-only should not be defined
} else {
// Browser environment
expect(result[0].key).toBe("F6"); // Only browser binding should be added
expect(keymap["F6"]).toBeDefined();
expect(keymap["F6"].key).toBe("F6");
expect(keymap["F7"]).not.toBeDefined(); // Native-only should not be defined
}
});
});

describe("removeBinding", function () {
Expand Down

0 comments on commit 1aaecf0

Please sign in to comment.