Skip to content

Commit 0a3c0e8

Browse files
authored
Feature/367/missing numpad key mappings (#368)
* (#367) Added mappings for missing numpad keys * (#367) Updated keyboard tests
1 parent 697ef1d commit 0a3c0e8

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

lib/provider/native/libnut-keyboard.class.spec.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ beforeEach(() => {
1010

1111
describe("libnut keyboard action", () => {
1212
describe("click", () => {
13-
it("should forward the keyTap call to libnut for a known key", () => {
13+
it("should forward the keyTap call to libnut for a known key", async () => {
1414
// GIVEN
1515
const SUT = new KeyboardAction();
1616

1717
// WHEN
18-
SUT.click(Key.A);
18+
await SUT.click(Key.A);
1919

2020
// THEN
2121
expect(libnut.keyTap).toBeCalledTimes(1);
@@ -31,29 +31,29 @@ describe("libnut keyboard action", () => {
3131
// WHEN
3232

3333
// THEN
34-
expect(SUT.click(Key.A)).rejects.toThrowError("Test error");
34+
await expect(SUT.click(Key.A)).rejects.toThrowError("Test error");
3535
});
3636

37-
it("should not forward the keyTap call to libnut for an unknown key", () => {
37+
it("should not forward the keyTap call to libnut for an unknown key", async () => {
3838
// GIVEN
3939
const SUT = new KeyboardAction();
4040

4141
// WHEN
42-
SUT.click(Key.Add);
42+
await SUT.click(Key.Pause);
4343

4444
// THEN
4545
expect(libnut.keyTap).not.toBeCalled();
4646
});
4747
});
4848

4949
describe("type", () => {
50-
it("should forward the type call to libnut", () => {
50+
it("should forward the type call to libnut", async () => {
5151
// GIVEN
5252
const SUT = new KeyboardAction();
5353
const payload = "testInput";
5454

5555
// WHEN
56-
SUT.type(payload);
56+
await SUT.type(payload);
5757

5858
// THEN
5959
expect(libnut.typeString).toBeCalledTimes(1);
@@ -70,42 +70,42 @@ describe("libnut keyboard action", () => {
7070
// WHEN
7171

7272
// THEN
73-
expect(SUT.type("foo")).rejects.toThrowError("Test error");
73+
await expect(SUT.type("foo")).rejects.toThrowError("Test error");
7474
});
7575
});
7676

7777
describe("pressKey", () => {
78-
it("should forward the pressKey call to libnut for a known key", () => {
78+
it("should forward the pressKey call to libnut for a known key", async () => {
7979
// GIVEN
8080
const SUT = new KeyboardAction();
8181

8282
// WHEN
83-
SUT.pressKey(Key.A);
83+
await SUT.pressKey(Key.A);
8484

8585
// THEN
8686
expect(libnut.keyToggle).toBeCalledTimes(1);
8787
expect(libnut.keyToggle).toBeCalledWith(KeyboardAction.keyLookup(Key.A), "down", []);
8888
});
8989

90-
it("should treat a list of keys as modifiers + the actual key to press", () => {
90+
it("should treat a list of keys as modifiers + the actual key to press", async () => {
9191
// GIVEN
9292
const SUT = new KeyboardAction();
9393

9494
// WHEN
95-
SUT.pressKey(Key.LeftControl, Key.A);
95+
await SUT.pressKey(Key.LeftControl, Key.A);
9696

9797
// THEN
9898
expect(libnut.keyToggle).toBeCalledTimes(1);
9999
expect(libnut.keyToggle)
100100
.toBeCalledWith(KeyboardAction.keyLookup(Key.A), "down", [KeyboardAction.keyLookup(Key.LeftControl)]);
101101
});
102102

103-
it("should not forward the pressKey call to libnut for an unknown key", () => {
103+
it("should not forward the pressKey call to libnut for an unknown key", async () => {
104104
// GIVEN
105105
const SUT = new KeyboardAction();
106106

107107
// WHEN
108-
SUT.pressKey(Key.Add);
108+
await SUT.pressKey(Key.Pause);
109109

110110
// THEN
111111
expect(libnut.keyToggle).not.toBeCalled();
@@ -121,42 +121,42 @@ describe("libnut keyboard action", () => {
121121
// WHEN
122122

123123
// THEN
124-
expect(SUT.pressKey(Key.A)).rejects.toThrowError("Test error");
124+
await expect(SUT.pressKey(Key.A)).rejects.toThrowError("Test error");
125125
});
126126
});
127127

128128
describe("releaseKey", () => {
129-
it("should forward the releaseKey call to libnut for a known key", () => {
129+
it("should forward the releaseKey call to libnut for a known key", async () => {
130130
// GIVEN
131131
const SUT = new KeyboardAction();
132132

133133
// WHEN
134-
SUT.releaseKey(Key.A);
134+
await SUT.releaseKey(Key.A);
135135

136136
// THEN
137137
expect(libnut.keyToggle).toBeCalledTimes(1);
138138
expect(libnut.keyToggle).toBeCalledWith(KeyboardAction.keyLookup(Key.A), "up", []);
139139
});
140140

141-
it("should treat a list of keys as modifiers + the actual key to release", () => {
141+
it("should treat a list of keys as modifiers + the actual key to release", async () => {
142142
// GIVEN
143143
const SUT = new KeyboardAction();
144144

145145
// WHEN
146-
SUT.releaseKey(Key.LeftControl, Key.A);
146+
await SUT.releaseKey(Key.LeftControl, Key.A);
147147

148148
// THEN
149149
expect(libnut.keyToggle).toBeCalledTimes(1);
150150
expect(libnut.keyToggle)
151151
.toBeCalledWith(KeyboardAction.keyLookup(Key.A), "up", [KeyboardAction.keyLookup(Key.LeftControl)]);
152152
});
153153

154-
it("should not forward the releaseKey call to libnut for an unknown key", () => {
154+
it("should not forward the releaseKey call to libnut for an unknown key", async () => {
155155
// GIVEN
156156
const SUT = new KeyboardAction();
157157

158158
// WHEN
159-
SUT.releaseKey(Key.Add);
159+
await SUT.releaseKey(Key.Pause);
160160

161161
// THEN
162162
expect(libnut.keyToggle).not.toBeCalled();
@@ -172,29 +172,29 @@ describe("libnut keyboard action", () => {
172172
// WHEN
173173

174174
// THEN
175-
expect(SUT.releaseKey(Key.A)).rejects.toThrowError("Test error");
175+
await expect(SUT.releaseKey(Key.A)).rejects.toThrowError("Test error");
176176
});
177177
});
178178

179179
describe("bugfix #260", () => {
180-
it("should forward the pressKey call to libnut for 'delete'", () => {
180+
it("should forward the pressKey call to libnut for 'delete'", async () => {
181181
// GIVEN
182182
const SUT = new KeyboardAction();
183183

184184
// WHEN
185-
SUT.pressKey(Key.Delete);
185+
await SUT.pressKey(Key.Delete);
186186

187187
// THEN
188188
expect(libnut.keyToggle).toBeCalledTimes(1);
189189
expect(libnut.keyToggle).toBeCalledWith("delete", "down", []);
190190
});
191191

192-
it("should forward the releaseKey call to libnut for 'delete'", () => {
192+
it("should forward the releaseKey call to libnut for 'delete'", async () => {
193193
// GIVEN
194194
const SUT = new KeyboardAction();
195195

196196
// WHEN
197-
SUT.releaseKey(Key.Delete);
197+
await SUT.releaseKey(Key.Delete);
198198

199199
// THEN
200200
expect(libnut.keyToggle).toBeCalledTimes(1);

lib/provider/native/libnut-keyboard.class.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export default class KeyboardAction implements KeyboardProviderInterface {
7777
[Key.NumPad7, "numpad_7"],
7878
[Key.NumPad8, "numpad_8"],
7979
[Key.NumPad9, "numpad_9"],
80+
[Key.Decimal, "numpad_decimal"],
8081

8182
[Key.Space, "space"],
8283
[Key.Escape, "escape"],
@@ -119,16 +120,15 @@ export default class KeyboardAction implements KeyboardProviderInterface {
119120
[Key.PageUp, "pageup"],
120121
[Key.PageDown, "pagedown"],
121122

122-
[Key.Add, null],
123-
[Key.Subtract, null],
124-
[Key.Multiply, null],
125-
[Key.Divide, null],
126-
[Key.Decimal, null],
123+
[Key.Add, "add"],
124+
[Key.Subtract, "subtract"],
125+
[Key.Multiply, "multiply"],
126+
[Key.Divide, "divide"],
127127
[Key.Enter, "enter"],
128128

129-
[Key.CapsLock, null],
130-
[Key.ScrollLock, null],
131-
[Key.NumLock, null],
129+
[Key.CapsLock, "caps_lock"],
130+
[Key.ScrollLock, "scroll_lock"],
131+
[Key.NumLock, "num_lock"],
132132

133133
[Key.AudioMute, "audio_mute"],
134134
[Key.AudioVolDown, "audio_vol_down"],

0 commit comments

Comments
 (0)