@sprucelabs/spruce-calendar-components 22.7.2 → 22.7.6
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/esm/index-components.d.ts +1 -0
- package/build/esm/index-components.js +1 -0
- package/build/esm/noSchedules/peopleToPeopleWithoutSchedules.d.ts +3 -0
- package/build/esm/noSchedules/peopleToPeopleWithoutSchedules.js +7 -0
- package/build/index-components.d.ts +1 -0
- package/build/index-components.js +3 -1
- package/build/noSchedules/peopleToPeopleWithoutSchedules.d.ts +3 -0
- package/build/noSchedules/peopleToPeopleWithoutSchedules.js +10 -0
- package/package.json +5 -33
- package/build/__tests__/support/CalendarToolBeltStateMachineTestFactory.d.ts +0 -39
- package/build/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +0 -105
- package/build/__tests__/support/SpyEventManager.d.ts +0 -42
- package/build/__tests__/support/SpyEventManager.js +0 -36
- package/build/__tests__/support/SpyPeopleManager.d.ts +0 -10
- package/build/__tests__/support/SpyPeopleManager.js +0 -23
- package/build/__tests__/support/SpyRemoteEventStore.d.ts +0 -18
- package/build/__tests__/support/SpyRemoteEventStore.js +0 -31
- package/build/__tests__/support/SpyRemotePreferencesStore.d.ts +0 -9
- package/build/__tests__/support/SpyRemotePreferencesStore.js +0 -17
- package/build/__tests__/support/utilities/calendarAssert.d.ts +0 -13
- package/build/__tests__/support/utilities/calendarAssert.js +0 -93
- package/build/__tests__/support/utilities/calendarSkillAssert.d.ts +0 -40
- package/build/__tests__/support/utilities/calendarSkillAssert.js +0 -346
- package/build/__tests__/support/utilities/calendarToolBeltInteractor.d.ts +0 -5
- package/build/__tests__/support/utilities/calendarToolBeltInteractor.js +0 -11
- package/build/esm/__tests__/support/CalendarToolBeltStateMachineTestFactory.d.ts +0 -39
- package/build/esm/__tests__/support/CalendarToolBeltStateMachineTestFactory.js +0 -126
- package/build/esm/__tests__/support/SpyEventManager.d.ts +0 -42
- package/build/esm/__tests__/support/SpyEventManager.js +0 -44
- package/build/esm/__tests__/support/SpyPeopleManager.d.ts +0 -10
- package/build/esm/__tests__/support/SpyPeopleManager.js +0 -31
- package/build/esm/__tests__/support/SpyRemoteEventStore.d.ts +0 -18
- package/build/esm/__tests__/support/SpyRemoteEventStore.js +0 -46
- package/build/esm/__tests__/support/SpyRemotePreferencesStore.d.ts +0 -9
- package/build/esm/__tests__/support/SpyRemotePreferencesStore.js +0 -22
- package/build/esm/__tests__/support/utilities/calendarAssert.d.ts +0 -13
- package/build/esm/__tests__/support/utilities/calendarAssert.js +0 -88
- package/build/esm/__tests__/support/utilities/calendarSkillAssert.d.ts +0 -40
- package/build/esm/__tests__/support/utilities/calendarSkillAssert.js +0 -372
- package/build/esm/__tests__/support/utilities/calendarToolBeltInteractor.d.ts +0 -5
- package/build/esm/__tests__/support/utilities/calendarToolBeltInteractor.js +0 -20
|
@@ -1,346 +0,0 @@
|
|
|
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
|
-
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
7
|
-
const schema_1 = require("@sprucelabs/schema");
|
|
8
|
-
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
|
|
9
|
-
const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
10
|
-
const test_1 = require("@sprucelabs/test");
|
|
11
|
-
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
12
|
-
const AbstractCalendarEventToolBeltState_1 = __importDefault(require("../../../toolBelt/states/AbstractCalendarEventToolBeltState"));
|
|
13
|
-
const Calendar_vc_1 = __importDefault(require("../../../viewControllers/Calendar.vc"));
|
|
14
|
-
const EventControlsCard_vc_1 = __importDefault(require("../../../viewControllers/EventControlsCard.vc"));
|
|
15
|
-
const EventDateTimeTool_vc_1 = __importDefault(require("../../../viewControllers/EventDateTimeTool.vc"));
|
|
16
|
-
const EventRepeatingTool_vc_1 = __importDefault(require("../../../viewControllers/EventRepeatingTool.vc"));
|
|
17
|
-
const EventTitleTool_vc_1 = __importDefault(require("../../../viewControllers/EventTitleTool.vc"));
|
|
18
|
-
const RepeatingControlsList_vc_1 = __importDefault(require("../../../viewControllers/RepeatingControlsList.vc"));
|
|
19
|
-
const CalendarToolBeltStateMachineTestFactory_1 = __importDefault(require("../CalendarToolBeltStateMachineTestFactory"));
|
|
20
|
-
class TestTool1 extends heartwood_view_controllers_1.CardViewControllerImpl {
|
|
21
|
-
async handleUpdateContext() { }
|
|
22
|
-
getLineIcon() {
|
|
23
|
-
return 'cellphone';
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
class TestTool2 extends heartwood_view_controllers_1.CardViewControllerImpl {
|
|
27
|
-
handleUpdateContext() { }
|
|
28
|
-
getLineIcon() {
|
|
29
|
-
return 'calendar';
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const vcs = {
|
|
33
|
-
['calendar.repeating-controls-list']: RepeatingControlsList_vc_1.default,
|
|
34
|
-
['calendar.event-repeating-tool']: EventRepeatingTool_vc_1.default,
|
|
35
|
-
['calendar.calendar']: Calendar_vc_1.default,
|
|
36
|
-
['calendar.event-date-time-tool']: EventDateTimeTool_vc_1.default,
|
|
37
|
-
['calendar.event-title-tool']: EventTitleTool_vc_1.default,
|
|
38
|
-
['calendar.event-controls-card']: EventControlsCard_vc_1.default,
|
|
39
|
-
};
|
|
40
|
-
const calendarSkillAssert = {
|
|
41
|
-
createdEventTypes: [],
|
|
42
|
-
createdCalendars: [],
|
|
43
|
-
async beforeEach(views) {
|
|
44
|
-
(0, schema_1.assertOptions)({ views }, ['views']);
|
|
45
|
-
//@ts-ignore
|
|
46
|
-
this._didBeforeEach = true;
|
|
47
|
-
this.createdEventTypes = [];
|
|
48
|
-
this.createdCalendars = [];
|
|
49
|
-
const factory = views.getFactory();
|
|
50
|
-
factory.mixinControllers(vcs);
|
|
51
|
-
await spruce_test_fixtures_1.eventFaker.on('calendar.register-event-tools::v2021_05_19', () => ({
|
|
52
|
-
vcIds: [],
|
|
53
|
-
}));
|
|
54
|
-
await fakeEventTypeEvents(this.createdEventTypes);
|
|
55
|
-
await fakeCalendarEvents(this.createdCalendars);
|
|
56
|
-
},
|
|
57
|
-
async createsCalendarOnInstall(calendarSlug, client, typeSlugs) {
|
|
58
|
-
var _a, _b, _c, _d;
|
|
59
|
-
assertRanBeforeEach(this);
|
|
60
|
-
(0, schema_1.assertOptions)({
|
|
61
|
-
calendarSlug,
|
|
62
|
-
client,
|
|
63
|
-
}, ['calendarSlug', 'client']);
|
|
64
|
-
const [{ organizations }] = await client.emitAndFlattenResponses('list-organizations::v2020_12_25', {
|
|
65
|
-
payload: {
|
|
66
|
-
shouldOnlyShowMine: true,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
const organization = organizations.pop();
|
|
70
|
-
test_1.assert.isTruthy(organization, `You gotta @seed('organizations', 1) before you can assert a calendar is created on install.`);
|
|
71
|
-
const skill = spruce_skill_utils_1.AuthService.Auth(process.cwd()).getCurrentSkill();
|
|
72
|
-
test_1.assert.isTruthy(skill, `Make sure you registered your skill before you can do anything else. Try 'spruce register'.`);
|
|
73
|
-
const responses = await client.emit('did-install::v2020_12_25', {
|
|
74
|
-
target: {
|
|
75
|
-
organizationId: organization.id,
|
|
76
|
-
skillId: skill.id,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
if (responses.totalErrors > 0) {
|
|
80
|
-
throw (_b = (_a = responses.responses[0].errors) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : `did-instal error`;
|
|
81
|
-
}
|
|
82
|
-
if (responses.totalResponses === 0) {
|
|
83
|
-
test_1.assert.fail(`did-install listener missing! To get this test passing your skill will need to be listening to did-install, try 'spruce create.listener' and look under Mercury. You may also need to boot your skill with 'await this.bootSkill()'`);
|
|
84
|
-
}
|
|
85
|
-
let cal;
|
|
86
|
-
try {
|
|
87
|
-
const [{ calendar }] = await client.emitAndFlattenResponses('calendar.get-calendar::v2021_05_19', {
|
|
88
|
-
target: {
|
|
89
|
-
slug: calendarSlug,
|
|
90
|
-
organizationId: organization.id,
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
cal = calendar;
|
|
94
|
-
}
|
|
95
|
-
catch (err) {
|
|
96
|
-
test_1.assert.fail(`It looks like you still need to create a calendar, maybe the following code will help:
|
|
97
|
-
const events = event.skill.getFeatureByCode('event') as EventFeature
|
|
98
|
-
const client = await events.connectToApi()
|
|
99
|
-
|
|
100
|
-
await client.emitAndFlattenResponses(
|
|
101
|
-
'calendar.create-calendar::v2021_05_19',
|
|
102
|
-
{
|
|
103
|
-
target: {
|
|
104
|
-
organizationId,
|
|
105
|
-
},
|
|
106
|
-
payload: {
|
|
107
|
-
availableTimeSlotBehavior: 'exclude or exclude',
|
|
108
|
-
title: '${calendarSlug}',
|
|
109
|
-
slug: '${calendarSlug}',
|
|
110
|
-
},
|
|
111
|
-
}
|
|
112
|
-
)\n\nOh, and here's the original error: ${(_d = (_c = err.stack) !== null && _c !== void 0 ? _c : err.message) !== null && _d !== void 0 ? _d : err}`);
|
|
113
|
-
}
|
|
114
|
-
if (typeSlugs) {
|
|
115
|
-
test_1.assert.isEqualDeep(cal.eventTypes, typeSlugs, `Your calendar does not have types set to: [${typeSlugs.join(', ')}]`);
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
async createsCalendarsWithMultipleInstalls(calendarSlug, client) {
|
|
119
|
-
await this.createsCalendarOnInstall(calendarSlug, client);
|
|
120
|
-
try {
|
|
121
|
-
await this.createsCalendarOnInstall(calendarSlug, client);
|
|
122
|
-
}
|
|
123
|
-
catch (err) {
|
|
124
|
-
test_1.assert.fail(`You tried to create the same calendar twice! It's time for the next step (don't forget to extract):
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
await client.emitAndFlattenResponses('calendar.get-calendar::v2021_05_19', {
|
|
128
|
-
target: {
|
|
129
|
-
organizationId,
|
|
130
|
-
slug: 'shifts',
|
|
131
|
-
},
|
|
132
|
-
})
|
|
133
|
-
} catch {
|
|
134
|
-
await client.emitAndFlattenResponses(
|
|
135
|
-
'calendar.create-calendar::v2021_05_19',
|
|
136
|
-
{
|
|
137
|
-
target: {
|
|
138
|
-
organizationId,
|
|
139
|
-
},
|
|
140
|
-
payload: {
|
|
141
|
-
availableTimeSlotBehavior: 'exclude or include',
|
|
142
|
-
title: 'Shifts',
|
|
143
|
-
slug: 'shifts',
|
|
144
|
-
},
|
|
145
|
-
}
|
|
146
|
-
)
|
|
147
|
-
}`);
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
async createsEventTypesOnBoot(types, client, boot) {
|
|
151
|
-
assertRanBeforeEach(this);
|
|
152
|
-
await (boot === null || boot === void 0 ? void 0 : boot());
|
|
153
|
-
test_1.assert.isTruthy(
|
|
154
|
-
//@ts-ignore
|
|
155
|
-
client.auth.skill, `You gotta be logged in as a skill! Try 'const { client } = await this.skills.loginAsCurrentSkill()'`);
|
|
156
|
-
const typeSlugs = types.map((t) => (typeof t === 'string' ? t : t.typeSlug));
|
|
157
|
-
const vcIds = types.map((t) => (typeof t === 'string' ? undefined : t.vcId));
|
|
158
|
-
function sort(a, b) {
|
|
159
|
-
return a.typeSlug > b.typeSlug ? 1 : -1;
|
|
160
|
-
}
|
|
161
|
-
const normalizedExpected = typeSlugs
|
|
162
|
-
.map((slug, idx) => ({
|
|
163
|
-
typeSlug: slug,
|
|
164
|
-
viewControllerId: vcIds[idx],
|
|
165
|
-
}))
|
|
166
|
-
.sort(sort);
|
|
167
|
-
const [{ calendarEventTypes }] = await client.emitAndFlattenResponses('calendar.list-calendar-event-types::v2021_05_19', {
|
|
168
|
-
payload: {
|
|
169
|
-
shouldShowOnlyMine: true,
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
test_1.assert.isAbove(calendarEventTypes.length, 0, `No event types were created. Make sure you are listening to the 'did-boot' event and booted. Use 'spruce create.listener' and look under Skill (or await this.bootSkill()). Then, drop in something like this:\n\n
|
|
173
|
-
await client.emitAndFlattenResponses('calendar.create-calendar-event-type::v2021_05_19', {
|
|
174
|
-
payload: {
|
|
175
|
-
name: '${typeSlugs[0]}',
|
|
176
|
-
slug: '${typeSlugs[0]}'
|
|
177
|
-
}
|
|
178
|
-
})`);
|
|
179
|
-
const normalizedActual = calendarEventTypes
|
|
180
|
-
.map((cet) => ({
|
|
181
|
-
typeSlug: cet.slug,
|
|
182
|
-
viewControllerId: cet.viewControllerId,
|
|
183
|
-
}))
|
|
184
|
-
.sort(sort);
|
|
185
|
-
test_1.assert.isEqualDeep(normalizedActual, normalizedExpected, 'The event types I was found were not created as expected.');
|
|
186
|
-
},
|
|
187
|
-
async createsEventTypesWithMultipleBoots(types, client, boot) {
|
|
188
|
-
await this.createsEventTypesOnBoot(types, client, boot);
|
|
189
|
-
await this.createsEventTypesOnBoot(types, client, boot);
|
|
190
|
-
},
|
|
191
|
-
isValidEventViewController(options) {
|
|
192
|
-
const { views, ToolBeltStateClass: ToolBeltClass, CalendarEventClass, } = (0, schema_1.assertOptions)(options, [
|
|
193
|
-
'views',
|
|
194
|
-
'CalendarEventClass',
|
|
195
|
-
'ToolBeltStateClass',
|
|
196
|
-
]);
|
|
197
|
-
const event = heartwood_view_controllers_1.calendarSeeder.generateEventValues();
|
|
198
|
-
const calendarVc = views.Controller('calendar', {
|
|
199
|
-
events: [event],
|
|
200
|
-
});
|
|
201
|
-
//@ts-ignore
|
|
202
|
-
views.getFactory().mixinControllers({
|
|
203
|
-
[event.id]: CalendarEventClass,
|
|
204
|
-
});
|
|
205
|
-
calendarVc.setDefaultControllerForEvents(event.id);
|
|
206
|
-
const vc = calendarVc.getEventVc(event.id);
|
|
207
|
-
test_1.assert.isFunction(vc.getToolBeltState, `Bad event vc. You need to make sure your event vc extends and implements what it needs to! Try:
|
|
208
|
-
|
|
209
|
-
class MyEventViewController
|
|
210
|
-
extends AbstractCalendarEventViewController
|
|
211
|
-
implements EventWithToolBeltState`);
|
|
212
|
-
const state = vc.getToolBeltState();
|
|
213
|
-
test_1.assert.isTrue(state instanceof ToolBeltClass, `Your event vc did not return the state I expected. Make sure getToolBeltState() is returning an instance of ${ToolBeltClass.name}.`);
|
|
214
|
-
},
|
|
215
|
-
async stateFetchesAndRendersRemoteTools(options) {
|
|
216
|
-
assertRanBeforeEach(this);
|
|
217
|
-
const { views, state } = (0, schema_1.assertOptions)(options, ['state', 'views']);
|
|
218
|
-
const event = Object.assign(Object.assign({}, heartwood_view_controllers_1.calendarSeeder.generateEventValues()), { eventTypeSlug: (0, test_utils_1.generateId)() });
|
|
219
|
-
const org = await views.getScope().getCurrentOrganization();
|
|
220
|
-
test_1.assert.isTruthy(org, `You gotta @seed('organizations', 1) to test fetching and rendering remote tools.`);
|
|
221
|
-
let passedTargetAndPayload;
|
|
222
|
-
const VC_NAME_1 = 'calendars.test-one';
|
|
223
|
-
const VC_NAME_2 = 'calendars.test-two';
|
|
224
|
-
const vcIds = [VC_NAME_1, VC_NAME_2];
|
|
225
|
-
const Classes = [TestTool1, TestTool2];
|
|
226
|
-
views.getFactory().mixinControllers({
|
|
227
|
-
[VC_NAME_1]: TestTool1,
|
|
228
|
-
[VC_NAME_2]: TestTool2,
|
|
229
|
-
});
|
|
230
|
-
await spruce_test_fixtures_1.eventFaker.on('calendar.register-event-tools::v2021_05_19', (targetAndPayload) => {
|
|
231
|
-
passedTargetAndPayload = targetAndPayload;
|
|
232
|
-
return {
|
|
233
|
-
vcIds,
|
|
234
|
-
};
|
|
235
|
-
});
|
|
236
|
-
const { toolBeltVc, stateMachine } = await CalendarToolBeltStateMachineTestFactory_1.default.StateMachine(views);
|
|
237
|
-
await stateMachine.updateContext({ event });
|
|
238
|
-
await stateMachine.transitionTo(state);
|
|
239
|
-
test_1.assert.isTruthy(passedTargetAndPayload, `You aren't emitting 'calendar.register-event-tools::v2021_05_19'.
|
|
240
|
-
|
|
241
|
-
Try adding the following to your state's load():
|
|
242
|
-
|
|
243
|
-
const tools = new CalendarToolRegistrar(stateMachine)
|
|
244
|
-
await tools.fetchAndAddCards()
|
|
245
|
-
`);
|
|
246
|
-
test_1.assert.isEqualDeep(passedTargetAndPayload.target, { organizationId: org.id, calendarEventId: event.id }, `Your target is not what is expected! Make sure you are sending organizationId and calendarEventId`);
|
|
247
|
-
test_1.assert.isEqualDeep(passedTargetAndPayload.payload, {
|
|
248
|
-
eventTypeSlug: event.eventTypeSlug,
|
|
249
|
-
}, `Your payload does not what is expected! Make sure you pass through eventTypeSlug.`);
|
|
250
|
-
const tools = toolBeltVc.getTools();
|
|
251
|
-
test_1.assert.isAbove(tools.length, 0, `It looks like you didn't add any tools to the tool belt! try sm.getToolBeltVc().addTool()`);
|
|
252
|
-
const results = [];
|
|
253
|
-
for (let c = 0; c < vcIds.length; c++) {
|
|
254
|
-
const id = vcIds[c];
|
|
255
|
-
const tool = toolBeltVc.getTool(id);
|
|
256
|
-
results.push({
|
|
257
|
-
toolId: id,
|
|
258
|
-
Class: Classes[c],
|
|
259
|
-
});
|
|
260
|
-
test_1.assert.isTruthy(tool, `You didn't add the tools I expected! Make sure you are using the CalendarToolRegistrar!`);
|
|
261
|
-
}
|
|
262
|
-
return results;
|
|
263
|
-
},
|
|
264
|
-
async toolBeltStateProperlyInheritsAbstractToolBeltState(stateMachine, state) {
|
|
265
|
-
assertRanBeforeEach(this);
|
|
266
|
-
(0, schema_1.assertOptions)({ stateMachine, state }, ['stateMachine', 'state']);
|
|
267
|
-
test_1.assert.isTrue(state instanceof AbstractCalendarEventToolBeltState_1.default, `Your state does not extend 'AbstractCalendarEventToolBeltState'. Make sure you do that next!`);
|
|
268
|
-
await stateMachine.transitionTo(state);
|
|
269
|
-
test_1.assert.isTruthy(state.getIsLoaded(), `You need to call super.load(stateMachine) in your state!`);
|
|
270
|
-
await stateMachine.on('did-update-context', () => { });
|
|
271
|
-
const originalListenCount = stateMachine.listenCount('did-update-context');
|
|
272
|
-
await state.destroy();
|
|
273
|
-
const count = stateMachine.listenCount('did-update-context');
|
|
274
|
-
test_1.assert.isAbove(count, originalListenCount - 2, `You 'sm.off(...)'ed too many listeners, make sure you pass the callback to remove to 'this.sm.off(...)'. It's the second param.`);
|
|
275
|
-
test_1.assert.isEqual(count, originalListenCount - 1, `Don't forget to remove all listeners to the stateMachine. Either implement 'destroy()' and call 'this.sm.off(...)' or try 'await super.destroy()' in your state.`);
|
|
276
|
-
},
|
|
277
|
-
async toolBeltStateAddsTool(options) {
|
|
278
|
-
const { state, toolId, views, Class } = (0, schema_1.assertOptions)(options, [
|
|
279
|
-
'state',
|
|
280
|
-
'toolId',
|
|
281
|
-
'views',
|
|
282
|
-
]);
|
|
283
|
-
const { toolBeltVc, stateMachine } = await CalendarToolBeltStateMachineTestFactory_1.default.StateMachine(views);
|
|
284
|
-
await stateMachine.transitionTo(state);
|
|
285
|
-
test_1.assert.isTruthy(toolBeltVc.getTool(toolId), `I could not find the tool with the id '${toolId}', try 'this.addTool(...)' from inside your state!`);
|
|
286
|
-
//@ts-ignore
|
|
287
|
-
const match = state.vcs.find((o) => o.toolId === toolId);
|
|
288
|
-
test_1.assert.isTruthy(match, `It looks like you added your tool directly to the toolBeltVc instead of to your parent class. 'this.addTool(...)'`);
|
|
289
|
-
if (Class) {
|
|
290
|
-
heartwood_view_controllers_1.vcAssert.assertToolInstanceOf(toolBeltVc, toolId, Class);
|
|
291
|
-
}
|
|
292
|
-
return toolBeltVc.getTool(toolId);
|
|
293
|
-
},
|
|
294
|
-
};
|
|
295
|
-
exports.default = calendarSkillAssert;
|
|
296
|
-
async function fakeEventTypeEvents(eventTypes) {
|
|
297
|
-
await spruce_test_fixtures_1.eventFaker.on('calendar.list-calendar-event-types::v2021_05_19', ({ source }) => {
|
|
298
|
-
const matches = eventTypes.filter((t) => t.source.skillId === (source === null || source === void 0 ? void 0 : source.skillId));
|
|
299
|
-
return {
|
|
300
|
-
calendarEventTypes: matches,
|
|
301
|
-
count: matches.length,
|
|
302
|
-
};
|
|
303
|
-
});
|
|
304
|
-
await spruce_test_fixtures_1.eventFaker.on('calendar.create-calendar-event-type::v2021_05_19', ({ payload, source }) => {
|
|
305
|
-
const type = Object.assign({ id: (0, test_utils_1.generateId)(), source: source, viewControllerId: null }, payload);
|
|
306
|
-
eventTypes.push(type);
|
|
307
|
-
return {
|
|
308
|
-
calendarEventType: type,
|
|
309
|
-
};
|
|
310
|
-
});
|
|
311
|
-
await spruce_test_fixtures_1.eventFaker.on('calendar.upsert-calendar-event-type::v2021_05_19', ({ payload, source, target }) => {
|
|
312
|
-
const match = eventTypes.find((t) => t.slug === target.slug);
|
|
313
|
-
if (match) {
|
|
314
|
-
match.name = payload.name;
|
|
315
|
-
return {
|
|
316
|
-
calendarEventType: match,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
const type = Object.assign({ id: (0, test_utils_1.generateId)(), source: source, viewControllerId: null, slug: target.slug }, payload);
|
|
320
|
-
eventTypes.push(type);
|
|
321
|
-
return {
|
|
322
|
-
calendarEventType: type,
|
|
323
|
-
};
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
async function fakeCalendarEvents(calendars) {
|
|
327
|
-
await spruce_test_fixtures_1.eventFaker.on('calendar.create-calendar::v2021_05_19', ({ payload, source, target }) => {
|
|
328
|
-
const matches = calendars.filter((c) => c.slug === payload.slug);
|
|
329
|
-
test_1.assert.isLength(matches, 0, `You already created a calendar the slug: ${payload.slug}!`);
|
|
330
|
-
const calendar = Object.assign({ id: (0, test_utils_1.generateId)(), source: source, target }, payload);
|
|
331
|
-
calendars.push(calendar);
|
|
332
|
-
return { calendar };
|
|
333
|
-
});
|
|
334
|
-
//@ts-ignore
|
|
335
|
-
await spruce_test_fixtures_1.eventFaker.on('calendar.get-calendar::v2021_05_19', ({ target }) => {
|
|
336
|
-
const calendar = calendars.find((c) => c.slug === target.slug);
|
|
337
|
-
return {
|
|
338
|
-
calendar,
|
|
339
|
-
};
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
function assertRanBeforeEach(me) {
|
|
343
|
-
test_1.assert.isTrue(
|
|
344
|
-
//@ts-ignore
|
|
345
|
-
me._didBeforeEach, `You gotta add 'await calendarSkillAssert.beforeEach(...)' to the beforeEach() of your test.`);
|
|
346
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { CalendarToolBeltContext, CalendarToolBeltStateMachine } from '../../../types/calendar.types';
|
|
2
|
-
declare const calendarToolBeltInteractor: {
|
|
3
|
-
simulateRandomContextUpdate(stateMachine: CalendarToolBeltStateMachine): Promise<CalendarToolBeltContext>;
|
|
4
|
-
};
|
|
5
|
-
export default calendarToolBeltInteractor;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
4
|
-
const calendarToolBeltInteractor = {
|
|
5
|
-
async simulateRandomContextUpdate(stateMachine) {
|
|
6
|
-
const context = Object.assign(Object.assign({}, stateMachine.getContext()), { event: Object.assign({}, heartwood_view_controllers_1.calendarSeeder.generateEventValues()) });
|
|
7
|
-
await stateMachine.updateContext(context);
|
|
8
|
-
return context;
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
exports.default = calendarToolBeltInteractor;
|
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
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;
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|