Skip to content

Commit

Permalink
Updated window tests
Browse files Browse the repository at this point in the history
  • Loading branch information
s1hofmann committed Apr 2, 2024
1 parent 8881668 commit 9b48ca0
Showing 1 changed file with 80 additions and 2 deletions.
82 changes: 80 additions & 2 deletions core/nut.js/lib/window.class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import {
WindowProviderInterface
} from "@nut-tree/provider-interfaces";
import { mockPartial } from "sneer";
import { Region, WindowElement, WindowElementDescription } from "@nut-tree/shared";
import { windowElementDescribedBy } from "../index";
import { Region, RGBA, WindowElement, WindowElementDescription } from "@nut-tree/shared";
import { pixelWithColor, windowElementDescribedBy } from "../index";
import { NoopLogProvider } from "./provider/log/noop-log-provider.class";

jest.setTimeout(50000);
describe("Window class", () => {
it("should retrieve the window region via provider", async () => {
// GIVEN
Expand Down Expand Up @@ -142,6 +143,83 @@ describe("Window class", () => {
expect(elementInspectorMock).toHaveBeenCalledWith(mockWindowHandle, description);
});

describe("invalid input", () => {
it("should throw on invalid input to find", async () => {
// GIVEN
const elementInspectorMock = jest.fn();
const providerRegistryMock = mockPartial<ProviderRegistry>({
getWindowElementInspector(): ElementInspectionProviderInterface {
return mockPartial<ElementInspectionProviderInterface>({
findElement: elementInspectorMock,
findElements: elementInspectorMock
});
},
getLogProvider(): LogProviderInterface {
return new NoopLogProvider();
}
});
const mockWindowHandle = 123;
const description = new RGBA(255, 0, 255, 255);
const SUT = new Window(providerRegistryMock, mockWindowHandle);

// WHEN
const test = () => SUT.find(pixelWithColor(description) as any);

// THEN
await expect(test).rejects.toThrowError(/.*'Error: Search input is not supported. Please use a valid search input type.'$/);
});

it("should throw on invalid input to findAll", async () => {
// GIVEN
const elementInspectorMock = jest.fn();
const providerRegistryMock = mockPartial<ProviderRegistry>({
getWindowElementInspector(): ElementInspectionProviderInterface {
return mockPartial<ElementInspectionProviderInterface>({
findElement: elementInspectorMock,
findElements: elementInspectorMock
});
},
getLogProvider(): LogProviderInterface {
return new NoopLogProvider();
}
});
const mockWindowHandle = 123;
const description = new RGBA(255, 0, 255, 255);
const SUT = new Window(providerRegistryMock, mockWindowHandle);

// WHEN
const test = () => SUT.findAll(pixelWithColor(description) as any);

// THEN
await expect(test).rejects.toThrowError(/.*'Error: Search input is not supported. Please use a valid search input type.'$/);
});

it("should throw on invalid input to waitFor", async () => {
// GIVEN
const elementInspectorMock = jest.fn();
const providerRegistryMock = mockPartial<ProviderRegistry>({
getWindowElementInspector(): ElementInspectionProviderInterface {
return mockPartial<ElementInspectionProviderInterface>({
findElement: elementInspectorMock,
findElements: elementInspectorMock
});
},
getLogProvider(): LogProviderInterface {
return new NoopLogProvider();
}
});
const mockWindowHandle = 123;
const description = new RGBA(255, 0, 255, 255);
const SUT = new Window(providerRegistryMock, mockWindowHandle);

// WHEN
const test = () => SUT.waitFor(pixelWithColor(description) as any, 100, 50);

// THEN
await expect(test).rejects.toMatch(/.*'Error: Search input is not supported.*$/);
});
});

describe("hooks", () => {
it("should trigger registered hooks", async () => {
// GIVEN
Expand Down

0 comments on commit 9b48ca0

Please sign in to comment.