Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {getTimestamp, ScreenApi} from "./screen.function";
import {createRegionClass} from "../region";
import {Project, TestExecutionContext} from "@sakuli/core";
import {SimpleLogger} from "@sakuli/commons";
import {FileType} from "@nut-tree/nut-js/dist/lib/file-type.enum";
import {cwd} from "process";
import {join} from "path";
let ctx: TestExecutionContext;
let project: Project;
const testFilename = "testfile.png";
const testPath = "/test/path";
const testConfidence = 0.99;
const testTimeout = 500;
const expectedRegion = new Region(0, 0, 100, 100);
beforeEach(() => {
ctx = new TestExecutionContext(new SimpleLogger());
project = new Project("");
});
describe("ScreenApi", () => {
it("should call `screen.find` with suitable Region", async () => {
// GIVEN
const TestRegion = createRegionClass(ctx, project);
const testRegion = new TestRegion(0, 0, 100, 100);
screen.find = jest.fn(() => Promise.resolve(expectedRegion));
// WHEN
await ScreenApi.find(testFilename, testPath, testConfidence, testRegion);
return new Promise(async (resolve, reject) => {
try {
screen.config.resourceDirectory = path;
const result = await screen.find(filename, {
confidence,
searchRegion: new NutRegion(
left,
top,
width,
height
)
});
resolve({
left: result.left,
top: result.top,
width: result.width,
height: result.height
});
} catch (e) {
reject(e);
}
});
const toNutRegion = async (region: Region): Promise => {
return new NutRegion(
await region.getX() || 0,
await region.getY() || 0,
await region.getW() || await ScreenApi.width(),
await region.getH() || await ScreenApi.height()
);
};