import {errors} from 'appium/driver'; import type {FakeDriver} from '../driver'; /** Throw if an alert is currently open (blocks other commands). */ export function assertNoAlert(this: FakeDriver): void { if (this.appModel.hasAlert()) { throw new errors.UnexpectedAlertOpenError(); } } /** Throw if no alert is open (required before get/set alert text, accept, etc.). */ export function assertAlert(this: FakeDriver): void { if (!this.appModel.hasAlert()) { throw new errors.NoAlertOpenError(); } } /** getAlertText. */ export async function getAlertText(this: FakeDriver): Promise { this.assertAlert(); return this.appModel.alertText(); } /** setAlertText. */ export async function setAlertText(this: FakeDriver, text: string): Promise { this.assertAlert(); try { this.appModel.setAlertText(text); } catch { throw new errors.InvalidElementStateError(); } } /** postAcceptAlert. */ export async function postAcceptAlert(this: FakeDriver): Promise { this.assertAlert(); this.appModel.handleAlert(); } /** In this fake, dismiss is the same as accept. */ export async function postDismissAlert(this: FakeDriver): Promise { return this.postAcceptAlert(); }