@sprucelabs/spruce-heartwood-utils 7.5.0 → 7.6.1
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-module.d.ts +1 -0
- package/build/esm/index-module.js +1 -0
- package/build/esm/tests/remoteVcAssert.d.ts +20 -0
- package/build/esm/tests/remoteVcAssert.js +139 -0
- package/build/esm/viewControllers/CardRegistrar.js +5 -1
- package/build/index-module.d.ts +1 -0
- package/build/index-module.js +3 -1
- package/build/tests/remoteVcAssert.d.ts +20 -0
- package/build/tests/remoteVcAssert.js +133 -0
- package/build/viewControllers/CardRegistrar.js +5 -1
- package/package.json +11 -3
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SkillViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { SkillEventContract } from '@sprucelabs/mercury-types';
|
|
3
|
+
import { ViewFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
4
|
+
declare type EventNames = keyof SkillEventContract['eventSignatures'];
|
|
5
|
+
export interface AssertRendersRemoteCardsOptions {
|
|
6
|
+
vc: SkillViewController;
|
|
7
|
+
fqen: EventNames;
|
|
8
|
+
views: ViewFixture;
|
|
9
|
+
expectedTarget?: Record<string, any>;
|
|
10
|
+
expectedPayload?: Record<string, any>;
|
|
11
|
+
shouldInvoke?: {
|
|
12
|
+
methodName: string;
|
|
13
|
+
expectedParams?: any[];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
declare const remoteVcAssert: {
|
|
17
|
+
assertSkillViewRendersRemoteCards(options: AssertRendersRemoteCardsOptions): Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
export declare function generateId(): string;
|
|
20
|
+
export default remoteVcAssert;
|
|
@@ -0,0 +1,139 @@
|
|
|
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 { AbstractViewController, vcAssert, } from '@sprucelabs/heartwood-view-controllers';
|
|
11
|
+
import { assertOptions } from '@sprucelabs/schema';
|
|
12
|
+
import { eventFaker } from '@sprucelabs/spruce-test-fixtures';
|
|
13
|
+
import { assert } from '@sprucelabs/test';
|
|
14
|
+
const remoteVcAssert = {
|
|
15
|
+
assertSkillViewRendersRemoteCards(options) {
|
|
16
|
+
var _a;
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const { views, vc, expectedTarget, expectedPayload, fqen, shouldInvoke } = assertOptions(options, ['vc', 'fqen', 'views']);
|
|
19
|
+
const factory = views.getFactory();
|
|
20
|
+
factory.setController('heartwood.error-card', ThrowingErrorCardVc);
|
|
21
|
+
const vc1Id = generateId();
|
|
22
|
+
const vc2Id = generateId();
|
|
23
|
+
let wasHit = false;
|
|
24
|
+
let passedTarget;
|
|
25
|
+
let passedPayload;
|
|
26
|
+
yield eventFaker.on(fqen,
|
|
27
|
+
//@ts-ignore
|
|
28
|
+
({ target, payload }) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
passedTarget = target;
|
|
30
|
+
passedPayload = payload;
|
|
31
|
+
wasHit = true;
|
|
32
|
+
return {
|
|
33
|
+
vcIds: ['assert.' + vc1Id, 'assert.' + vc2Id],
|
|
34
|
+
};
|
|
35
|
+
}));
|
|
36
|
+
yield eventFaker.on('heartwood.get-skill-views::v2021_02_11', () => {
|
|
37
|
+
const source = [
|
|
38
|
+
generateVcSource({
|
|
39
|
+
vcId: vc1Id,
|
|
40
|
+
count: 1,
|
|
41
|
+
stubMethod: shouldInvoke === null || shouldInvoke === void 0 ? void 0 : shouldInvoke.methodName,
|
|
42
|
+
}),
|
|
43
|
+
generateVcSource({
|
|
44
|
+
vcId: vc2Id,
|
|
45
|
+
count: 2,
|
|
46
|
+
stubMethod: shouldInvoke === null || shouldInvoke === void 0 ? void 0 : shouldInvoke.methodName,
|
|
47
|
+
}),
|
|
48
|
+
`heartwood({ TestEventViewController1, TestEventViewController2 })`,
|
|
49
|
+
].join('\n');
|
|
50
|
+
return {
|
|
51
|
+
id: generateId(),
|
|
52
|
+
ids: [vc1Id, vc2Id],
|
|
53
|
+
source,
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
yield views.load(vc);
|
|
57
|
+
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`);
|
|
58
|
+
if (expectedTarget) {
|
|
59
|
+
assert.isEqualDeep(passedTarget, expectedTarget, 'The target you passed did not match!');
|
|
60
|
+
}
|
|
61
|
+
if (expectedPayload) {
|
|
62
|
+
assert.isEqualDeep(passedPayload, expectedPayload, 'The payload you passed did not match!');
|
|
63
|
+
}
|
|
64
|
+
let cards = [];
|
|
65
|
+
try {
|
|
66
|
+
cards = vcAssert.assertSkillViewRendersCards(vc, [vc1Id, vc2Id]);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
assert.fail(`You didn't drop in the cards to your skill view! Make sure your vcIdsTransformer looks something like:
|
|
70
|
+
|
|
71
|
+
vcIdsTransformer: (payload) => {
|
|
72
|
+
return payload.vcIds
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
You'll also want to add the cards to a local prop like:
|
|
76
|
+
|
|
77
|
+
this.cards.push(...cards)
|
|
78
|
+
|
|
79
|
+
Then make sure you render the cards like:
|
|
80
|
+
|
|
81
|
+
public render() {
|
|
82
|
+
return {
|
|
83
|
+
layouts: splitCardsIntoLayouts(this.cards.map((c) => c.render()))
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
The original error is: ${(_a = err.stack) !== null && _a !== void 0 ? _a : err.message}
|
|
88
|
+
`);
|
|
89
|
+
}
|
|
90
|
+
if (shouldInvoke) {
|
|
91
|
+
const { methodName, expectedParams } = shouldInvoke;
|
|
92
|
+
assert.isTrue(
|
|
93
|
+
//@ts-ignore
|
|
94
|
+
cards.filter((c) => c.wasHit).length === cards.length, `You gotta call cardVc.${methodName}(...) on all the cards you get back!`);
|
|
95
|
+
if (expectedParams) {
|
|
96
|
+
//@ts-ignore
|
|
97
|
+
const passed = cards[0].passedParams;
|
|
98
|
+
assert.isEqualDeep(passed, expectedParams, `You didn't pass the expected params to ${methodName}!`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
function generateVcSource(options) {
|
|
105
|
+
const { vcId, count, stubMethod } = options;
|
|
106
|
+
return [
|
|
107
|
+
`class TestEventViewController${count} {
|
|
108
|
+
alert = function() {}
|
|
109
|
+
${stubMethod !== null && stubMethod !== void 0 ? stubMethod : 'noop'} = function () {
|
|
110
|
+
this.wasHit = true
|
|
111
|
+
this.passedParams = Array.prototype.slice.call(arguments)
|
|
112
|
+
}
|
|
113
|
+
render = function() {
|
|
114
|
+
return {
|
|
115
|
+
id: '${vcId}',
|
|
116
|
+
controller: this,
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}`,
|
|
120
|
+
`TestEventViewController${count}.id = '${vcId}'`,
|
|
121
|
+
].join('\n\n');
|
|
122
|
+
}
|
|
123
|
+
export function generateId() {
|
|
124
|
+
return `${Math.round(new Date().getTime() * (Math.random() * 100))}`;
|
|
125
|
+
}
|
|
126
|
+
class ThrowingErrorCardVc extends AbstractViewController {
|
|
127
|
+
constructor(options) {
|
|
128
|
+
super(options);
|
|
129
|
+
//@ts-ignore
|
|
130
|
+
if (options.error) {
|
|
131
|
+
//@ts-ignore
|
|
132
|
+
throw options.error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
render() {
|
|
136
|
+
return {};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export default remoteVcAssert;
|
|
@@ -62,7 +62,11 @@ export default class CardRegistrar {
|
|
|
62
62
|
}
|
|
63
63
|
catch (err) {
|
|
64
64
|
console.error(err);
|
|
65
|
-
return [
|
|
65
|
+
return [
|
|
66
|
+
this.remoteVcFactory.Controller('heartwood.error-card', {
|
|
67
|
+
error: err,
|
|
68
|
+
}),
|
|
69
|
+
];
|
|
66
70
|
}
|
|
67
71
|
});
|
|
68
72
|
}
|
package/build/index-module.d.ts
CHANGED
package/build/index-module.js
CHANGED
|
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CardRegistrar = exports.RemoteViewControllerFactory = void 0;
|
|
6
|
+
exports.remoteVcAssert = exports.CardRegistrar = exports.RemoteViewControllerFactory = void 0;
|
|
7
7
|
var RemoteViewControllerFactory_1 = require("./viewControllers/RemoteViewControllerFactory");
|
|
8
8
|
Object.defineProperty(exports, "RemoteViewControllerFactory", { enumerable: true, get: function () { return __importDefault(RemoteViewControllerFactory_1).default; } });
|
|
9
9
|
var CardRegistrar_1 = require("./viewControllers/CardRegistrar");
|
|
10
10
|
Object.defineProperty(exports, "CardRegistrar", { enumerable: true, get: function () { return __importDefault(CardRegistrar_1).default; } });
|
|
11
|
+
var remoteVcAssert_1 = require("./tests/remoteVcAssert");
|
|
12
|
+
Object.defineProperty(exports, "remoteVcAssert", { enumerable: true, get: function () { return __importDefault(remoteVcAssert_1).default; } });
|
|
11
13
|
//# sourceMappingURL=index-module.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SkillViewController } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { SkillEventContract } from '@sprucelabs/mercury-types';
|
|
3
|
+
import { ViewFixture } from '@sprucelabs/spruce-test-fixtures';
|
|
4
|
+
declare type EventNames = keyof SkillEventContract['eventSignatures'];
|
|
5
|
+
export interface AssertRendersRemoteCardsOptions {
|
|
6
|
+
vc: SkillViewController;
|
|
7
|
+
fqen: EventNames;
|
|
8
|
+
views: ViewFixture;
|
|
9
|
+
expectedTarget?: Record<string, any>;
|
|
10
|
+
expectedPayload?: Record<string, any>;
|
|
11
|
+
shouldInvoke?: {
|
|
12
|
+
methodName: string;
|
|
13
|
+
expectedParams?: any[];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
declare const remoteVcAssert: {
|
|
17
|
+
assertSkillViewRendersRemoteCards(options: AssertRendersRemoteCardsOptions): Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
export declare function generateId(): string;
|
|
20
|
+
export default remoteVcAssert;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateId = void 0;
|
|
4
|
+
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
5
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
6
|
+
const spruce_test_fixtures_1 = require("@sprucelabs/spruce-test-fixtures");
|
|
7
|
+
const test_1 = require("@sprucelabs/test");
|
|
8
|
+
const remoteVcAssert = {
|
|
9
|
+
async assertSkillViewRendersRemoteCards(options) {
|
|
10
|
+
var _a;
|
|
11
|
+
const { views, vc, expectedTarget, expectedPayload, fqen, shouldInvoke } = (0, schema_1.assertOptions)(options, ['vc', 'fqen', 'views']);
|
|
12
|
+
const factory = views.getFactory();
|
|
13
|
+
factory.setController('heartwood.error-card', ThrowingErrorCardVc);
|
|
14
|
+
const vc1Id = generateId();
|
|
15
|
+
const vc2Id = generateId();
|
|
16
|
+
let wasHit = false;
|
|
17
|
+
let passedTarget;
|
|
18
|
+
let passedPayload;
|
|
19
|
+
await spruce_test_fixtures_1.eventFaker.on(fqen,
|
|
20
|
+
//@ts-ignore
|
|
21
|
+
async ({ target, payload }) => {
|
|
22
|
+
passedTarget = target;
|
|
23
|
+
passedPayload = payload;
|
|
24
|
+
wasHit = true;
|
|
25
|
+
return {
|
|
26
|
+
vcIds: ['assert.' + vc1Id, 'assert.' + vc2Id],
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
await spruce_test_fixtures_1.eventFaker.on('heartwood.get-skill-views::v2021_02_11', () => {
|
|
30
|
+
const source = [
|
|
31
|
+
generateVcSource({
|
|
32
|
+
vcId: vc1Id,
|
|
33
|
+
count: 1,
|
|
34
|
+
stubMethod: shouldInvoke === null || shouldInvoke === void 0 ? void 0 : shouldInvoke.methodName,
|
|
35
|
+
}),
|
|
36
|
+
generateVcSource({
|
|
37
|
+
vcId: vc2Id,
|
|
38
|
+
count: 2,
|
|
39
|
+
stubMethod: shouldInvoke === null || shouldInvoke === void 0 ? void 0 : shouldInvoke.methodName,
|
|
40
|
+
}),
|
|
41
|
+
`heartwood({ TestEventViewController1, TestEventViewController2 })`,
|
|
42
|
+
].join('\n');
|
|
43
|
+
return {
|
|
44
|
+
id: generateId(),
|
|
45
|
+
ids: [vc1Id, vc2Id],
|
|
46
|
+
source,
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
await views.load(vc);
|
|
50
|
+
test_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`);
|
|
51
|
+
if (expectedTarget) {
|
|
52
|
+
test_1.assert.isEqualDeep(passedTarget, expectedTarget, 'The target you passed did not match!');
|
|
53
|
+
}
|
|
54
|
+
if (expectedPayload) {
|
|
55
|
+
test_1.assert.isEqualDeep(passedPayload, expectedPayload, 'The payload you passed did not match!');
|
|
56
|
+
}
|
|
57
|
+
let cards = [];
|
|
58
|
+
try {
|
|
59
|
+
cards = heartwood_view_controllers_1.vcAssert.assertSkillViewRendersCards(vc, [vc1Id, vc2Id]);
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
test_1.assert.fail(`You didn't drop in the cards to your skill view! Make sure your vcIdsTransformer looks something like:
|
|
63
|
+
|
|
64
|
+
vcIdsTransformer: (payload) => {
|
|
65
|
+
return payload.vcIds
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
You'll also want to add the cards to a local prop like:
|
|
69
|
+
|
|
70
|
+
this.cards.push(...cards)
|
|
71
|
+
|
|
72
|
+
Then make sure you render the cards like:
|
|
73
|
+
|
|
74
|
+
public render() {
|
|
75
|
+
return {
|
|
76
|
+
layouts: splitCardsIntoLayouts(this.cards.map((c) => c.render()))
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
The original error is: ${(_a = err.stack) !== null && _a !== void 0 ? _a : err.message}
|
|
81
|
+
`);
|
|
82
|
+
}
|
|
83
|
+
if (shouldInvoke) {
|
|
84
|
+
const { methodName, expectedParams } = shouldInvoke;
|
|
85
|
+
test_1.assert.isTrue(
|
|
86
|
+
//@ts-ignore
|
|
87
|
+
cards.filter((c) => c.wasHit).length === cards.length, `You gotta call cardVc.${methodName}(...) on all the cards you get back!`);
|
|
88
|
+
if (expectedParams) {
|
|
89
|
+
//@ts-ignore
|
|
90
|
+
const passed = cards[0].passedParams;
|
|
91
|
+
test_1.assert.isEqualDeep(passed, expectedParams, `You didn't pass the expected params to ${methodName}!`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
function generateVcSource(options) {
|
|
97
|
+
const { vcId, count, stubMethod } = options;
|
|
98
|
+
return [
|
|
99
|
+
`class TestEventViewController${count} {
|
|
100
|
+
alert = function() {}
|
|
101
|
+
${stubMethod !== null && stubMethod !== void 0 ? stubMethod : 'noop'} = function () {
|
|
102
|
+
this.wasHit = true
|
|
103
|
+
this.passedParams = Array.prototype.slice.call(arguments)
|
|
104
|
+
}
|
|
105
|
+
render = function() {
|
|
106
|
+
return {
|
|
107
|
+
id: '${vcId}',
|
|
108
|
+
controller: this,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}`,
|
|
112
|
+
`TestEventViewController${count}.id = '${vcId}'`,
|
|
113
|
+
].join('\n\n');
|
|
114
|
+
}
|
|
115
|
+
function generateId() {
|
|
116
|
+
return `${Math.round(new Date().getTime() * (Math.random() * 100))}`;
|
|
117
|
+
}
|
|
118
|
+
exports.generateId = generateId;
|
|
119
|
+
class ThrowingErrorCardVc extends heartwood_view_controllers_1.AbstractViewController {
|
|
120
|
+
constructor(options) {
|
|
121
|
+
super(options);
|
|
122
|
+
//@ts-ignore
|
|
123
|
+
if (options.error) {
|
|
124
|
+
//@ts-ignore
|
|
125
|
+
throw options.error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
render() {
|
|
129
|
+
return {};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.default = remoteVcAssert;
|
|
133
|
+
//# sourceMappingURL=remoteVcAssert.js.map
|
|
@@ -57,7 +57,11 @@ class CardRegistrar {
|
|
|
57
57
|
}
|
|
58
58
|
catch (err) {
|
|
59
59
|
console.error(err);
|
|
60
|
-
return [
|
|
60
|
+
return [
|
|
61
|
+
this.remoteVcFactory.Controller('heartwood.error-card', {
|
|
62
|
+
error: err,
|
|
63
|
+
}),
|
|
64
|
+
];
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
67
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sprucelabs/spruce-heartwood-utils",
|
|
3
3
|
"description": "Heartwood Utilities",
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.6.1",
|
|
5
5
|
"skill": {
|
|
6
6
|
"namespace": "heartwood"
|
|
7
7
|
},
|
|
@@ -29,7 +29,11 @@
|
|
|
29
29
|
"build/ThemeManager.js",
|
|
30
30
|
"build/ThemeManager.d.ts",
|
|
31
31
|
"build/esm/ThemeManager.js",
|
|
32
|
-
"build/esm/ThemeManager.d.ts"
|
|
32
|
+
"build/esm/ThemeManager.d.ts",
|
|
33
|
+
"build/tests/remoteVcAssert.js",
|
|
34
|
+
"build/tests/remoteVcAssert.d.ts",
|
|
35
|
+
"build/esm/tests/remoteVcAssert.js",
|
|
36
|
+
"build/esm/tests/remoteVcAssert.d.ts"
|
|
33
37
|
],
|
|
34
38
|
"keywords": [],
|
|
35
39
|
"scripts": {
|
|
@@ -38,7 +42,11 @@
|
|
|
38
42
|
"dependencies": {
|
|
39
43
|
"@sprucelabs/heartwood-view-controllers": "latest",
|
|
40
44
|
"@sprucelabs/mercury-client": "latest",
|
|
41
|
-
"@sprucelabs/
|
|
45
|
+
"@sprucelabs/mercury-types": "latest",
|
|
46
|
+
"@sprucelabs/spruce-event-utils": "latest",
|
|
47
|
+
"@sprucelabs/spruce-schema": "latest",
|
|
48
|
+
"@sprucelabs/spruce-test-fixtures": "latest",
|
|
49
|
+
"@sprucelabs/test": "latest"
|
|
42
50
|
},
|
|
43
51
|
"engines": {
|
|
44
52
|
"node": "16.x",
|