UNPKG

scriptable-testlab

Version:

A lightweight, efficient tool designed to manage and update scripts for Scriptable.

180 lines (151 loc) 4.14 kB
import {AbsCalendarEvent} from 'scriptable-abstract'; /** * State interface for CalendarEvent mock */ export interface CalendarEventState { identifier: string; title: string; location: string; notes: string; startDate: Date; endDate: Date; isAllDay: boolean; attendees: Array<{ isCurrentUser: boolean; name: string; status: string; type: string; role: string; }>; availability: 'busy' | 'free' | 'tentative' | 'unavailable'; timeZone: string; calendar: any; // Calendar type } /** * Mock implementation of Scriptable's CalendarEvent. * Represents a calendar event that can be created, modified and removed. */ export class MockCalendarEvent extends AbsCalendarEvent<CalendarEventState> { private static _instance: MockCalendarEvent; static get instance(): MockCalendarEvent { if (!this._instance) { this._instance = new MockCalendarEvent(); } return this._instance; } constructor() { super({ identifier: '', title: '', location: '', notes: '', startDate: new Date(), endDate: new Date(), isAllDay: false, attendees: [], availability: 'busy', timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, calendar: null, // Will be set when created through create() }); } /** * _Creates a new calendar event._ * @param calendar - Calendar to create the event in. * @see https://docs.scriptable.app/calendarevent/#new-calendarevent */ static create(calendar: any): MockCalendarEvent { const event = new MockCalendarEvent(); event.setState({calendar}); return event; } /** * _Saves the calendar event._ * @see https://docs.scriptable.app/calendarevent/#-save */ async save(): Promise<void> { // In a real implementation, this would save to the calendar return Promise.resolve(); } /** * _Removes the calendar event._ * @see https://docs.scriptable.app/calendarevent/#-remove */ async remove(): Promise<void> { // In a real implementation, this would remove from the calendar return Promise.resolve(); } /** * _Presents a view for editing the calendar event._ * @see https://docs.scriptable.app/calendarevent/#-presentedit */ async presentEdit(): Promise<MockCalendarEvent> { // In a mock environment, just return this return Promise.resolve(this); } /** * _Presents a view for creating a new calendar event._ * @see https://docs.scriptable.app/calendarevent/#presentcreate */ static async presentCreate(): Promise<MockCalendarEvent> { // In a mock environment, create and return a new instance return Promise.resolve(new MockCalendarEvent()); } // Property getters and setters get identifier(): string { return this.state.identifier; } get title(): string { return this.state.title; } set title(value: string) { this.setState({title: value}); } get location(): string { return this.state.location; } set location(value: string) { this.setState({location: value}); } get notes(): string { return this.state.notes; } set notes(value: string) { this.setState({notes: value}); } get startDate(): Date { return this.state.startDate; } set startDate(value: Date) { this.setState({startDate: value}); } get endDate(): Date { return this.state.endDate; } set endDate(value: Date) { this.setState({endDate: value}); } get isAllDay(): boolean { return this.state.isAllDay; } set isAllDay(value: boolean) { this.setState({isAllDay: value}); } get attendees(): CalendarEventState['attendees'] { return [...this.state.attendees]; } get availability(): CalendarEventState['availability'] { return this.state.availability; } set availability(value: CalendarEventState['availability']) { this.setState({availability: value}); } get timeZone(): string { return this.state.timeZone; } set timeZone(value: string) { this.setState({timeZone: value}); } get calendar(): any { return this.state.calendar; } }