@sprucelabs/spruce-heartwood-utils 16.3.15 → 16.4.0
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/MockRemoteViewControllerFactory.d.ts +15 -0
- package/build/__tests__/support/MockRemoteViewControllerFactory.js +41 -0
- package/build/__tests__/support/heartwoodEventFaker.d.ts +4 -0
- package/build/__tests__/support/heartwoodEventFaker.js +51 -0
- package/build/__tests__/support/remoteVcAssert.d.ts +5 -5
- package/build/__tests__/support/remoteVcAssert.js +7 -42
- package/build/esm/__tests__/support/MockRemoteViewControllerFactory.d.ts +15 -0
- package/build/esm/__tests__/support/MockRemoteViewControllerFactory.js +48 -0
- package/build/esm/__tests__/support/heartwoodEventFaker.d.ts +4 -0
- package/build/esm/__tests__/support/heartwoodEventFaker.js +59 -0
- package/build/esm/__tests__/support/remoteVcAssert.d.ts +5 -5
- package/build/esm/__tests__/support/remoteVcAssert.js +4 -42
- package/build/esm/index-module.d.ts +1 -0
- package/build/esm/index-module.js +1 -0
- package/build/esm/skillViews/CardRegistrar.js +3 -2
- package/build/esm/skillViews/RemoteViewControllerFactory.d.ts +13 -6
- package/build/esm/skillViews/RemoteViewControllerFactory.js +8 -4
- package/build/index-module.d.ts +1 -0
- package/build/index-module.js +3 -1
- package/build/skillViews/CardRegistrar.js +1 -0
- package/build/skillViews/RemoteViewControllerFactory.d.ts +13 -6
- package/build/skillViews/RemoteViewControllerFactory.js +9 -5
- package/package.json +9 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ViewControllerMap, ControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { RemoteViewControllerFactory } from '../../skillViews/RemoteViewControllerFactory';
|
|
3
|
+
export default class MockRemoteViewControllerFactory implements RemoteViewControllerFactory {
|
|
4
|
+
private static instance?;
|
|
5
|
+
private loadedControllers;
|
|
6
|
+
private remoteControllerOptions?;
|
|
7
|
+
constructor();
|
|
8
|
+
Controller<N extends keyof ViewControllerMap, O extends ControllerOptions<N>>(_name: N, _options: O): ViewControllerMap[N];
|
|
9
|
+
static reset(): void;
|
|
10
|
+
static getInstance(): MockRemoteViewControllerFactory;
|
|
11
|
+
getTheme(_namespace?: string | undefined): undefined;
|
|
12
|
+
assertFetchedRemoteController(id: string, options?: Record<string, any>): void;
|
|
13
|
+
hasController(name: string): boolean;
|
|
14
|
+
RemoteController(name: string, options: Record<string, any>): Promise<any>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
4
|
+
class MockRemoteViewControllerFactory {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.loadedControllers = {};
|
|
7
|
+
MockRemoteViewControllerFactory.instance = this;
|
|
8
|
+
}
|
|
9
|
+
Controller(_name, _options) {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
static reset() {
|
|
13
|
+
delete this.instance;
|
|
14
|
+
}
|
|
15
|
+
static getInstance() {
|
|
16
|
+
if (!this.instance) {
|
|
17
|
+
throw 'You did not create a RemoveViewControllerFactory instance (and setup the mock factory). In your test try RemoteViewControllerFactoryImpl.Class = MockRemoteViewControllerFactory and in your skill view try this.remove = RemoteViewControllerFactoryImpl.Factory(...)';
|
|
18
|
+
}
|
|
19
|
+
return this.instance;
|
|
20
|
+
}
|
|
21
|
+
getTheme(_namespace) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
assertFetchedRemoteController(id, options) {
|
|
25
|
+
test_utils_1.assert.isTrue(this.hasController(id), `You never tried to fetch a controller with the id '${id}'. Try remoteViews.RemoteController(...)`);
|
|
26
|
+
if (options) {
|
|
27
|
+
test_utils_1.assert.isEqualDeep(this.remoteControllerOptions, options, `You did not pass the expected options to remoteViews.RemoteController(${id}, options)`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
hasController(name) {
|
|
31
|
+
var _a;
|
|
32
|
+
return (_a = this.loadedControllers[name]) !== null && _a !== void 0 ? _a : false;
|
|
33
|
+
}
|
|
34
|
+
async RemoteController(name, options) {
|
|
35
|
+
this.loadedControllers[name] = true;
|
|
36
|
+
this.remoteControllerOptions = options;
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = MockRemoteViewControllerFactory;
|
|
41
|
+
//# sourceMappingURL=MockRemoteViewControllerFactory.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
4
|
+
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
5
|
+
const heartwoodEventFaker = {
|
|
6
|
+
async fakeGetViews(svcIds, stubMethodToImplement) {
|
|
7
|
+
const vcs = svcIds.map((id) => ({
|
|
8
|
+
id,
|
|
9
|
+
stubMethod: stubMethodToImplement,
|
|
10
|
+
}));
|
|
11
|
+
const source = [
|
|
12
|
+
...vcs.map((vc, idx) => generateVcSource({
|
|
13
|
+
vcId: vc.id,
|
|
14
|
+
count: idx + 1,
|
|
15
|
+
stubMethod: vc.stubMethod,
|
|
16
|
+
})),
|
|
17
|
+
`heartwood({ ${vcs.map((vc, idx) => `TestEventViewController${idx + 1}`)} })`,
|
|
18
|
+
];
|
|
19
|
+
await spruce_test_fixtures_1.eventFaker.on('heartwood.get-skill-views::v2021_02_11', () => {
|
|
20
|
+
return {
|
|
21
|
+
id: (0, test_utils_1.generateId)(),
|
|
22
|
+
ids: svcIds,
|
|
23
|
+
source: source.join('\n'),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
exports.default = heartwoodEventFaker;
|
|
29
|
+
function generateVcSource(options) {
|
|
30
|
+
const { vcId, count, stubMethod } = options;
|
|
31
|
+
return [
|
|
32
|
+
`class TestEventViewController${count} {
|
|
33
|
+
alert = function() {}
|
|
34
|
+
${stubMethod !== null && stubMethod !== void 0 ? stubMethod : 'noop'} = function () {
|
|
35
|
+
this.wasHit = true
|
|
36
|
+
this.passedParams = Array.prototype.slice.call(arguments)
|
|
37
|
+
}
|
|
38
|
+
setTriggerRenderHandler = function(handler) {
|
|
39
|
+
this.triggerRender = handler
|
|
40
|
+
}
|
|
41
|
+
render = function() {
|
|
42
|
+
return {
|
|
43
|
+
id: '${vcId}',
|
|
44
|
+
controller: this,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}`,
|
|
48
|
+
`TestEventViewController${count}.id = '${vcId}'`,
|
|
49
|
+
].join('\n\n');
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=heartwoodEventFaker.js.map
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { SkillViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { SkillEventContract } from '@sprucelabs/mercury-types';
|
|
3
3
|
import { ArgsFromSvc, ViewFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
4
|
-
declare
|
|
4
|
+
declare const remoteVcAssert: {
|
|
5
|
+
assertSkillViewRendersRemoteCards<Svc extends SkillViewController<Record<string, any>> = SkillViewController<Record<string, any>>>(options: AssertRendersRemoteCardsOptions<Svc>): Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export default remoteVcAssert;
|
|
5
8
|
export interface AssertRendersRemoteCardsOptions<Svc extends SkillViewController = SkillViewController> {
|
|
6
9
|
svc: Svc;
|
|
7
10
|
fqen: EventNames;
|
|
@@ -14,7 +17,4 @@ export interface AssertRendersRemoteCardsOptions<Svc extends SkillViewController
|
|
|
14
17
|
expectedParams?: any[];
|
|
15
18
|
};
|
|
16
19
|
}
|
|
17
|
-
declare
|
|
18
|
-
assertSkillViewRendersRemoteCards<Svc extends SkillViewController<Record<string, any>> = SkillViewController<Record<string, any>>>(options: AssertRendersRemoteCardsOptions<Svc>): Promise<void>;
|
|
19
|
-
};
|
|
20
|
-
export default remoteVcAssert;
|
|
20
|
+
declare type EventNames = keyof SkillEventContract['eventSignatures'];
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
4
7
|
const schema_1 = require("@sprucelabs/schema");
|
|
5
8
|
const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
6
9
|
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
7
10
|
const test_utils_2 = require("@sprucelabs/test-utils");
|
|
11
|
+
const heartwoodEventFaker_1 = __importDefault(require("./heartwoodEventFaker"));
|
|
8
12
|
const remoteVcAssert = {
|
|
9
13
|
async assertSkillViewRendersRemoteCards(options) {
|
|
10
14
|
var _a;
|
|
@@ -30,26 +34,9 @@ const remoteVcAssert = {
|
|
|
30
34
|
vcIds: ['assert.' + vc1Id, 'assert.' + vc2Id],
|
|
31
35
|
};
|
|
32
36
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
vcId: vc1Id,
|
|
37
|
-
count: 1,
|
|
38
|
-
stubMethod: shouldInvoke === null || shouldInvoke === void 0 ? void 0 : shouldInvoke.methodName,
|
|
39
|
-
}),
|
|
40
|
-
generateVcSource({
|
|
41
|
-
vcId: vc2Id,
|
|
42
|
-
count: 2,
|
|
43
|
-
stubMethod: shouldInvoke === null || shouldInvoke === void 0 ? void 0 : shouldInvoke.methodName,
|
|
44
|
-
}),
|
|
45
|
-
`heartwood({ TestEventViewController1, TestEventViewController2 })`,
|
|
46
|
-
].join('\n');
|
|
47
|
-
return {
|
|
48
|
-
id: (0, test_utils_2.generateId)(),
|
|
49
|
-
ids: [vc1Id, vc2Id],
|
|
50
|
-
source,
|
|
51
|
-
};
|
|
52
|
-
});
|
|
37
|
+
const stubMethodName = shouldInvoke === null || shouldInvoke === void 0 ? void 0 : shouldInvoke.methodName;
|
|
38
|
+
const ids = [vc1Id, vc2Id];
|
|
39
|
+
await heartwoodEventFaker_1.default.fakeGetViews(ids, stubMethodName);
|
|
53
40
|
await views.load(svc, loadArgs);
|
|
54
41
|
test_utils_1.assert.isTrue(wasHit, `You did not load any remote cards. Next step is to add the following to your skill view's load():\n\nconst registrar = new CardRegistrar(...)\nconst cards = await registrar.fetch(...)\n\nAlso, make sure you create the new event that you'll emit when trying to fetch remote cards, something like 'my-skill.register-cards::v2020_02_02'\n\n`);
|
|
55
42
|
if (expectedTarget) {
|
|
@@ -97,28 +84,6 @@ The original error is: ${(_a = err.stack) !== null && _a !== void 0 ? _a : err.m
|
|
|
97
84
|
}
|
|
98
85
|
},
|
|
99
86
|
};
|
|
100
|
-
function generateVcSource(options) {
|
|
101
|
-
const { vcId, count, stubMethod } = options;
|
|
102
|
-
return [
|
|
103
|
-
`class TestEventViewController${count} {
|
|
104
|
-
alert = function() {}
|
|
105
|
-
${stubMethod !== null && stubMethod !== void 0 ? stubMethod : 'noop'} = function () {
|
|
106
|
-
this.wasHit = true
|
|
107
|
-
this.passedParams = Array.prototype.slice.call(arguments)
|
|
108
|
-
}
|
|
109
|
-
setTriggerRenderHandler = function(handler) {
|
|
110
|
-
this.triggerRender = handler
|
|
111
|
-
}
|
|
112
|
-
render = function() {
|
|
113
|
-
return {
|
|
114
|
-
id: '${vcId}',
|
|
115
|
-
controller: this,
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}`,
|
|
119
|
-
`TestEventViewController${count}.id = '${vcId}'`,
|
|
120
|
-
].join('\n\n');
|
|
121
|
-
}
|
|
122
87
|
class ThrowingErrorCardVc extends heartwood_view_controllers_1.AbstractViewController {
|
|
123
88
|
constructor(options) {
|
|
124
89
|
super(options);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ViewControllerMap, ControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { RemoteViewControllerFactory } from '../../skillViews/RemoteViewControllerFactory';
|
|
3
|
+
export default class MockRemoteViewControllerFactory implements RemoteViewControllerFactory {
|
|
4
|
+
private static instance?;
|
|
5
|
+
private loadedControllers;
|
|
6
|
+
private remoteControllerOptions?;
|
|
7
|
+
constructor();
|
|
8
|
+
Controller<N extends keyof ViewControllerMap, O extends ControllerOptions<N>>(_name: N, _options: O): ViewControllerMap[N];
|
|
9
|
+
static reset(): void;
|
|
10
|
+
static getInstance(): MockRemoteViewControllerFactory;
|
|
11
|
+
getTheme(_namespace?: string | undefined): undefined;
|
|
12
|
+
assertFetchedRemoteController(id: string, options?: Record<string, any>): void;
|
|
13
|
+
hasController(name: string): boolean;
|
|
14
|
+
RemoteController(name: string, options: Record<string, any>): Promise<any>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { assert } from '@sprucelabs/test-utils';
|
|
11
|
+
export default class MockRemoteViewControllerFactory {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.loadedControllers = {};
|
|
14
|
+
MockRemoteViewControllerFactory.instance = this;
|
|
15
|
+
}
|
|
16
|
+
Controller(_name, _options) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
static reset() {
|
|
20
|
+
delete this.instance;
|
|
21
|
+
}
|
|
22
|
+
static getInstance() {
|
|
23
|
+
if (!this.instance) {
|
|
24
|
+
throw 'You did not create a RemoveViewControllerFactory instance (and setup the mock factory). In your test try RemoteViewControllerFactoryImpl.Class = MockRemoteViewControllerFactory and in your skill view try this.remove = RemoteViewControllerFactoryImpl.Factory(...)';
|
|
25
|
+
}
|
|
26
|
+
return this.instance;
|
|
27
|
+
}
|
|
28
|
+
getTheme(_namespace) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
assertFetchedRemoteController(id, options) {
|
|
32
|
+
assert.isTrue(this.hasController(id), `You never tried to fetch a controller with the id '${id}'. Try remoteViews.RemoteController(...)`);
|
|
33
|
+
if (options) {
|
|
34
|
+
assert.isEqualDeep(this.remoteControllerOptions, options, `You did not pass the expected options to remoteViews.RemoteController(${id}, options)`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
hasController(name) {
|
|
38
|
+
var _a;
|
|
39
|
+
return (_a = this.loadedControllers[name]) !== null && _a !== void 0 ? _a : false;
|
|
40
|
+
}
|
|
41
|
+
RemoteController(name, options) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
this.loadedControllers[name] = true;
|
|
44
|
+
this.remoteControllerOptions = options;
|
|
45
|
+
return {};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 { eventFaker } from '@sprucelabs/spruce-test-fixtures';
|
|
11
|
+
import { generateId } from '@sprucelabs/test-utils';
|
|
12
|
+
const heartwoodEventFaker = {
|
|
13
|
+
fakeGetViews(svcIds, stubMethodToImplement) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const vcs = svcIds.map((id) => ({
|
|
16
|
+
id,
|
|
17
|
+
stubMethod: stubMethodToImplement,
|
|
18
|
+
}));
|
|
19
|
+
const source = [
|
|
20
|
+
...vcs.map((vc, idx) => generateVcSource({
|
|
21
|
+
vcId: vc.id,
|
|
22
|
+
count: idx + 1,
|
|
23
|
+
stubMethod: vc.stubMethod,
|
|
24
|
+
})),
|
|
25
|
+
`heartwood({ ${vcs.map((vc, idx) => `TestEventViewController${idx + 1}`)} })`,
|
|
26
|
+
];
|
|
27
|
+
yield eventFaker.on('heartwood.get-skill-views::v2021_02_11', () => {
|
|
28
|
+
return {
|
|
29
|
+
id: generateId(),
|
|
30
|
+
ids: svcIds,
|
|
31
|
+
source: source.join('\n'),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
export default heartwoodEventFaker;
|
|
38
|
+
function generateVcSource(options) {
|
|
39
|
+
const { vcId, count, stubMethod } = options;
|
|
40
|
+
return [
|
|
41
|
+
`class TestEventViewController${count} {
|
|
42
|
+
alert = function() {}
|
|
43
|
+
${stubMethod !== null && stubMethod !== void 0 ? stubMethod : 'noop'} = function () {
|
|
44
|
+
this.wasHit = true
|
|
45
|
+
this.passedParams = Array.prototype.slice.call(arguments)
|
|
46
|
+
}
|
|
47
|
+
setTriggerRenderHandler = function(handler) {
|
|
48
|
+
this.triggerRender = handler
|
|
49
|
+
}
|
|
50
|
+
render = function() {
|
|
51
|
+
return {
|
|
52
|
+
id: '${vcId}',
|
|
53
|
+
controller: this,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}`,
|
|
57
|
+
`TestEventViewController${count}.id = '${vcId}'`,
|
|
58
|
+
].join('\n\n');
|
|
59
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { SkillViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { SkillEventContract } from '@sprucelabs/mercury-types';
|
|
3
3
|
import { ArgsFromSvc, ViewFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
4
|
-
declare
|
|
4
|
+
declare const remoteVcAssert: {
|
|
5
|
+
assertSkillViewRendersRemoteCards<Svc extends SkillViewController<Record<string, any>> = SkillViewController<Record<string, any>>>(options: AssertRendersRemoteCardsOptions<Svc>): Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export default remoteVcAssert;
|
|
5
8
|
export interface AssertRendersRemoteCardsOptions<Svc extends SkillViewController = SkillViewController> {
|
|
6
9
|
svc: Svc;
|
|
7
10
|
fqen: EventNames;
|
|
@@ -14,7 +17,4 @@ export interface AssertRendersRemoteCardsOptions<Svc extends SkillViewController
|
|
|
14
17
|
expectedParams?: any[];
|
|
15
18
|
};
|
|
16
19
|
}
|
|
17
|
-
declare
|
|
18
|
-
assertSkillViewRendersRemoteCards<Svc extends SkillViewController<Record<string, any>> = SkillViewController<Record<string, any>>>(options: AssertRendersRemoteCardsOptions<Svc>): Promise<void>;
|
|
19
|
-
};
|
|
20
|
-
export default remoteVcAssert;
|
|
20
|
+
declare type EventNames = keyof SkillEventContract['eventSignatures'];
|
|
@@ -12,6 +12,7 @@ import { assertOptions } from '@sprucelabs/schema';
|
|
|
12
12
|
import { eventFaker, } from '@sprucelabs/spruce-test-fixtures';
|
|
13
13
|
import { assert } from '@sprucelabs/test-utils';
|
|
14
14
|
import { generateId } from '@sprucelabs/test-utils';
|
|
15
|
+
import heartwoodEventFaker from './heartwoodEventFaker.js';
|
|
15
16
|
const remoteVcAssert = {
|
|
16
17
|
assertSkillViewRendersRemoteCards(options) {
|
|
17
18
|
var _a;
|
|
@@ -38,26 +39,9 @@ const remoteVcAssert = {
|
|
|
38
39
|
vcIds: ['assert.' + vc1Id, 'assert.' + vc2Id],
|
|
39
40
|
};
|
|
40
41
|
}));
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
vcId: vc1Id,
|
|
45
|
-
count: 1,
|
|
46
|
-
stubMethod: shouldInvoke === null || shouldInvoke === void 0 ? void 0 : shouldInvoke.methodName,
|
|
47
|
-
}),
|
|
48
|
-
generateVcSource({
|
|
49
|
-
vcId: vc2Id,
|
|
50
|
-
count: 2,
|
|
51
|
-
stubMethod: shouldInvoke === null || shouldInvoke === void 0 ? void 0 : shouldInvoke.methodName,
|
|
52
|
-
}),
|
|
53
|
-
`heartwood({ TestEventViewController1, TestEventViewController2 })`,
|
|
54
|
-
].join('\n');
|
|
55
|
-
return {
|
|
56
|
-
id: generateId(),
|
|
57
|
-
ids: [vc1Id, vc2Id],
|
|
58
|
-
source,
|
|
59
|
-
};
|
|
60
|
-
});
|
|
42
|
+
const stubMethodName = shouldInvoke === null || shouldInvoke === void 0 ? void 0 : shouldInvoke.methodName;
|
|
43
|
+
const ids = [vc1Id, vc2Id];
|
|
44
|
+
yield heartwoodEventFaker.fakeGetViews(ids, stubMethodName);
|
|
61
45
|
yield views.load(svc, loadArgs);
|
|
62
46
|
assert.isTrue(wasHit, `You did not load any remote cards. Next step is to add the following to your skill view's load():\n\nconst registrar = new CardRegistrar(...)\nconst cards = await registrar.fetch(...)\n\nAlso, make sure you create the new event that you'll emit when trying to fetch remote cards, something like 'my-skill.register-cards::v2020_02_02'\n\n`);
|
|
63
47
|
if (expectedTarget) {
|
|
@@ -106,28 +90,6 @@ The original error is: ${(_a = err.stack) !== null && _a !== void 0 ? _a : err.m
|
|
|
106
90
|
});
|
|
107
91
|
},
|
|
108
92
|
};
|
|
109
|
-
function generateVcSource(options) {
|
|
110
|
-
const { vcId, count, stubMethod } = options;
|
|
111
|
-
return [
|
|
112
|
-
`class TestEventViewController${count} {
|
|
113
|
-
alert = function() {}
|
|
114
|
-
${stubMethod !== null && stubMethod !== void 0 ? stubMethod : 'noop'} = function () {
|
|
115
|
-
this.wasHit = true
|
|
116
|
-
this.passedParams = Array.prototype.slice.call(arguments)
|
|
117
|
-
}
|
|
118
|
-
setTriggerRenderHandler = function(handler) {
|
|
119
|
-
this.triggerRender = handler
|
|
120
|
-
}
|
|
121
|
-
render = function() {
|
|
122
|
-
return {
|
|
123
|
-
id: '${vcId}',
|
|
124
|
-
controller: this,
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}`,
|
|
128
|
-
`TestEventViewController${count}.id = '${vcId}'`,
|
|
129
|
-
].join('\n\n');
|
|
130
|
-
}
|
|
131
93
|
class ThrowingErrorCardVc extends AbstractViewController {
|
|
132
94
|
constructor(options) {
|
|
133
95
|
super(options);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as RemoteViewControllerFactory } from './skillViews/RemoteViewControllerFactory';
|
|
2
2
|
export { default as CardRegistrar } from './skillViews/CardRegistrar';
|
|
3
3
|
export { default as remoteVcAssert } from './__tests__/support/remoteVcAssert';
|
|
4
|
+
export { default as fakeGetViews } from './__tests__/support/heartwoodEventFaker';
|
|
4
5
|
export * from './types/heartwood-module.types';
|
|
5
6
|
export { default as loadActiveThemeForOrg } from './theming/loadActiveThemeForOrg';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as RemoteViewControllerFactory } from './skillViews/RemoteViewControllerFactory.js';
|
|
2
2
|
export { default as CardRegistrar } from './skillViews/CardRegistrar.js';
|
|
3
3
|
export { default as remoteVcAssert } from './__tests__/support/remoteVcAssert.js';
|
|
4
|
+
export { default as fakeGetViews } from './__tests__/support/heartwoodEventFaker.js';
|
|
4
5
|
export * from './types/heartwood-module.types.js';
|
|
5
6
|
export { default as loadActiveThemeForOrg } from './theming/loadActiveThemeForOrg.js';
|
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { assertOptions } from '@sprucelabs/schema';
|
|
11
|
-
import
|
|
11
|
+
import RemoteViewControllerFactoryImpl from './RemoteViewControllerFactory.js';
|
|
12
12
|
export default class CardRegistrar {
|
|
13
13
|
/** @ts-ignore */
|
|
14
14
|
constructor(options) {
|
|
@@ -21,7 +21,7 @@ export default class CardRegistrar {
|
|
|
21
21
|
this.client = options.client;
|
|
22
22
|
this.eventName = options.eventName;
|
|
23
23
|
this.vcIdsTransformer = options.vcIdsTransformer;
|
|
24
|
-
this.remoteVcFactory =
|
|
24
|
+
this.remoteVcFactory = RemoteViewControllerFactoryImpl.Factory({
|
|
25
25
|
//@ts-ignore
|
|
26
26
|
connectToApi: () => options.client,
|
|
27
27
|
vcFactory: options.vcFactory,
|
|
@@ -84,6 +84,7 @@ export default class CardRegistrar {
|
|
|
84
84
|
}
|
|
85
85
|
ErrorCardVc(err) {
|
|
86
86
|
return this.remoteVcFactory.Controller('heartwood.error-card', {
|
|
87
|
+
//@ts-ignore
|
|
87
88
|
error: err,
|
|
88
89
|
});
|
|
89
90
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { ViewController, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
|
|
1
|
+
import { ControllerOptions, ViewController, ViewControllerFactory, ViewControllerId, ViewControllerMap } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { MercuryClient } from '@sprucelabs/mercury-client';
|
|
3
3
|
import { SkillTheme } from '../theming/ThemeManager';
|
|
4
|
-
export default class
|
|
4
|
+
export default class RemoteViewControllerFactoryImpl implements RemoteViewControllerFactory {
|
|
5
|
+
static Class?: new (options: RemoteFactoryOptions) => RemoteViewControllerFactory;
|
|
5
6
|
static Request: any;
|
|
6
7
|
private connectToApi;
|
|
7
8
|
private vcFactory;
|
|
8
9
|
private themesByNamespace;
|
|
9
|
-
static Factory(options:
|
|
10
|
+
static Factory(options: RemoteFactoryOptions): RemoteViewControllerFactory;
|
|
11
|
+
static reset(): void;
|
|
10
12
|
private constructor();
|
|
11
13
|
hasController(name: string): boolean;
|
|
12
14
|
getTheme(namespace?: string): SkillTheme;
|
|
13
|
-
Controller(name:
|
|
15
|
+
Controller<N extends ViewControllerId, O extends ControllerOptions<N>>(name: N, options: O): ViewControllerMap[N];
|
|
14
16
|
private getNamespace;
|
|
15
17
|
getController(name: string): any;
|
|
16
18
|
fetchRemoteController(name: string): Promise<(new () => ViewController<any>) & {
|
|
@@ -20,11 +22,16 @@ export default class RemoteViewControllerFactory implements Factory {
|
|
|
20
22
|
private optionallyLoadController;
|
|
21
23
|
private fetchFromUrl;
|
|
22
24
|
}
|
|
25
|
+
declare type Theme = SkillTheme;
|
|
23
26
|
declare type ConnectToApi = () => Promise<MercuryClient>;
|
|
24
27
|
export declare type VcFactoryForRemoteFactory = Pick<ViewControllerFactory, 'setController' | 'hasController' | 'getController' | 'Controller' | 'importControllers'>;
|
|
25
|
-
interface
|
|
28
|
+
export interface RemoteFactoryOptions {
|
|
26
29
|
connectToApi: ConnectToApi;
|
|
27
30
|
vcFactory: VcFactoryForRemoteFactory;
|
|
28
31
|
}
|
|
29
|
-
declare type Factory = Pick<ViewControllerFactory, 'hasController'>;
|
|
32
|
+
declare type Factory = Pick<ViewControllerFactory, 'hasController' | 'Controller'>;
|
|
33
|
+
export interface RemoteViewControllerFactory extends Factory {
|
|
34
|
+
RemoteController: (name: string, options: Record<string, any>) => Promise<ViewController<Record<string, any>>>;
|
|
35
|
+
getTheme: (namespace?: string) => Theme | undefined;
|
|
36
|
+
}
|
|
30
37
|
export {};
|
|
@@ -9,14 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { ViewControllerImporter, } from '@sprucelabs/heartwood-view-controllers';
|
|
11
11
|
import SpruceError from '../errors/SpruceError.js';
|
|
12
|
-
export default class
|
|
12
|
+
export default class RemoteViewControllerFactoryImpl {
|
|
13
13
|
constructor(options) {
|
|
14
14
|
this.themesByNamespace = {};
|
|
15
15
|
this.connectToApi = options.connectToApi;
|
|
16
16
|
this.vcFactory = options.vcFactory;
|
|
17
17
|
}
|
|
18
18
|
static Factory(options) {
|
|
19
|
-
|
|
19
|
+
var _a;
|
|
20
|
+
return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(options);
|
|
21
|
+
}
|
|
22
|
+
static reset() {
|
|
23
|
+
delete this.Class;
|
|
20
24
|
}
|
|
21
25
|
hasController(name) {
|
|
22
26
|
return this.vcFactory.hasController(name);
|
|
@@ -73,7 +77,7 @@ export default class RemoteViewControllerFactory {
|
|
|
73
77
|
fetchFromUrl(sourceUrl) {
|
|
74
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
79
|
return (yield new Promise((resolve, reject) => {
|
|
76
|
-
const request = new
|
|
80
|
+
const request = new RemoteViewControllerFactoryImpl.Request();
|
|
77
81
|
request.open('GET', sourceUrl, true);
|
|
78
82
|
request.onload = () => {
|
|
79
83
|
if (request.readyState !== 4) {
|
|
@@ -94,4 +98,4 @@ export default class RemoteViewControllerFactory {
|
|
|
94
98
|
});
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
|
-
|
|
101
|
+
RemoteViewControllerFactoryImpl.Request = typeof XMLHttpRequest === 'undefined' ? {} : XMLHttpRequest;
|
package/build/index-module.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as RemoteViewControllerFactory } from './skillViews/RemoteViewControllerFactory';
|
|
2
2
|
export { default as CardRegistrar } from './skillViews/CardRegistrar';
|
|
3
3
|
export { default as remoteVcAssert } from './__tests__/support/remoteVcAssert';
|
|
4
|
+
export { default as fakeGetViews } from './__tests__/support/heartwoodEventFaker';
|
|
4
5
|
export * from './types/heartwood-module.types';
|
|
5
6
|
export { default as loadActiveThemeForOrg } from './theming/loadActiveThemeForOrg';
|
package/build/index-module.js
CHANGED
|
@@ -17,13 +17,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.loadActiveThemeForOrg = exports.remoteVcAssert = exports.CardRegistrar = exports.RemoteViewControllerFactory = void 0;
|
|
20
|
+
exports.loadActiveThemeForOrg = exports.fakeGetViews = exports.remoteVcAssert = exports.CardRegistrar = exports.RemoteViewControllerFactory = void 0;
|
|
21
21
|
var RemoteViewControllerFactory_1 = require("./skillViews/RemoteViewControllerFactory");
|
|
22
22
|
Object.defineProperty(exports, "RemoteViewControllerFactory", { enumerable: true, get: function () { return __importDefault(RemoteViewControllerFactory_1).default; } });
|
|
23
23
|
var CardRegistrar_1 = require("./skillViews/CardRegistrar");
|
|
24
24
|
Object.defineProperty(exports, "CardRegistrar", { enumerable: true, get: function () { return __importDefault(CardRegistrar_1).default; } });
|
|
25
25
|
var remoteVcAssert_1 = require("./__tests__/support/remoteVcAssert");
|
|
26
26
|
Object.defineProperty(exports, "remoteVcAssert", { enumerable: true, get: function () { return __importDefault(remoteVcAssert_1).default; } });
|
|
27
|
+
var heartwoodEventFaker_1 = require("./__tests__/support/heartwoodEventFaker");
|
|
28
|
+
Object.defineProperty(exports, "fakeGetViews", { enumerable: true, get: function () { return __importDefault(heartwoodEventFaker_1).default; } });
|
|
27
29
|
__exportStar(require("./types/heartwood-module.types"), exports);
|
|
28
30
|
var loadActiveThemeForOrg_1 = require("./theming/loadActiveThemeForOrg");
|
|
29
31
|
Object.defineProperty(exports, "loadActiveThemeForOrg", { enumerable: true, get: function () { return __importDefault(loadActiveThemeForOrg_1).default; } });
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { ViewController, ViewControllerFactory } from '@sprucelabs/heartwood-view-controllers';
|
|
1
|
+
import { ControllerOptions, ViewController, ViewControllerFactory, ViewControllerId, ViewControllerMap } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { MercuryClient } from '@sprucelabs/mercury-client';
|
|
3
3
|
import { SkillTheme } from '../theming/ThemeManager';
|
|
4
|
-
export default class
|
|
4
|
+
export default class RemoteViewControllerFactoryImpl implements RemoteViewControllerFactory {
|
|
5
|
+
static Class?: new (options: RemoteFactoryOptions) => RemoteViewControllerFactory;
|
|
5
6
|
static Request: any;
|
|
6
7
|
private connectToApi;
|
|
7
8
|
private vcFactory;
|
|
8
9
|
private themesByNamespace;
|
|
9
|
-
static Factory(options:
|
|
10
|
+
static Factory(options: RemoteFactoryOptions): RemoteViewControllerFactory;
|
|
11
|
+
static reset(): void;
|
|
10
12
|
private constructor();
|
|
11
13
|
hasController(name: string): boolean;
|
|
12
14
|
getTheme(namespace?: string): SkillTheme;
|
|
13
|
-
Controller(name:
|
|
15
|
+
Controller<N extends ViewControllerId, O extends ControllerOptions<N>>(name: N, options: O): ViewControllerMap[N];
|
|
14
16
|
private getNamespace;
|
|
15
17
|
getController(name: string): any;
|
|
16
18
|
fetchRemoteController(name: string): Promise<(new () => ViewController<any>) & {
|
|
@@ -20,11 +22,16 @@ export default class RemoteViewControllerFactory implements Factory {
|
|
|
20
22
|
private optionallyLoadController;
|
|
21
23
|
private fetchFromUrl;
|
|
22
24
|
}
|
|
25
|
+
declare type Theme = SkillTheme;
|
|
23
26
|
declare type ConnectToApi = () => Promise<MercuryClient>;
|
|
24
27
|
export declare type VcFactoryForRemoteFactory = Pick<ViewControllerFactory, 'setController' | 'hasController' | 'getController' | 'Controller' | 'importControllers'>;
|
|
25
|
-
interface
|
|
28
|
+
export interface RemoteFactoryOptions {
|
|
26
29
|
connectToApi: ConnectToApi;
|
|
27
30
|
vcFactory: VcFactoryForRemoteFactory;
|
|
28
31
|
}
|
|
29
|
-
declare type Factory = Pick<ViewControllerFactory, 'hasController'>;
|
|
32
|
+
declare type Factory = Pick<ViewControllerFactory, 'hasController' | 'Controller'>;
|
|
33
|
+
export interface RemoteViewControllerFactory extends Factory {
|
|
34
|
+
RemoteController: (name: string, options: Record<string, any>) => Promise<ViewController<Record<string, any>>>;
|
|
35
|
+
getTheme: (namespace?: string) => Theme | undefined;
|
|
36
|
+
}
|
|
30
37
|
export {};
|
|
@@ -5,14 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
7
7
|
const SpruceError_1 = __importDefault(require("../errors/SpruceError"));
|
|
8
|
-
class
|
|
8
|
+
class RemoteViewControllerFactoryImpl {
|
|
9
9
|
constructor(options) {
|
|
10
10
|
this.themesByNamespace = {};
|
|
11
11
|
this.connectToApi = options.connectToApi;
|
|
12
12
|
this.vcFactory = options.vcFactory;
|
|
13
13
|
}
|
|
14
14
|
static Factory(options) {
|
|
15
|
-
|
|
15
|
+
var _a;
|
|
16
|
+
return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(options);
|
|
17
|
+
}
|
|
18
|
+
static reset() {
|
|
19
|
+
delete this.Class;
|
|
16
20
|
}
|
|
17
21
|
hasController(name) {
|
|
18
22
|
return this.vcFactory.hasController(name);
|
|
@@ -62,7 +66,7 @@ class RemoteViewControllerFactory {
|
|
|
62
66
|
}
|
|
63
67
|
async fetchFromUrl(sourceUrl) {
|
|
64
68
|
return (await new Promise((resolve, reject) => {
|
|
65
|
-
const request = new
|
|
69
|
+
const request = new RemoteViewControllerFactoryImpl.Request();
|
|
66
70
|
request.open('GET', sourceUrl, true);
|
|
67
71
|
request.onload = () => {
|
|
68
72
|
if (request.readyState !== 4) {
|
|
@@ -82,6 +86,6 @@ class RemoteViewControllerFactory {
|
|
|
82
86
|
}));
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
|
-
exports.default =
|
|
86
|
-
|
|
89
|
+
exports.default = RemoteViewControllerFactoryImpl;
|
|
90
|
+
RemoteViewControllerFactoryImpl.Request = typeof XMLHttpRequest === 'undefined' ? {} : XMLHttpRequest;
|
|
87
91
|
//# sourceMappingURL=RemoteViewControllerFactory.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sprucelabs/spruce-heartwood-utils",
|
|
3
3
|
"description": "Heartwood Utilities",
|
|
4
|
-
"version": "16.
|
|
4
|
+
"version": "16.4.0",
|
|
5
5
|
"skill": {
|
|
6
6
|
"namespace": "heartwood"
|
|
7
7
|
},
|
|
@@ -34,6 +34,14 @@
|
|
|
34
34
|
"build/__tests__/support/remoteVcAssert.d.ts",
|
|
35
35
|
"build/esm/__tests__/support/remoteVcAssert.js",
|
|
36
36
|
"build/esm/__tests__/support/remoteVcAssert.d.ts",
|
|
37
|
+
"build/__tests__/support/heartwoodEventFaker.js",
|
|
38
|
+
"build/__tests__/support/heartwoodEventFaker.d.ts",
|
|
39
|
+
"build/esm/__tests__/support/heartwoodEventFaker.js",
|
|
40
|
+
"build/esm/__tests__/support/heartwoodEventFaker.d.ts",
|
|
41
|
+
"build/__tests__/support/MockRemoteViewControllerFactory.js",
|
|
42
|
+
"build/__tests__/support/MockRemoteViewControllerFactory.d.ts",
|
|
43
|
+
"build/esm/__tests__/support/MockRemoteViewControllerFactory.js",
|
|
44
|
+
"build/esm/__tests__/support/MockRemoteViewControllerFactory.d.ts",
|
|
37
45
|
"build/utilities/slug.js",
|
|
38
46
|
"build/utilities/slug.d.ts",
|
|
39
47
|
"build/esm/utilities/slug.js",
|