scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
118 lines • 3.18 kB
JavaScript
import { AbsArgs } from "scriptable-abstract";
import { MockNotification } from "../services/notification";
const DEFAULT_STATE = {
plainTexts: [],
urls: [],
fileURLs: [],
images: [],
queryParameters: {},
shortcutParameter: null,
widgetParameter: null,
notification: new MockNotification()
};
class MockArgs extends 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 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 });
}
}
export {
MockArgs
};
//# sourceMappingURL=args.js.map