@sprucelabs/spruce-calendar-components 22.7.11 → 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/__tests__/support/CalendarToolBeltStateMachineTestFactory.d.ts +39 -0
- package/build/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +105 -0
- package/build/esm/__tests__/support/CalendarToolBeltStateMachineTestFactory.d.ts +39 -0
- package/build/esm/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +126 -0
- package/package.json +6 -2
|
@@ -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,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FakeRemoteEventStore = void 0;
|
|
7
|
+
const calendar_utils_1 = require("@sprucelabs/calendar-utils");
|
|
8
|
+
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
9
|
+
const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
10
|
+
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
11
|
+
const RemotePreferencesStore_1 = __importDefault(require("../../stores/RemotePreferencesStore"));
|
|
12
|
+
const draftGenerator_1 = __importDefault(require("../../utilities/draftGenerator"));
|
|
13
|
+
const Calendar_vc_1 = __importDefault(require("../../viewControllers/Calendar.vc"));
|
|
14
|
+
const SpyEventManager_1 = __importDefault(require("./SpyEventManager"));
|
|
15
|
+
const SpyPeopleManager_1 = __importDefault(require("./SpyPeopleManager"));
|
|
16
|
+
class CalendarToolBeltStateMachineTestFactory {
|
|
17
|
+
static async StateMachine(views) {
|
|
18
|
+
const factory = views.getFactory();
|
|
19
|
+
if (!factory.hasController('calendar.calendar')) {
|
|
20
|
+
factory.mixinControllers({
|
|
21
|
+
//@ts-ignore
|
|
22
|
+
'calendar.calendar': Calendar_vc_1.default,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const toolBeltVc = views.Controller('toolBelt', {});
|
|
26
|
+
const event = heartwood_view_controllers_1.calendarSeeder.generateEventValues();
|
|
27
|
+
const calendarVc = views.Controller('calendar.calendar', {
|
|
28
|
+
onAddDraftEvent: () => { },
|
|
29
|
+
onEventSwapped(draft, saved) {
|
|
30
|
+
return events.silentlySwapEvent(draft.id, saved);
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
calendarVc.addEvent(event);
|
|
34
|
+
const sm = new heartwood_view_controllers_1.ToolBeltStateMachine({
|
|
35
|
+
vcFactory: views.getFactory(),
|
|
36
|
+
toolBeltVc,
|
|
37
|
+
connectToApi: async () => spruce_test_fixtures_1.fake.getClient(),
|
|
38
|
+
context: Object.assign(Object.assign({}, views.getRouter().buildLoadOptions()), { event,
|
|
39
|
+
calendarVc, cancelEvent: () => { } }),
|
|
40
|
+
});
|
|
41
|
+
const connectToApi = async () => spruce_test_fixtures_1.fake.getClient();
|
|
42
|
+
const preferences = new FakeRemotePreferences({ connectToApi });
|
|
43
|
+
const remoteEventsStore = new FakeRemoteEventStore();
|
|
44
|
+
const events = new SpyEventManager_1.default({
|
|
45
|
+
calendarVc,
|
|
46
|
+
sm,
|
|
47
|
+
dates: calendar_utils_1.dateUtil,
|
|
48
|
+
remoteVc: {
|
|
49
|
+
fetchRemoteController: async (name) => factory.getController(name),
|
|
50
|
+
},
|
|
51
|
+
askForUpdateStrategy: async () => {
|
|
52
|
+
return 'all';
|
|
53
|
+
},
|
|
54
|
+
events: remoteEventsStore,
|
|
55
|
+
preferences,
|
|
56
|
+
});
|
|
57
|
+
await events.load();
|
|
58
|
+
events.silentlyAddEvent(event);
|
|
59
|
+
const people = new SpyPeopleManager_1.default({
|
|
60
|
+
calendarVc,
|
|
61
|
+
connectToApi,
|
|
62
|
+
preferences,
|
|
63
|
+
getVisibleEvents: () => [],
|
|
64
|
+
});
|
|
65
|
+
await sm.updateContext({ events, people });
|
|
66
|
+
await sm.on('did-update-context', () => {
|
|
67
|
+
calendarVc.updateEvent(event.id, Object.assign({}, sm.getContext().event));
|
|
68
|
+
});
|
|
69
|
+
//@ts-ignore
|
|
70
|
+
return { stateMachine: sm, toolBeltVc, calendarVc, events };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.default = CalendarToolBeltStateMachineTestFactory;
|
|
74
|
+
class FakeRemotePreferences extends RemotePreferencesStore_1.default {
|
|
75
|
+
async loadPreferences() { }
|
|
76
|
+
async save() { }
|
|
77
|
+
}
|
|
78
|
+
class FakeRemoteEventStore {
|
|
79
|
+
async load(_options) { }
|
|
80
|
+
async persist(event) {
|
|
81
|
+
const e = Object.assign(Object.assign({ dateCreated: new Date().getTime() }, heartwood_view_controllers_1.calendarSeeder.generateEventValues()), event);
|
|
82
|
+
if (draftGenerator_1.default.isDraftId(e.id)) {
|
|
83
|
+
e.id = (0, test_utils_1.generateId)();
|
|
84
|
+
}
|
|
85
|
+
this.lastPersistedEvent = e;
|
|
86
|
+
return e;
|
|
87
|
+
}
|
|
88
|
+
setCalendarId(_id) { }
|
|
89
|
+
clearCalendarId() { }
|
|
90
|
+
getCalendarId() {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
async waitForPendingSaves() { }
|
|
94
|
+
async cancelEvent(_id) { }
|
|
95
|
+
async getSchedules(_options) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
async getEventTypes() {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
async getCalendars() {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.FakeRemoteEventStore = FakeRemoteEventStore;
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sprucelabs/spruce-calendar-components",
|
|
3
3
|
"description": "Calendar components for working with calendars and Sprucebot.",
|
|
4
|
-
"version": "22.7.
|
|
4
|
+
"version": "22.7.12",
|
|
5
5
|
"skill": {
|
|
6
6
|
"namespace": "calendar"
|
|
7
7
|
},
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
"module": "./build/esm/index-components.js",
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"files": [
|
|
17
|
+
"build/__tests__/support/CalendarToolBeltStateMachineTestFactory.js",
|
|
18
|
+
"build/__tests__/support/CalendarToolBeltStateMachineTestFactory.d.ts",
|
|
19
|
+
"build/esm/__tests__/support/CalendarToolBeltStateMachineTestFactory.js",
|
|
20
|
+
"build/esm/__tests__/support/CalendarToolBeltStateMachineTestFactory.d.ts",
|
|
17
21
|
"build/__tests__/support/SpyEventManager.js",
|
|
18
22
|
"build/__tests__/support/SpyEventManager.d.ts",
|
|
19
23
|
"build/esm/__tests__/support/SpyEventManager.js",
|
|
@@ -166,7 +170,7 @@
|
|
|
166
170
|
"build/noSchedules/peopleToPeopleWithoutSchedules.d.ts",
|
|
167
171
|
"build/esm/noSchedules/peopleToPeopleWithoutSchedules.js",
|
|
168
172
|
"build/esm/noSchedules/peopleToPeopleWithoutSchedules.d.ts"
|
|
169
|
-
],
|
|
173
|
+
],
|
|
170
174
|
"keywords": [],
|
|
171
175
|
"scripts": {
|
|
172
176
|
"release": "npm publish"
|