scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
141 lines • 4.26 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var args_exports = {};
__export(args_exports, {
MockArgs: () => MockArgs
});
module.exports = __toCommonJS(args_exports);
var import_scriptable_abstract = require("scriptable-abstract");
var import_notification = require("../services/notification");
const DEFAULT_STATE = {
plainTexts: [],
urls: [],
fileURLs: [],
images: [],
queryParameters: {},
shortcutParameter: null,
widgetParameter: null,
notification: new import_notification.MockNotification()
};
class MockArgs extends import_scriptable_abstract.AbsArgs {
static get instance() {
if (!this._instance) {
this._instance = new MockArgs();
}
return this._instance;
}
constructor() {
super(DEFAULT_STATE);
}
static reset() {
this.instance.setState(DEFAULT_STATE);
}
get plainTexts() {
return [...this.state.plainTexts ?? []];
}
get urls() {
return [...this.state.urls ?? []];
}
get fileURLs() {
return [...this.state.fileURLs ?? []];
}
get images() {
return [...this.state.images ?? []];
}
get queryParameters() {
return { ...this.state.queryParameters ?? {} };
}
get shortcutParameter() {
return this.state.shortcutParameter;
}
get widgetParameter() {
return this.state.widgetParameter;
}
get notification() {
return this.state.notification ?? new import_notification.MockNotification();
}
setState(newState) {
if (!newState) {
throw new Error("State cannot be null or undefined");
}
if ("plainTexts" in newState && !Array.isArray(newState.plainTexts)) {
throw new Error("plainTexts must be an array");
}
if ("urls" in newState && !Array.isArray(newState.urls)) {
throw new Error("urls must be an array");
}
if ("fileURLs" in newState && !Array.isArray(newState.fileURLs)) {
throw new Error("fileURLs must be an array");
}
if ("images" in newState && !Array.isArray(newState.images)) {
throw new Error("images must be an array");
}
if ("queryParameters" in newState && typeof newState.queryParameters !== "object") {
throw new Error("queryParameters must be an object");
}
return super.setState(newState);
}
// Testing helpers
setPlainTexts(texts) {
if (!Array.isArray(texts)) {
throw new Error("texts must be an array");
}
this.setState({ plainTexts: [...texts] });
}
setUrls(urls) {
if (!Array.isArray(urls)) {
throw new Error("urls must be an array");
}
this.setState({ urls: [...urls] });
}
setFileURLs(urls) {
if (!Array.isArray(urls)) {
throw new Error("urls must be an array");
}
this.setState({ fileURLs: [...urls] });
}
setImages(images) {
if (!Array.isArray(images)) {
throw new Error("images must be an array");
}
this.setState({ images: [...images] });
}
setQueryParameters(params) {
if (typeof params !== "object") {
throw new Error("params must be an object");
}
this.setState({ queryParameters: { ...params } });
}
setShortcutParameter(param) {
this.setState({ shortcutParameter: param });
}
setWidgetParameter(param) {
this.setState({ widgetParameter: param });
}
setNotification(notification) {
if (!notification) {
throw new Error("notification cannot be null");
}
this.setState({ notification });
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MockArgs
});
//# sourceMappingURL=args.js.map