Skip to content

Commit 752aa4f

Browse files
committed
(#373) Tests click/doubleClick and deprecation notice for leftClick/middleClick/rightClick
1 parent 7a03b9d commit 752aa4f

File tree

2 files changed

+78
-26
lines changed

2 files changed

+78
-26
lines changed

lib/mouse.class.spec.ts

Lines changed: 72 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -186,32 +186,78 @@ describe("Mouse class", () => {
186186
expect(releaseButtonMock).toBeCalledWith(Button.LEFT);
187187
expect(result).toBe(SUT);
188188
});
189-
});
190189

191-
describe("Mousebuttons", () => {
192-
it.each([
193-
[Button.LEFT, Button.LEFT],
194-
[Button.MIDDLE, Button.MIDDLE],
195-
[Button.RIGHT, Button.RIGHT],
196-
] as Array<[Button, Button]>)("should be pressed and released", async (input: Button, expected: Button) => {
197-
// GIVEN
198-
const SUT = new MouseClass(providerRegistryMock);
199-
const pressButtonMock = jest.fn();
200-
const releaseButtonMock = jest.fn();
201-
providerRegistryMock.getMouse = jest.fn(() => mockPartial<MouseProviderInterface>({
202-
setMouseDelay: jest.fn(),
203-
pressButton: pressButtonMock,
204-
releaseButton: releaseButtonMock
205-
}));
206-
207-
// WHEN
208-
const pressed = await SUT.pressButton(input);
209-
const released = await SUT.releaseButton(input);
210-
211-
// THEN
212-
expect(pressButtonMock).toBeCalledWith(expected);
213-
expect(releaseButtonMock).toBeCalledWith(expected);
214-
expect(pressed).toBe(SUT);
215-
expect(released).toBe(SUT);
190+
describe("Mousebuttons", () => {
191+
it.each([
192+
[Button.LEFT, Button.LEFT],
193+
[Button.MIDDLE, Button.MIDDLE],
194+
[Button.RIGHT, Button.RIGHT],
195+
] as Array<[Button, Button]>)("should be pressed and released", async (input: Button, expected: Button) => {
196+
// GIVEN
197+
const SUT = new MouseClass(providerRegistryMock);
198+
const pressButtonMock = jest.fn();
199+
const releaseButtonMock = jest.fn();
200+
providerRegistryMock.getMouse = jest.fn(() => mockPartial<MouseProviderInterface>({
201+
setMouseDelay: jest.fn(),
202+
pressButton: pressButtonMock,
203+
releaseButton: releaseButtonMock
204+
}));
205+
206+
// WHEN
207+
const pressed = await SUT.pressButton(input);
208+
const released = await SUT.releaseButton(input);
209+
210+
// THEN
211+
expect(pressButtonMock).toBeCalledWith(expected);
212+
expect(releaseButtonMock).toBeCalledWith(expected);
213+
expect(pressed).toBe(SUT);
214+
expect(released).toBe(SUT);
215+
});
216216
});
217+
218+
describe("click and doubleClick", () => {
219+
describe("click", () => {
220+
it.each([
221+
[Button.LEFT, Button.LEFT],
222+
[Button.MIDDLE, Button.MIDDLE],
223+
[Button.RIGHT, Button.RIGHT],
224+
] as Array<[Button, Button]>)("should click the respective button on the provider", async (input: Button, expected: Button) => {
225+
// GIVEN
226+
const SUT = new MouseClass(providerRegistryMock);
227+
const clickMock = jest.fn();
228+
providerRegistryMock.getMouse = jest.fn(() => mockPartial<MouseProviderInterface>({
229+
setMouseDelay: jest.fn(),
230+
click: clickMock,
231+
}));
232+
233+
// WHEN
234+
await SUT.click(input);
235+
236+
// THEN
237+
expect(clickMock).toBeCalledWith(expected);
238+
});
239+
});
240+
241+
describe("doubleClick", () => {
242+
it.each([
243+
[Button.LEFT, Button.LEFT],
244+
[Button.MIDDLE, Button.MIDDLE],
245+
[Button.RIGHT, Button.RIGHT],
246+
] as Array<[Button, Button]>)("should click the respective button on the provider", async (input: Button, expected: Button) => {
247+
// GIVEN
248+
const SUT = new MouseClass(providerRegistryMock);
249+
const clickMock = jest.fn();
250+
providerRegistryMock.getMouse = jest.fn(() => mockPartial<MouseProviderInterface>({
251+
setMouseDelay: jest.fn(),
252+
doubleClick: clickMock,
253+
}));
254+
255+
// WHEN
256+
await SUT.doubleClick(input);
257+
258+
// THEN
259+
expect(clickMock).toBeCalledWith(expected);
260+
});
261+
});
262+
})
217263
});

lib/provider/mouse-provider.interface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,22 @@ export interface MouseProviderInterface {
4242

4343
/**
4444
* leftClick should allow to perform a left click via OS event
45+
*
46+
* @deprecated Will be deprecated with the next major release, use `click` instead
4547
*/
4648
leftClick(): Promise<void>;
4749

4850
/**
4951
* rightClick should allow to perform a right click via OS event
52+
*
53+
* @deprecated Will be deprecated with the next major release, use `click` instead
5054
*/
5155
rightClick(): Promise<void>;
5256

5357
/**
5458
* middleClick should allow to perform a middle click via OS event
59+
*
60+
* @deprecated Will be deprecated with the next major release, use `click` instead
5561
*/
5662
middleClick(): Promise<void>;
5763

0 commit comments

Comments
 (0)