Skip to content

Commit

Permalink
add approve method
Browse files Browse the repository at this point in the history
  • Loading branch information
0xPxt committed Feb 14, 2025
1 parent fa29747 commit 575a459
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Zemu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,39 @@ export default class Zemu {
return imageIndex;
}

async approve(

Check failure on line 751 in src/Zemu.ts

View workflow job for this annotation

GitHub Actions / Format and Lint

Missing return type on function
path: string,
testcaseName: string,
text: string | RegExp,
waitForScreenUpdate = true,
takeSnapshots = true,
imageIndex: number,
) {
// Approve can be performed with Tap or PressAndHold
const approveButton = getTouchElement(this.startOptions.model, this.startOptions.approveAction);
const textRegex = new RegExp(text, "i");
const snapshotPrefixTmp = resolve(`${path}/snapshots-tmp/${testcaseName}`);
const filename = this.getSnapshotPath(snapshotPrefixTmp, imageIndex, takeSnapshots);
const touchDevice = isTouchDevice(this.startOptions.model);

if (this.startOptions.approveAction === ButtonKind.DynamicTapButton) {
const events = await this.getEvents();
const matchingEvent = events.find((event: IEvent) => textRegex.test(event.text));

if (matchingEvent != null) {
approveButton.x = Math.round(matchingEvent.x + matchingEvent.w / 2);
approveButton.y = Math.round(matchingEvent.y + matchingEvent.h / 2);
}
}

const nav: INavElement = {
type: touchDevice ? ActionKind.Touch : ActionKind.BothClick,
button: approveButton,
};
await this.runAction(nav, filename, waitForScreenUpdate, true);
return imageIndex;
}

async navigateAndCompareUntilText(
path: string,
testcaseName: string,
Expand Down

0 comments on commit 575a459

Please sign in to comment.