Skip to content

Commit 7471b61

Browse files
authored
Feature/499/single point move (#507)
* (#499) Test for single point inputs * (#499) Extend mouse.move to handle single point inputs
1 parent cb9dcf3 commit 7471b61

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/mouse.class.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,29 @@ describe("Mouse class", () => {
142142
expect(result).toBe(SUT);
143143
});
144144

145+
it("should convert single point inputs to an array", async () => {
146+
// GIVEN
147+
const SUT = new MouseClass(providerRegistryMock);
148+
const testPoint = new Point(0, 0);
149+
150+
const setPositionMock = jest.fn();
151+
providerRegistryMock.getMouse = jest.fn(() =>
152+
mockPartial<MouseProviderInterface>({
153+
setMouseDelay: jest.fn(),
154+
setMousePosition: setPositionMock,
155+
})
156+
);
157+
providerRegistryMock.getLogProvider = () => new NoopLogProvider();
158+
159+
// WHEN
160+
const result = await SUT.move(testPoint as unknown as Array<Point>);
161+
162+
// THEN
163+
expect(setPositionMock).toBeCalledTimes(1);
164+
expect(setPositionMock).toBeCalledWith(testPoint);
165+
expect(result).toBe(SUT);
166+
});
167+
145168
it("should press and hold left mouse button, move and release left mouse button on drag", async () => {
146169
// GIVEN
147170
const SUT = new MouseClass(providerRegistryMock);

lib/mouse.class.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ export class MouseClass {
9090
): Promise<MouseClass> {
9191
return new Promise<MouseClass>(async (resolve, reject) => {
9292
try {
93-
const pathSteps = await path;
93+
let pathSteps = await path;
94+
if (!Array.isArray(pathSteps)) {
95+
pathSteps = [pathSteps];
96+
}
9497
this.providerRegistry
9598
.getLogProvider()
9699
.info(

0 commit comments

Comments
 (0)