@metamask/snaps-simulation
Version:
A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment
64 lines • 1.99 kB
JavaScript
import { DialogType } from "@metamask/snaps-sdk";
import { getJsxChildren } from "@metamask/snaps-utils";
import { assert, hasProperty } from "@metamask/utils";
import { getElementByType } from "./interface.mjs";
/**
* Ensure that the actual interface is an alert dialog.
*
* @param ui - The interface to verify.
*/
export function assertIsAlertDialog(ui) {
assert(hasProperty(ui, 'type') && ui.type === DialogType.Alert);
}
/**
* Ensure that the actual interface is a confirmation dialog.
*
* @param ui - The interface to verify.
*/
export function assertIsConfirmationDialog(ui) {
assert(hasProperty(ui, 'type') && ui.type === DialogType.Confirmation);
}
/**
* Ensure that the actual interface is a Prompt dialog.
*
* @param ui - The interface to verify.
*/
export function assertIsPromptDialog(ui) {
assert(hasProperty(ui, 'type') && ui.type === DialogType.Prompt);
}
/**
* Ensure that the actual interface is a custom dialog.
*
* @param ui - The interface to verify.
*/
export function assertIsCustomDialog(ui) {
assert(!hasProperty(ui, 'type'));
}
/**
* Ensure that the actual interface is a custom dialog with a complete footer.
*
* @param ui - The interface to verify.
*/
export function assertCustomDialogHasFooter(ui) {
const footer = getElementByType(ui.content, 'Footer');
assert(footer && getJsxChildren(footer).length === 2);
}
/**
* Ensure that the actual interface is a custom dialog with a partial footer.
*
* @param ui - The interface to verify.
*/
export function assertCustomDialogHasPartialFooter(ui) {
const footer = getElementByType(ui.content, 'Footer');
assert(footer && getJsxChildren(footer).length === 1);
}
/**
* Ensure that the actual interface is a custom dialog without a footer.
*
* @param ui - The interface to verify.
*/
export function assertCustomDialogHasNoFooter(ui) {
const footer = getElementByType(ui.content, 'Footer');
assert(!footer);
}
//# sourceMappingURL=validation.mjs.map