@sprucelabs/spruce-calendar-components 22.7.8 → 22.7.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/.spruce/schemas/schemas.types.d.ts +511 -511
- package/build/__tests__/support/CalendarToolBeltStateMachineTestFactory.d.ts +39 -0
- package/build/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +105 -0
- package/build/__tests__/support/SpyEventManager.d.ts +42 -0
- package/build/__tests__/support/SpyEventManager.js +36 -0
- package/build/__tests__/support/SpyPeopleManager.d.ts +10 -0
- package/build/__tests__/support/SpyPeopleManager.js +23 -0
- package/build/__tests__/support/SpyRemoteEventStore.d.ts +18 -0
- package/build/__tests__/support/SpyRemoteEventStore.js +31 -0
- package/build/__tests__/support/SpyRemotePreferencesStore.d.ts +9 -0
- package/build/__tests__/support/SpyRemotePreferencesStore.js +17 -0
- package/build/__tests__/support/utilities/calendarAssert.d.ts +13 -0
- package/build/__tests__/support/utilities/calendarAssert.js +93 -0
- package/build/__tests__/support/utilities/calendarSkillAssert.d.ts +40 -0
- package/build/__tests__/support/utilities/calendarSkillAssert.js +346 -0
- package/build/__tests__/support/utilities/calendarToolBeltInteractor.d.ts +5 -0
- package/build/__tests__/support/utilities/calendarToolBeltInteractor.js +11 -0
- package/build/esm/.spruce/schemas/schemas.types.d.ts +511 -511
- package/build/esm/__tests__/support/CalendarToolBeltStateMachineTestFactory.d.ts +39 -0
- package/build/esm/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +126 -0
- package/build/esm/__tests__/support/SpyEventManager.d.ts +42 -0
- package/build/esm/__tests__/support/SpyEventManager.js +44 -0
- package/build/esm/__tests__/support/SpyPeopleManager.d.ts +10 -0
- package/build/esm/__tests__/support/SpyPeopleManager.js +31 -0
- package/build/esm/__tests__/support/SpyRemoteEventStore.d.ts +18 -0
- package/build/esm/__tests__/support/SpyRemoteEventStore.js +46 -0
- package/build/esm/__tests__/support/SpyRemotePreferencesStore.d.ts +9 -0
- package/build/esm/__tests__/support/SpyRemotePreferencesStore.js +22 -0
- package/build/esm/__tests__/support/utilities/calendarAssert.d.ts +13 -0
- package/build/esm/__tests__/support/utilities/calendarAssert.js +88 -0
- package/build/esm/__tests__/support/utilities/calendarSkillAssert.d.ts +40 -0
- package/build/esm/__tests__/support/utilities/calendarSkillAssert.js +372 -0
- package/build/esm/__tests__/support/utilities/calendarToolBeltInteractor.d.ts +5 -0
- package/build/esm/__tests__/support/utilities/calendarToolBeltInteractor.js +20 -0
- package/package.json +33 -5
- package/build/esm/index-module.d.ts +0 -31
- package/build/esm/index-module.js +0 -8
- package/build/index-module.d.ts +0 -31
- package/build/index-module.js +0 -34
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SpruceSchemas } from '@sprucelabs/calendar-utils';
|
|
2
|
+
import { ToolBeltViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
3
|
+
import { ViewFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
4
|
+
import { GetScheduleOptions, RemoteEventStore } from '../../stores/RemoteEventStore';
|
|
5
|
+
import { CalendarToolBeltStateMachine, UpdateEvent } from '../../types/calendar.types';
|
|
6
|
+
import CalendarViewController from '../../viewControllers/Calendar.vc';
|
|
7
|
+
import SpyEventManager from './SpyEventManager';
|
|
8
|
+
export default class CalendarToolBeltStateMachineTestFactory {
|
|
9
|
+
static StateMachine(views: ViewFixture): Promise<{
|
|
10
|
+
stateMachine: CalendarToolBeltStateMachine;
|
|
11
|
+
toolBeltVc: ToolBeltViewController;
|
|
12
|
+
calendarVc: CalendarViewController;
|
|
13
|
+
events: SpyEventManager;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
|
|
17
|
+
interface ViewControllerMap {
|
|
18
|
+
'calendar.calendar': CalendarViewController;
|
|
19
|
+
}
|
|
20
|
+
interface ViewControllerOptionsMap {
|
|
21
|
+
'calendar.calendar': ConstructorParameters<typeof CalendarViewController>[0];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export declare class FakeRemoteEventStore implements RemoteEventStore {
|
|
25
|
+
lastPersistedEvent?: SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent;
|
|
26
|
+
load(_options: {
|
|
27
|
+
organizationId: string;
|
|
28
|
+
locationId: string;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
persist(event: UpdateEvent): Promise<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent>;
|
|
31
|
+
setCalendarId(_id: string): void;
|
|
32
|
+
clearCalendarId(): void;
|
|
33
|
+
getCalendarId(): string | undefined;
|
|
34
|
+
waitForPendingSaves(): Promise<void>;
|
|
35
|
+
cancelEvent(_id: string): Promise<void>;
|
|
36
|
+
getSchedules(_options: GetScheduleOptions): Promise<SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent[]>;
|
|
37
|
+
getEventTypes(): Promise<SpruceSchemas.Calendar.v2021_05_19.CalendarEventType[]>;
|
|
38
|
+
getCalendars(): Promise<SpruceSchemas.Calendar.v2021_05_19.Calendar[]>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { dateUtil } from '@sprucelabs/calendar-utils';
|
|
11
|
+
import { calendarSeeder, ToolBeltStateMachine, } from '@sprucelabs/heartwood-view-controllers';
|
|
12
|
+
import { fake } from '@sprucelabs/spruce-test-fixtures';
|
|
13
|
+
import { generateId } from '@sprucelabs/test-utils';
|
|
14
|
+
import RemotePreferencesStore from '../../stores/RemotePreferencesStore.js';
|
|
15
|
+
import draftEventGenerator from '../../utilities/draftGenerator.js';
|
|
16
|
+
import CalendarViewController from '../../viewControllers/Calendar.vc.js';
|
|
17
|
+
import SpyEventManager from './SpyEventManager.js';
|
|
18
|
+
import SpyPeopleManager from './SpyPeopleManager.js';
|
|
19
|
+
export default class CalendarToolBeltStateMachineTestFactory {
|
|
20
|
+
static StateMachine(views) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const factory = views.getFactory();
|
|
23
|
+
if (!factory.hasController('calendar.calendar')) {
|
|
24
|
+
factory.mixinControllers({
|
|
25
|
+
//@ts-ignore
|
|
26
|
+
'calendar.calendar': CalendarViewController,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const toolBeltVc = views.Controller('toolBelt', {});
|
|
30
|
+
const event = calendarSeeder.generateEventValues();
|
|
31
|
+
const calendarVc = views.Controller('calendar.calendar', {
|
|
32
|
+
onAddDraftEvent: () => { },
|
|
33
|
+
onEventSwapped(draft, saved) {
|
|
34
|
+
return events.silentlySwapEvent(draft.id, saved);
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
calendarVc.addEvent(event);
|
|
38
|
+
const sm = new ToolBeltStateMachine({
|
|
39
|
+
vcFactory: views.getFactory(),
|
|
40
|
+
toolBeltVc,
|
|
41
|
+
connectToApi: () => __awaiter(this, void 0, void 0, function* () { return fake.getClient(); }),
|
|
42
|
+
context: Object.assign(Object.assign({}, views.getRouter().buildLoadOptions()), { event,
|
|
43
|
+
calendarVc, cancelEvent: () => { } }),
|
|
44
|
+
});
|
|
45
|
+
const connectToApi = () => __awaiter(this, void 0, void 0, function* () { return fake.getClient(); });
|
|
46
|
+
const preferences = new FakeRemotePreferences({ connectToApi });
|
|
47
|
+
const remoteEventsStore = new FakeRemoteEventStore();
|
|
48
|
+
const events = new SpyEventManager({
|
|
49
|
+
calendarVc,
|
|
50
|
+
sm,
|
|
51
|
+
dates: dateUtil,
|
|
52
|
+
remoteVc: {
|
|
53
|
+
fetchRemoteController: (name) => __awaiter(this, void 0, void 0, function* () { return factory.getController(name); }),
|
|
54
|
+
},
|
|
55
|
+
askForUpdateStrategy: () => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
return 'all';
|
|
57
|
+
}),
|
|
58
|
+
events: remoteEventsStore,
|
|
59
|
+
preferences,
|
|
60
|
+
});
|
|
61
|
+
yield events.load();
|
|
62
|
+
events.silentlyAddEvent(event);
|
|
63
|
+
const people = new SpyPeopleManager({
|
|
64
|
+
calendarVc,
|
|
65
|
+
connectToApi,
|
|
66
|
+
preferences,
|
|
67
|
+
getVisibleEvents: () => [],
|
|
68
|
+
});
|
|
69
|
+
yield sm.updateContext({ events, people });
|
|
70
|
+
yield sm.on('did-update-context', () => {
|
|
71
|
+
calendarVc.updateEvent(event.id, Object.assign({}, sm.getContext().event));
|
|
72
|
+
});
|
|
73
|
+
//@ts-ignore
|
|
74
|
+
return { stateMachine: sm, toolBeltVc, calendarVc, events };
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class FakeRemotePreferences extends RemotePreferencesStore {
|
|
79
|
+
loadPreferences() {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
81
|
+
}
|
|
82
|
+
save() {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export class FakeRemoteEventStore {
|
|
87
|
+
load(_options) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
89
|
+
}
|
|
90
|
+
persist(event) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const e = Object.assign(Object.assign({ dateCreated: new Date().getTime() }, calendarSeeder.generateEventValues()), event);
|
|
93
|
+
if (draftEventGenerator.isDraftId(e.id)) {
|
|
94
|
+
e.id = generateId();
|
|
95
|
+
}
|
|
96
|
+
this.lastPersistedEvent = e;
|
|
97
|
+
return e;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
setCalendarId(_id) { }
|
|
101
|
+
clearCalendarId() { }
|
|
102
|
+
getCalendarId() {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
waitForPendingSaves() {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
107
|
+
}
|
|
108
|
+
cancelEvent(_id) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
110
|
+
}
|
|
111
|
+
getSchedules(_options) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
return [];
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
getEventTypes() {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
return [];
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
getCalendars() {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
return [];
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CalendarEvent, CalendarToolBeltContext, UpdateCalendarToolBeltContextHandler } from '../../types/calendar.types';
|
|
2
|
+
import CalendarEventManager, { CalendarEventManagerOptions } from '../../utilities/CalendarEventManager';
|
|
3
|
+
import SpyRemoteEventStore from './SpyRemoteEventStore';
|
|
4
|
+
import SpyRemotePreferencesStore from './SpyRemotePreferencesStore';
|
|
5
|
+
export default class SpyEventManager extends CalendarEventManager {
|
|
6
|
+
updateContext?: UpdateCalendarToolBeltContextHandler<CalendarToolBeltContext>;
|
|
7
|
+
getShouldIgnoreNextContextUpdate(): boolean;
|
|
8
|
+
constructor(options: SpyEventManagerOptions);
|
|
9
|
+
getRemoteEventsStore(): SpyRemoteEventStore;
|
|
10
|
+
getStateMachine(): import("../../types/calendar.types").CalendarToolBeltStateMachine<CalendarToolBeltContext>;
|
|
11
|
+
getPreferences(): SpyRemotePreferencesStore;
|
|
12
|
+
silentlySetAllEvents(events: CalendarEvent[]): void;
|
|
13
|
+
silentlyMixinEvents(events: CalendarEvent[]): void;
|
|
14
|
+
silentlyAddEvent(event: CalendarEvent): void;
|
|
15
|
+
updateEventInContext(updates: Partial<CalendarEvent>): Promise<{
|
|
16
|
+
isBusy: boolean;
|
|
17
|
+
id: string;
|
|
18
|
+
target: import("@sprucelabs/spruce-core-schemas").SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventTarget;
|
|
19
|
+
calendarId: string;
|
|
20
|
+
eventTypeSlug?: string | null | undefined;
|
|
21
|
+
startDateTimeMs: number;
|
|
22
|
+
isResizeable?: boolean | null | undefined;
|
|
23
|
+
style?: "draft" | "tentative" | "upcoming" | "unavailable" | "blocked" | "active" | "past" | "warn" | "critical" | null | undefined;
|
|
24
|
+
groupId?: string | null | undefined;
|
|
25
|
+
timeBlocks: import("@sprucelabs/spruce-core-schemas").SpruceSchemas.CalendarUtils.v2021_05_19.EventTimeBlock[];
|
|
26
|
+
repeats?: "weekly" | "monthly" | "daily" | null | undefined;
|
|
27
|
+
daysOfWeek?: ("sun" | "mon" | "tue" | "wed" | "thur" | "fri" | "sat")[] | null | undefined;
|
|
28
|
+
daysOfMonth?: ("1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" | "18" | "19" | "20" | "21" | "22" | "23" | "24" | "25" | "26" | "27" | "28" | "29" | "30" | "31")[] | null | undefined;
|
|
29
|
+
repeatsUntil?: number | null | undefined;
|
|
30
|
+
occurrences?: number | null | undefined;
|
|
31
|
+
interval?: number | null | undefined;
|
|
32
|
+
nthOccurrences?: number[] | null | undefined;
|
|
33
|
+
activeUntilDate?: number | null | undefined;
|
|
34
|
+
exclusionDates?: import("@sprucelabs/spruce-core-schemas").SpruceSchemas.CalendarUtils.v2021_05_19.EventExclusionDate[] | null | undefined;
|
|
35
|
+
nthInRepeating?: number | null | undefined;
|
|
36
|
+
totalInRepeating?: number | null | undefined;
|
|
37
|
+
error?: Error | null | undefined;
|
|
38
|
+
isSelected?: boolean | null | undefined;
|
|
39
|
+
controller?: import("@sprucelabs/heartwood-view-controllers").CalendarEventViewController | null | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
export declare type SpyEventManagerOptions = CalendarEventManagerOptions;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import CalendarEventManager from '../../utilities/CalendarEventManager.js';
|
|
11
|
+
export default class SpyEventManager extends CalendarEventManager {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
}
|
|
15
|
+
getShouldIgnoreNextContextUpdate() {
|
|
16
|
+
return this.shouldIgnoreNextContextUpdate;
|
|
17
|
+
}
|
|
18
|
+
getRemoteEventsStore() {
|
|
19
|
+
return this.events;
|
|
20
|
+
}
|
|
21
|
+
getStateMachine() {
|
|
22
|
+
return this.sm;
|
|
23
|
+
}
|
|
24
|
+
getPreferences() {
|
|
25
|
+
return this.prefs;
|
|
26
|
+
}
|
|
27
|
+
silentlySetAllEvents(events) {
|
|
28
|
+
this.allEvents = events;
|
|
29
|
+
}
|
|
30
|
+
silentlyMixinEvents(events) {
|
|
31
|
+
this.allEvents = [...this.allEvents, ...events];
|
|
32
|
+
}
|
|
33
|
+
silentlyAddEvent(event) {
|
|
34
|
+
this.allEvents.push(event);
|
|
35
|
+
}
|
|
36
|
+
updateEventInContext(updates) {
|
|
37
|
+
const _super = Object.create(null, {
|
|
38
|
+
updateEventInContext: { get: () => super.updateEventInContext }
|
|
39
|
+
});
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
return _super.updateEventInContext.call(this, updates);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import CalendarPeopleManager, { PeopleManagerOptions, SetVisiblePeolpeOptions } from '../../utilities/CalendarPeopleManager';
|
|
2
|
+
import { PersonMode } from '../../viewControllers/PersonSelectTool.vc';
|
|
3
|
+
export default class SpyPeopleManager extends CalendarPeopleManager {
|
|
4
|
+
visiblePeopleIds?: string[];
|
|
5
|
+
peopleVisibilityMode?: PersonMode;
|
|
6
|
+
constructor(options: PeopleManagerOptions);
|
|
7
|
+
protected getVisiblePeopleIds(): string[];
|
|
8
|
+
getVisibilityMode(): PersonMode;
|
|
9
|
+
setVisiblePeopleIds(ids: string[], options?: SetVisiblePeolpeOptions): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import CalendarPeopleManager from '../../utilities/CalendarPeopleManager.js';
|
|
11
|
+
export default class SpyPeopleManager extends CalendarPeopleManager {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
}
|
|
15
|
+
getVisiblePeopleIds() {
|
|
16
|
+
var _a;
|
|
17
|
+
return (_a = this.visiblePeopleIds) !== null && _a !== void 0 ? _a : super.getVisiblePeopleIds();
|
|
18
|
+
}
|
|
19
|
+
getVisibilityMode() {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = this.peopleVisibilityMode) !== null && _a !== void 0 ? _a : super.getVisibilityMode();
|
|
22
|
+
}
|
|
23
|
+
setVisiblePeopleIds(ids, options) {
|
|
24
|
+
const _super = Object.create(null, {
|
|
25
|
+
setVisiblePeopleIds: { get: () => super.setVisiblePeopleIds }
|
|
26
|
+
});
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
return _super.setVisiblePeopleIds.call(this, ids, options);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MercuryClient } from '@sprucelabs/mercury-client';
|
|
2
|
+
import { SpruceSchemas } from '@sprucelabs/spruce-core-schemas';
|
|
3
|
+
import RemoteEventStoreImpl, { RemoteEventStoreOptions } from '../../stores/RemoteEventStore';
|
|
4
|
+
import { Calendar, UpdateEvent } from '../../types/calendar.types';
|
|
5
|
+
export default class SpyRemoteEventStore extends RemoteEventStoreImpl {
|
|
6
|
+
private calendars?;
|
|
7
|
+
lastPersistedEvent?: SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent;
|
|
8
|
+
constructor(options: Omit<RemoteEventStoreOptions, 'connectToApi'> & {
|
|
9
|
+
calendars?: Calendar[];
|
|
10
|
+
locationId?: string;
|
|
11
|
+
organizationId?: string;
|
|
12
|
+
client: MercuryClient;
|
|
13
|
+
});
|
|
14
|
+
setOrganizationId(id: string): void;
|
|
15
|
+
cancelEvent(_id: string): Promise<void>;
|
|
16
|
+
getCalendars(): Promise<SpruceSchemas.Calendar.v2021_05_19.Calendar[] | import("@sprucelabs/schema").SchemaStaticValues<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema, false, import("@sprucelabs/schema").SchemaOptionalFieldNames<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema>, import("@sprucelabs/schema").StaticSchemaAllValues<SpruceSchemas.Calendar.v2021_05_19.CalendarSchema, false>>[]>;
|
|
17
|
+
persist(event: UpdateEvent): Promise<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { generateId } from '@sprucelabs/test-utils';
|
|
11
|
+
import RemoteEventStoreImpl from '../../stores/RemoteEventStore.js';
|
|
12
|
+
export default class SpyRemoteEventStore extends RemoteEventStoreImpl {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
const { calendars, client, locationId, organizationId } = options;
|
|
15
|
+
super({ connectToApi: () => __awaiter(this, void 0, void 0, function* () { return client; }) });
|
|
16
|
+
this.client = client;
|
|
17
|
+
this.calendars = calendars;
|
|
18
|
+
this.locationId = locationId !== null && locationId !== void 0 ? locationId : generateId();
|
|
19
|
+
this.organizationId = organizationId !== null && organizationId !== void 0 ? organizationId : generateId();
|
|
20
|
+
}
|
|
21
|
+
setOrganizationId(id) {
|
|
22
|
+
this.organizationId = id;
|
|
23
|
+
}
|
|
24
|
+
cancelEvent(_id) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
26
|
+
}
|
|
27
|
+
getCalendars() {
|
|
28
|
+
const _super = Object.create(null, {
|
|
29
|
+
getCalendars: { get: () => super.getCalendars }
|
|
30
|
+
});
|
|
31
|
+
var _a;
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return (_a = this.calendars) !== null && _a !== void 0 ? _a : _super.getCalendars.call(this);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
persist(event) {
|
|
37
|
+
const _super = Object.create(null, {
|
|
38
|
+
persist: { get: () => super.persist }
|
|
39
|
+
});
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const results = yield _super.persist.call(this, event);
|
|
42
|
+
this.lastPersistedEvent = results;
|
|
43
|
+
return results;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MercuryClient } from '@sprucelabs/mercury-client';
|
|
2
|
+
import RemotePreferencesStore from '../../stores/RemotePreferencesStore';
|
|
3
|
+
export default class SpyRemotePreferencesStore extends RemotePreferencesStore {
|
|
4
|
+
constructor(options: {
|
|
5
|
+
client: MercuryClient;
|
|
6
|
+
visibleCalendarIds?: string[];
|
|
7
|
+
});
|
|
8
|
+
protected save(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import RemotePreferencesStore from '../../stores/RemotePreferencesStore.js';
|
|
11
|
+
export default class SpyRemotePreferencesStore extends RemotePreferencesStore {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
const { visibleCalendarIds, client } = options;
|
|
14
|
+
super({ connectToApi: () => __awaiter(this, void 0, void 0, function* () { return client; }) });
|
|
15
|
+
this.client = client;
|
|
16
|
+
this.isLoaded = true;
|
|
17
|
+
this.visibleCalendarIds = visibleCalendarIds;
|
|
18
|
+
}
|
|
19
|
+
save() {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CalendarEvent, SpruceSchemas, ViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
declare type Calendar = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Calendar;
|
|
3
|
+
declare type Event = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
|
|
4
|
+
declare const calendarAssert: {
|
|
5
|
+
rendersTotalEvents(vc: ViewController<Calendar>, expected: number): void;
|
|
6
|
+
hasEvent(vc: ViewController<Calendar>, lookup: Partial<Event>): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
|
|
7
|
+
eventsAreEqual(actual: Event[], expected: Event[]): void;
|
|
8
|
+
includesInEvent(events: Event[], lookup: Partial<Event>): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
|
|
9
|
+
eventIsDuration(event: Event, expectedDuration: number): void;
|
|
10
|
+
eventsFallOnDows(events: CalendarEvent[], expectedDows: string[]): void;
|
|
11
|
+
eventEquals(actual: Partial<CalendarEvent> | undefined | null, expected: Partial<CalendarEvent> | undefined | null): void;
|
|
12
|
+
};
|
|
13
|
+
export default calendarAssert;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { dateUtil } from '@sprucelabs/calendar-utils';
|
|
2
|
+
import { renderUtil, } from '@sprucelabs/heartwood-view-controllers';
|
|
3
|
+
import { assert, assertUtil } from '@sprucelabs/test';
|
|
4
|
+
import clone from 'just-clone';
|
|
5
|
+
const calendarAssert = {
|
|
6
|
+
rendersTotalEvents(vc, expected) {
|
|
7
|
+
const model = renderUtil.render(vc);
|
|
8
|
+
assert.isLength(model.events, expected);
|
|
9
|
+
},
|
|
10
|
+
hasEvent(vc, lookup) {
|
|
11
|
+
const { events } = renderUtil.render(vc);
|
|
12
|
+
return this.includesInEvent(events, lookup);
|
|
13
|
+
},
|
|
14
|
+
eventsAreEqual(actual, expected) {
|
|
15
|
+
function sort(a, b) {
|
|
16
|
+
return a.id > b.id ? 1 : -1;
|
|
17
|
+
}
|
|
18
|
+
actual.sort(sort);
|
|
19
|
+
expected.sort(sort);
|
|
20
|
+
assert.isEqualDeep(actual, expected);
|
|
21
|
+
},
|
|
22
|
+
includesInEvent(events, lookup) {
|
|
23
|
+
const match = events.find((e) => {
|
|
24
|
+
try {
|
|
25
|
+
assert.doesInclude(e, lookup);
|
|
26
|
+
return e;
|
|
27
|
+
// eslint-disable-next-line no-empty
|
|
28
|
+
}
|
|
29
|
+
catch (_a) { }
|
|
30
|
+
return null;
|
|
31
|
+
});
|
|
32
|
+
assert.isTruthy(match, `I could not find an event that matched:\n\n${assertUtil.stringify(lookup)}`);
|
|
33
|
+
return match;
|
|
34
|
+
},
|
|
35
|
+
eventIsDuration(event, expectedDuration) {
|
|
36
|
+
const duration = event.timeBlocks.reduce((minutes, timeBlock) => {
|
|
37
|
+
minutes += timeBlock.durationMinutes;
|
|
38
|
+
return minutes;
|
|
39
|
+
}, 0);
|
|
40
|
+
assert.isEqual(duration, expectedDuration);
|
|
41
|
+
},
|
|
42
|
+
eventsFallOnDows(events, expectedDows) {
|
|
43
|
+
const remaining = [...expectedDows];
|
|
44
|
+
for (const event of events) {
|
|
45
|
+
const dow = dateUtil.getDayOfWeek(event.startDateTimeMs);
|
|
46
|
+
const idx = remaining.indexOf(dow);
|
|
47
|
+
if (idx === -1) {
|
|
48
|
+
assert.fail(`Checking days of week and got ${dow} but it wasn't in the array of expected dows.`);
|
|
49
|
+
}
|
|
50
|
+
remaining.splice(idx, 1);
|
|
51
|
+
}
|
|
52
|
+
if (remaining.length > 0) {
|
|
53
|
+
assert.fail(`Didn't find the following days of week in events:\n\n${assertUtil.stringify(remaining)}`);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
eventEquals(actual, expected) {
|
|
57
|
+
var _a, _b, _c;
|
|
58
|
+
assert.isTruthy(actual, 'Event is missing');
|
|
59
|
+
assert.isTruthy(expected, 'Event is missing');
|
|
60
|
+
assert.isEqual(actual.startDateTimeMs, expected.startDateTimeMs, 'startDateTimeMs does not match');
|
|
61
|
+
assert.isEqual((_a = actual.isBusy) !== null && _a !== void 0 ? _a : false, (_b = expected.isBusy) !== null && _b !== void 0 ? _b : false, `isBusy does not match, needs to be '${(_c = expected.isBusy) !== null && _c !== void 0 ? _c : false}'`);
|
|
62
|
+
const cleanedActual = clone(actual);
|
|
63
|
+
const cleanedExpected = clone(expected);
|
|
64
|
+
cleanEvent(cleanedActual);
|
|
65
|
+
cleanEvent(cleanedExpected);
|
|
66
|
+
assert.isEqualDeep(cleanedActual, cleanedExpected, 'Your event did not equal what I expected!');
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
function cleanEvent(obj, propsToIgnore = [
|
|
70
|
+
'isSelected',
|
|
71
|
+
'source',
|
|
72
|
+
'dateCreated',
|
|
73
|
+
'isBusy',
|
|
74
|
+
'controller',
|
|
75
|
+
]) {
|
|
76
|
+
for (const prop in obj) {
|
|
77
|
+
const value = obj[prop];
|
|
78
|
+
if (propsToIgnore.indexOf(prop) > -1 ||
|
|
79
|
+
value === null ||
|
|
80
|
+
typeof value === 'undefined') {
|
|
81
|
+
delete obj[prop];
|
|
82
|
+
}
|
|
83
|
+
else if (typeof value === 'object') {
|
|
84
|
+
cleanEvent(value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export default calendarAssert;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ToolBeltState, AbstractCalendarEventViewController, ToolBeltStateMachine, SpruceSchemas } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { MercuryClient } from '@sprucelabs/mercury-client';
|
|
3
|
+
import { ViewFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
4
|
+
import AbstractCalendarEventToolBeltState from '../../../toolBelt/states/AbstractCalendarEventToolBeltState';
|
|
5
|
+
export interface AssertRemoteToolsOptions {
|
|
6
|
+
client: MercuryClient;
|
|
7
|
+
state: ToolBeltState;
|
|
8
|
+
views: ViewFixture;
|
|
9
|
+
}
|
|
10
|
+
interface TypeWithVcId {
|
|
11
|
+
typeSlug: string;
|
|
12
|
+
vcId: string;
|
|
13
|
+
}
|
|
14
|
+
export declare type AssertTypeSlug = string | TypeWithVcId;
|
|
15
|
+
declare const calendarSkillAssert: {
|
|
16
|
+
createdEventTypes: SpruceSchemas.Calendar.v2021_05_19.CalendarEventType[];
|
|
17
|
+
createdCalendars: SpruceSchemas.Calendar.v2021_05_19.Calendar[];
|
|
18
|
+
beforeEach(views: ViewFixture): Promise<void>;
|
|
19
|
+
createsCalendarOnInstall(calendarSlug: string, client: MercuryClient, typeSlugs?: string[]): Promise<void>;
|
|
20
|
+
createsCalendarsWithMultipleInstalls(calendarSlug: string, client: MercuryClient): Promise<void>;
|
|
21
|
+
createsEventTypesOnBoot(types: AssertTypeSlug[], client: MercuryClient, boot: () => Promise<any>): Promise<void>;
|
|
22
|
+
createsEventTypesWithMultipleBoots(types: AssertTypeSlug[], client: MercuryClient, boot: () => Promise<any>): Promise<void>;
|
|
23
|
+
isValidEventViewController(options: {
|
|
24
|
+
views: ViewFixture;
|
|
25
|
+
CalendarEventClass: typeof AbstractCalendarEventViewController;
|
|
26
|
+
ToolBeltStateClass: any;
|
|
27
|
+
}): void;
|
|
28
|
+
stateFetchesAndRendersRemoteTools(options: AssertRemoteToolsOptions): Promise<{
|
|
29
|
+
toolId: string;
|
|
30
|
+
Class: any;
|
|
31
|
+
}[]>;
|
|
32
|
+
toolBeltStateProperlyInheritsAbstractToolBeltState(stateMachine: ToolBeltStateMachine, state: AbstractCalendarEventToolBeltState): Promise<void>;
|
|
33
|
+
toolBeltStateAddsTool(options: {
|
|
34
|
+
state: AbstractCalendarEventToolBeltState;
|
|
35
|
+
toolId: string;
|
|
36
|
+
views: ViewFixture;
|
|
37
|
+
Class?: any;
|
|
38
|
+
}): Promise<SpruceSchemas.HeartwoodViewControllers.v2021_02_11.ToolBeltTool>;
|
|
39
|
+
};
|
|
40
|
+
export default calendarSkillAssert;
|