scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
64 lines (52 loc) • 1.25 kB
text/typescript
import {AbsMessage} from 'scriptable-abstract';
interface MessageState {
recipients: string[];
body: string;
}
const DEFAULT_STATE: MessageState = {
recipients: [],
body: '',
};
/**
* Mock implementation of Scriptable's Message.
* Provides functionality for sending messages.
* @implements Message
*/
export class MockMessage extends AbsMessage<MessageState> {
private static _instance: MockMessage | null = null;
static get instance(): MockMessage {
if (!this._instance) {
this._instance = new MockMessage();
}
return this._instance;
}
constructor() {
super(DEFAULT_STATE);
}
get recipients(): string[] {
return [...this.state.recipients];
}
set recipients(value: string[]) {
this.setState({recipients: [...value]});
}
get body(): string {
return this.state.body;
}
set body(value: string) {
this.setState({body: value});
}
/**
* Send the message.
* @returns A promise that resolves when the message is sent
*/
async send(): Promise<void> {
// In a mock environment, we'll simulate successful message sending
return Promise.resolve();
}
/**
* Clear the message details
*/
clear(): void {
this.setState(DEFAULT_STATE);
}
}