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