Skip to content

Commit

Permalink
(#547) Updated toShow to support full search parameters, added the po…
Browse files Browse the repository at this point in the history
…ssibility to pass a region to directly specify a search region instead of the whole screen
  • Loading branch information
s1hofmann committed Dec 14, 2023
1 parent 2d53a82 commit 99aec20
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions lib/expect/matchers/toShow.function.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
import { FindInput, ScreenClass } from "../../screen.class";
import { OptionalSearchParameters } from "../../optionalsearchparameters.class";
import { isRegion, Region } from "../../region.class";
import { screen } from "../../../index";

export const toShow = async (
received: ScreenClass,
export const toShow = async <PROVIDER_DATA>(
received: ScreenClass | Region,
needle: FindInput,
confidence?: number
parameters?: OptionalSearchParameters<PROVIDER_DATA>,
) => {
let locationParams;
if (confidence) {
locationParams = new OptionalSearchParameters();
locationParams.confidence = confidence;
}
const identifier = (await needle).id;
try {
await received.find(needle, locationParams);
return {
message: () => `Expected screen to not show ${identifier}`,
pass: true,
};
} catch (err) {
return {
message: () => `Screen is not showing ${identifier}: ${err}`,
pass: false,
};
if (isRegion(received)) {
if (parameters != null) {
parameters.searchRegion = received;
} else {
parameters = { searchRegion: received };
}
try {
await screen.find(needle, parameters);
return {
message: () => `Expected screen to not show ${identifier}`,
pass: true,
};
} catch (err) {
return {
message: () => `Screen is not showing ${identifier}: ${err}`,
pass: false,
};
}
} else {
try {
await received.find(needle, parameters);
return {
message: () => `Expected screen to not show ${identifier}`,
pass: true,
};
} catch (err) {
return {
message: () => `Screen is not showing ${identifier}: ${err}`,
pass: false,
};
}
}
};

0 comments on commit 99aec20

Please sign in to comment.