|
1 |
| -import {NativeAdapter} from "./adapter/native.adapter.class"; |
2 |
| -import {Key} from "./key.enum"; |
3 |
| -import {Keyboard} from "./keyboard.class"; |
| 1 | +import { NativeAdapter } from "./adapter/native.adapter.class"; |
| 2 | +import { Key } from "./key.enum"; |
| 3 | +import { Keyboard } from "./keyboard.class"; |
4 | 4 |
|
5 | 5 | jest.mock("./adapter/native.adapter.class");
|
6 | 6 |
|
7 | 7 | beforeEach(() => {
|
8 |
| - jest.resetAllMocks(); |
| 8 | + jest.resetAllMocks(); |
9 | 9 | });
|
10 | 10 |
|
11 | 11 | describe("Keyboard", () => {
|
12 |
| - it("should have a default delay of 20 ms", () => { |
13 |
| - // GIVEN |
14 |
| - const adapterMock = new NativeAdapter(); |
15 |
| - const SUT = new Keyboard(adapterMock); |
16 |
| - |
17 |
| - // WHEN |
18 |
| - |
19 |
| - // THEN |
20 |
| - expect(SUT.config.autoDelayMs).toEqual(20); |
21 |
| - }); |
22 |
| - |
23 |
| - it("should pass input strings down to the type call.", () => { |
24 |
| - // GIVEN |
25 |
| - const adapterMock = new NativeAdapter(); |
26 |
| - const SUT = new Keyboard(adapterMock); |
27 |
| - const payload = "Test input!"; |
28 |
| - |
29 |
| - // WHEN |
30 |
| - SUT.type(payload); |
31 |
| - |
32 |
| - // THEN |
33 |
| - expect(adapterMock.type).toHaveBeenCalledTimes(1); |
34 |
| - expect(adapterMock.type).toHaveBeenCalledWith(payload); |
35 |
| - }); |
36 |
| - |
37 |
| - it("should pass input keys down to the click call.", () => { |
38 |
| - // GIVEN |
39 |
| - const adapterMock = new NativeAdapter(); |
40 |
| - const SUT = new Keyboard(adapterMock); |
41 |
| - const payload = Key.A; |
42 |
| - |
43 |
| - // WHEN |
44 |
| - SUT.type(payload); |
45 |
| - |
46 |
| - // THEN |
47 |
| - expect(adapterMock.click).toHaveBeenCalledTimes(1); |
48 |
| - expect(adapterMock.click).toHaveBeenCalledWith(payload); |
49 |
| - }); |
50 |
| - |
51 |
| - it("should pass a list of input keys down to the click call.", () => { |
52 |
| - // GIVEN |
53 |
| - const adapterMock = new NativeAdapter(); |
54 |
| - const SUT = new Keyboard(adapterMock); |
55 |
| - const payload = [Key.A, Key.S, Key.D, Key.F]; |
56 |
| - |
57 |
| - // WHEN |
58 |
| - for (const key of payload) { |
59 |
| - SUT.type(key); |
60 |
| - } |
61 |
| - |
62 |
| - // THEN |
63 |
| - expect(adapterMock.click).toHaveBeenCalledTimes(payload.length); |
64 |
| - }); |
65 |
| - |
66 |
| - it("should pass a list of input keys down to the pressKey call.", () => { |
67 |
| - // GIVEN |
68 |
| - const adapterMock = new NativeAdapter(); |
69 |
| - const SUT = new Keyboard(adapterMock); |
70 |
| - const payload = [Key.A, Key.S, Key.D, Key.F]; |
71 |
| - |
72 |
| - // WHEN |
73 |
| - for (const key of payload) { |
74 |
| - SUT.pressKey(key); |
75 |
| - } |
76 |
| - |
77 |
| - // THEN |
78 |
| - expect(adapterMock.pressKey).toHaveBeenCalledTimes(payload.length); |
79 |
| - }); |
80 |
| - |
81 |
| - it("should pass a list of input keys down to the releaseKey call.", () => { |
82 |
| - // GIVEN |
83 |
| - const adapterMock = new NativeAdapter(); |
84 |
| - const SUT = new Keyboard(adapterMock); |
85 |
| - const payload = [Key.A, Key.S, Key.D, Key.F]; |
86 |
| - |
87 |
| - // WHEN |
88 |
| - for (const key of payload) { |
89 |
| - SUT.releaseKey(key); |
90 |
| - } |
91 |
| - |
92 |
| - // THEN |
93 |
| - expect(adapterMock.releaseKey).toHaveBeenCalledTimes(payload.length); |
94 |
| - }); |
| 12 | + it("should have a default delay of 20 ms", () => { |
| 13 | + // GIVEN |
| 14 | + const adapterMock = new NativeAdapter(); |
| 15 | + const SUT = new Keyboard(adapterMock); |
| 16 | + |
| 17 | + // WHEN |
| 18 | + |
| 19 | + // THEN |
| 20 | + expect(SUT.config.autoDelayMs).toEqual(20); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should pass input strings down to the type call.", () => { |
| 24 | + // GIVEN |
| 25 | + const adapterMock = new NativeAdapter(); |
| 26 | + const SUT = new Keyboard(adapterMock); |
| 27 | + const payload = "Test input!"; |
| 28 | + |
| 29 | + // WHEN |
| 30 | + SUT.type(payload); |
| 31 | + |
| 32 | + // THEN |
| 33 | + expect(adapterMock.type).toHaveBeenCalledTimes(1); |
| 34 | + expect(adapterMock.type).toHaveBeenCalledWith(payload); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should pass multiple input strings down to the type call.", () => { |
| 38 | + // GIVEN |
| 39 | + const adapterMock = new NativeAdapter(); |
| 40 | + const SUT = new Keyboard(adapterMock); |
| 41 | + const payload = ["Test input!", "Array test2"]; |
| 42 | + |
| 43 | + // WHEN |
| 44 | + SUT.type(...payload); |
| 45 | + |
| 46 | + // THEN |
| 47 | + expect(adapterMock.type).toHaveBeenCalledTimes(1); |
| 48 | + expect(adapterMock.type).toHaveBeenCalledWith(payload.join(" ")); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should pass input keys down to the click call.", () => { |
| 52 | + // GIVEN |
| 53 | + const adapterMock = new NativeAdapter(); |
| 54 | + const SUT = new Keyboard(adapterMock); |
| 55 | + const payload = [Key.A, Key.S, Key.D, Key.F]; |
| 56 | + |
| 57 | + // WHEN |
| 58 | + SUT.type(...payload); |
| 59 | + |
| 60 | + // THEN |
| 61 | + expect(adapterMock.click).toHaveBeenCalledTimes(1); |
| 62 | + expect(adapterMock.click).toHaveBeenCalledWith(...payload); |
| 63 | + }); |
| 64 | + |
| 65 | + it("should pass a list of input keys down to the click call.", () => { |
| 66 | + // GIVEN |
| 67 | + const adapterMock = new NativeAdapter(); |
| 68 | + const SUT = new Keyboard(adapterMock); |
| 69 | + const payload = [Key.A, Key.S, Key.D, Key.F]; |
| 70 | + |
| 71 | + // WHEN |
| 72 | + for (const key of payload) { |
| 73 | + SUT.type(key); |
| 74 | + } |
| 75 | + |
| 76 | + // THEN |
| 77 | + expect(adapterMock.click).toHaveBeenCalledTimes(payload.length); |
| 78 | + }); |
| 79 | + |
| 80 | + it("should pass a list of input keys down to the pressKey call.", () => { |
| 81 | + // GIVEN |
| 82 | + const adapterMock = new NativeAdapter(); |
| 83 | + const SUT = new Keyboard(adapterMock); |
| 84 | + const payload = [Key.A, Key.S, Key.D, Key.F]; |
| 85 | + |
| 86 | + // WHEN |
| 87 | + for (const key of payload) { |
| 88 | + SUT.pressKey(key); |
| 89 | + } |
| 90 | + |
| 91 | + // THEN |
| 92 | + expect(adapterMock.pressKey).toHaveBeenCalledTimes(payload.length); |
| 93 | + }); |
| 94 | + |
| 95 | + it("should pass a list of input keys down to the releaseKey call.", () => { |
| 96 | + // GIVEN |
| 97 | + const adapterMock = new NativeAdapter(); |
| 98 | + const SUT = new Keyboard(adapterMock); |
| 99 | + const payload = [Key.A, Key.S, Key.D, Key.F]; |
| 100 | + |
| 101 | + // WHEN |
| 102 | + for (const key of payload) { |
| 103 | + SUT.releaseKey(key); |
| 104 | + } |
| 105 | + |
| 106 | + // THEN |
| 107 | + expect(adapterMock.releaseKey).toHaveBeenCalledTimes(payload.length); |
| 108 | + }); |
95 | 109 | });
|
0 commit comments