@sprucelabs/spruce-heartwood-utils 29.6.0 → 29.7.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 +7 -4
- package/build/__tests__/support/MockRemoteViewControllerFactory.js +42 -13
- package/build/esm/__tests__/support/MockRemoteViewControllerFactory.d.ts +7 -4
- package/build/esm/__tests__/support/MockRemoteViewControllerFactory.js +44 -14
- package/package.json +1 -1
@@ -3,9 +3,11 @@ import { RemoteFactoryOptions, RemoteViewControllerFactory } from '../../skillVi
|
|
3
3
|
export default class MockRemoteViewControllerFactory implements RemoteViewControllerFactory {
|
4
4
|
private static instance?;
|
5
5
|
private loadedControllers;
|
6
|
-
private
|
6
|
+
private lastRemoteCostructorOptions?;
|
7
|
+
private constructorOptionsById;
|
7
8
|
private views;
|
8
9
|
private static controllers?;
|
10
|
+
private static wasReset;
|
9
11
|
constructor(options: RemoteFactoryOptions);
|
10
12
|
fetchRemoteController(_name: string): Promise<(new () => ViewController<any>) & {
|
11
13
|
id: string;
|
@@ -13,13 +15,14 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
|
|
13
15
|
Controller<N extends keyof ViewControllerMap, O extends ControllerOptions<N>>(_name: N, _options: O): ViewControllerMap[N];
|
14
16
|
static dropInRemoteController(id: string, Class: new (args: any) => ViewController<any>): void;
|
15
17
|
private static dropInControllers;
|
16
|
-
assertSkillViewRendersRemoteCard(vc: SkillViewController,
|
18
|
+
assertSkillViewRendersRemoteCard(vc: SkillViewController, name: string, id?: string): void;
|
17
19
|
static reset(): void;
|
18
20
|
static getInstance(): MockRemoteViewControllerFactory;
|
19
21
|
getTheme(_namespace?: string | undefined): undefined;
|
20
22
|
assertDidNotFetchRemoteController(id: string): void;
|
21
|
-
assertFetchedRemoteController(
|
23
|
+
assertFetchedRemoteController(name: string, options?: Record<string, any>): void;
|
24
|
+
assertRemoteCardConstructorOptionsEqual(id: string, expected: Record<string, any>): void;
|
22
25
|
hasController(name: string): boolean;
|
23
|
-
RemoteController(
|
26
|
+
RemoteController(id: string, options: Record<string, any>): Promise<any>;
|
24
27
|
}
|
25
28
|
export type MockDroppedInControllers = Record<string, new (args: any) => ViewController<any>>;
|
@@ -5,12 +5,13 @@ const test_utils_1 = require("@sprucelabs/test-utils");
|
|
5
5
|
class MockRemoteViewControllerFactory {
|
6
6
|
constructor(options) {
|
7
7
|
this.loadedControllers = {};
|
8
|
+
this.constructorOptionsById = {};
|
8
9
|
MockRemoteViewControllerFactory.instance = this;
|
9
10
|
this.views = options.vcFactory;
|
10
11
|
MockRemoteViewControllerFactory.dropInControllers(this);
|
11
12
|
}
|
12
13
|
fetchRemoteController(_name) {
|
13
|
-
throw new Error('Not implemented in mock.');
|
14
|
+
throw new Error('Not implemented in mock. Maybe you meant to use this.remote.RemoteController(..)?');
|
14
15
|
}
|
15
16
|
Controller(_name, _options) {
|
16
17
|
return {};
|
@@ -34,20 +35,41 @@ class MockRemoteViewControllerFactory {
|
|
34
35
|
}
|
35
36
|
}
|
36
37
|
}
|
37
|
-
assertSkillViewRendersRemoteCard(vc, id) {
|
38
|
+
assertSkillViewRendersRemoteCard(vc, name, id) {
|
39
|
+
var _a;
|
40
|
+
const Class = (_a = MockRemoteViewControllerFactory.controllers) === null || _a === void 0 ? void 0 : _a[name];
|
41
|
+
test_utils_1.assert.isTruthy(Class, `You did not drop in a remote card with the name '${name}'! Try MockRemoteViewControllerFactory.dropInRemoteController('${name}', Class) in your beforeEach().`);
|
38
42
|
const cards = heartwood_view_controllers_1.vcAssert.assertSkillViewRendersCards(vc);
|
43
|
+
const cardsWithNoControllers = cards.filter((c) => !c);
|
44
|
+
test_utils_1.assert.isLength(cardsWithNoControllers, 0, `Your remote card did not render with a controller. Try extending CardViewControllerImpl or rendering a CardViewController in your card's render() method:\n\npublic render() {
|
45
|
+
return this.cardVc.render()
|
46
|
+
}`);
|
47
|
+
const cardsAndParents = [];
|
48
|
+
for (const card of cards) {
|
49
|
+
cardsAndParents.push(card);
|
50
|
+
// @ts-ignore
|
51
|
+
if (card.getParent) {
|
52
|
+
//@ts-ignore
|
53
|
+
cardsAndParents.push(card.getParent());
|
54
|
+
}
|
55
|
+
}
|
39
56
|
//@ts-ignore
|
40
|
-
|
41
|
-
test_utils_1.assert.isTruthy(match, `Could not find the remote card with the id '${
|
42
|
-
|
57
|
+
let match = cardsAndParents.find((c) => c.id === name);
|
58
|
+
test_utils_1.assert.isTruthy(match, `Could not find the remote card with the id '${name}' Make sure your are rendering it!`);
|
59
|
+
if (id) {
|
60
|
+
match = heartwood_view_controllers_1.vcAssert.assertSkillViewRendersCard(vc, id);
|
61
|
+
}
|
62
|
+
heartwood_view_controllers_1.vcAssert.assertControllerInstanceOf(match, Class);
|
43
63
|
}
|
44
64
|
static reset() {
|
45
65
|
delete this.instance;
|
46
66
|
delete this.controllers;
|
67
|
+
this.wasReset = true;
|
47
68
|
}
|
48
69
|
static getInstance() {
|
70
|
+
test_utils_1.assert.isTruthy(this.wasReset, `You must reset your MockRemoteViewControllerFactory before getting an instance. Try MockRemoteViewControllerFactory.reset() in your test's beforeEach().`);
|
49
71
|
if (!this.instance) {
|
50
|
-
|
72
|
+
test_utils_1.assert.fail('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.remote = RemoteViewControllerFactoryImpl.Factory(...)');
|
51
73
|
}
|
52
74
|
return this.instance;
|
53
75
|
}
|
@@ -63,21 +85,28 @@ class MockRemoteViewControllerFactory {
|
|
63
85
|
}
|
64
86
|
test_utils_1.assert.fail(`You fetched the controller with the id '${id}' but you should not have.`);
|
65
87
|
}
|
66
|
-
assertFetchedRemoteController(
|
67
|
-
test_utils_1.assert.isTrue(this.hasController(
|
88
|
+
assertFetchedRemoteController(name, options) {
|
89
|
+
test_utils_1.assert.isTrue(this.hasController(name), `You never tried to fetch a controller with the name '${name}'. Try remote.RemoteController(...)`);
|
68
90
|
if (options) {
|
69
|
-
test_utils_1.assert.isEqualDeep(this.
|
91
|
+
test_utils_1.assert.isEqualDeep(this.lastRemoteCostructorOptions, options, `You did not pass the expected options to remote.RemoteController(${name}, options)`);
|
70
92
|
}
|
71
93
|
}
|
94
|
+
assertRemoteCardConstructorOptionsEqual(id, expected) {
|
95
|
+
test_utils_1.assert.isEqualDeep(this.constructorOptionsById[id], expected, `The constructor options for the remote card with id '${id}' do not match the expected options. Make sure the card you are rendering has an id using this.views.Controller('card', { id })`);
|
96
|
+
}
|
72
97
|
hasController(name) {
|
73
98
|
var _a;
|
74
99
|
return (_a = this.loadedControllers[name]) !== null && _a !== void 0 ? _a : false;
|
75
100
|
}
|
76
|
-
async RemoteController(
|
77
|
-
|
78
|
-
|
79
|
-
|
101
|
+
async RemoteController(id, options) {
|
102
|
+
var _a, _b;
|
103
|
+
test_utils_1.assert.isTruthy((_a = MockRemoteViewControllerFactory.controllers) === null || _a === void 0 ? void 0 : _a[id], `Could not find a remote card with the id '${id}'! Try MockRemoteViewControllerFactory.dropInRemoteController('${id}', Class) in your beforeEach().`);
|
104
|
+
this.loadedControllers[id] = true;
|
105
|
+
this.constructorOptionsById[(_b = options.id) !== null && _b !== void 0 ? _b : id] = options;
|
106
|
+
this.lastRemoteCostructorOptions = options;
|
107
|
+
return this.views.Controller(id, options);
|
80
108
|
}
|
81
109
|
}
|
110
|
+
MockRemoteViewControllerFactory.wasReset = false;
|
82
111
|
exports.default = MockRemoteViewControllerFactory;
|
83
112
|
//# sourceMappingURL=MockRemoteViewControllerFactory.js.map
|
@@ -3,9 +3,11 @@ import { RemoteFactoryOptions, RemoteViewControllerFactory } from '../../skillVi
|
|
3
3
|
export default class MockRemoteViewControllerFactory implements RemoteViewControllerFactory {
|
4
4
|
private static instance?;
|
5
5
|
private loadedControllers;
|
6
|
-
private
|
6
|
+
private lastRemoteCostructorOptions?;
|
7
|
+
private constructorOptionsById;
|
7
8
|
private views;
|
8
9
|
private static controllers?;
|
10
|
+
private static wasReset;
|
9
11
|
constructor(options: RemoteFactoryOptions);
|
10
12
|
fetchRemoteController(_name: string): Promise<(new () => ViewController<any>) & {
|
11
13
|
id: string;
|
@@ -13,13 +15,14 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
|
|
13
15
|
Controller<N extends keyof ViewControllerMap, O extends ControllerOptions<N>>(_name: N, _options: O): ViewControllerMap[N];
|
14
16
|
static dropInRemoteController(id: string, Class: new (args: any) => ViewController<any>): void;
|
15
17
|
private static dropInControllers;
|
16
|
-
assertSkillViewRendersRemoteCard(vc: SkillViewController,
|
18
|
+
assertSkillViewRendersRemoteCard(vc: SkillViewController, name: string, id?: string): void;
|
17
19
|
static reset(): void;
|
18
20
|
static getInstance(): MockRemoteViewControllerFactory;
|
19
21
|
getTheme(_namespace?: string | undefined): undefined;
|
20
22
|
assertDidNotFetchRemoteController(id: string): void;
|
21
|
-
assertFetchedRemoteController(
|
23
|
+
assertFetchedRemoteController(name: string, options?: Record<string, any>): void;
|
24
|
+
assertRemoteCardConstructorOptionsEqual(id: string, expected: Record<string, any>): void;
|
22
25
|
hasController(name: string): boolean;
|
23
|
-
RemoteController(
|
26
|
+
RemoteController(id: string, options: Record<string, any>): Promise<any>;
|
24
27
|
}
|
25
28
|
export type MockDroppedInControllers = Record<string, new (args: any) => ViewController<any>>;
|
@@ -9,15 +9,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
};
|
10
10
|
import { vcAssert, } from '@sprucelabs/heartwood-view-controllers';
|
11
11
|
import { assert } from '@sprucelabs/test-utils';
|
12
|
-
|
12
|
+
class MockRemoteViewControllerFactory {
|
13
13
|
constructor(options) {
|
14
14
|
this.loadedControllers = {};
|
15
|
+
this.constructorOptionsById = {};
|
15
16
|
MockRemoteViewControllerFactory.instance = this;
|
16
17
|
this.views = options.vcFactory;
|
17
18
|
MockRemoteViewControllerFactory.dropInControllers(this);
|
18
19
|
}
|
19
20
|
fetchRemoteController(_name) {
|
20
|
-
throw new Error('Not implemented in mock.');
|
21
|
+
throw new Error('Not implemented in mock. Maybe you meant to use this.remote.RemoteController(..)?');
|
21
22
|
}
|
22
23
|
Controller(_name, _options) {
|
23
24
|
return {};
|
@@ -41,20 +42,41 @@ export default class MockRemoteViewControllerFactory {
|
|
41
42
|
}
|
42
43
|
}
|
43
44
|
}
|
44
|
-
assertSkillViewRendersRemoteCard(vc, id) {
|
45
|
+
assertSkillViewRendersRemoteCard(vc, name, id) {
|
46
|
+
var _a;
|
47
|
+
const Class = (_a = MockRemoteViewControllerFactory.controllers) === null || _a === void 0 ? void 0 : _a[name];
|
48
|
+
assert.isTruthy(Class, `You did not drop in a remote card with the name '${name}'! Try MockRemoteViewControllerFactory.dropInRemoteController('${name}', Class) in your beforeEach().`);
|
45
49
|
const cards = vcAssert.assertSkillViewRendersCards(vc);
|
50
|
+
const cardsWithNoControllers = cards.filter((c) => !c);
|
51
|
+
assert.isLength(cardsWithNoControllers, 0, `Your remote card did not render with a controller. Try extending CardViewControllerImpl or rendering a CardViewController in your card's render() method:\n\npublic render() {
|
52
|
+
return this.cardVc.render()
|
53
|
+
}`);
|
54
|
+
const cardsAndParents = [];
|
55
|
+
for (const card of cards) {
|
56
|
+
cardsAndParents.push(card);
|
57
|
+
// @ts-ignore
|
58
|
+
if (card.getParent) {
|
59
|
+
//@ts-ignore
|
60
|
+
cardsAndParents.push(card.getParent());
|
61
|
+
}
|
62
|
+
}
|
46
63
|
//@ts-ignore
|
47
|
-
|
48
|
-
assert.isTruthy(match, `Could not find the remote card with the id '${
|
49
|
-
|
64
|
+
let match = cardsAndParents.find((c) => c.id === name);
|
65
|
+
assert.isTruthy(match, `Could not find the remote card with the id '${name}' Make sure your are rendering it!`);
|
66
|
+
if (id) {
|
67
|
+
match = vcAssert.assertSkillViewRendersCard(vc, id);
|
68
|
+
}
|
69
|
+
vcAssert.assertControllerInstanceOf(match, Class);
|
50
70
|
}
|
51
71
|
static reset() {
|
52
72
|
delete this.instance;
|
53
73
|
delete this.controllers;
|
74
|
+
this.wasReset = true;
|
54
75
|
}
|
55
76
|
static getInstance() {
|
77
|
+
assert.isTruthy(this.wasReset, `You must reset your MockRemoteViewControllerFactory before getting an instance. Try MockRemoteViewControllerFactory.reset() in your test's beforeEach().`);
|
56
78
|
if (!this.instance) {
|
57
|
-
|
79
|
+
assert.fail('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.remote = RemoteViewControllerFactoryImpl.Factory(...)');
|
58
80
|
}
|
59
81
|
return this.instance;
|
60
82
|
}
|
@@ -70,21 +92,29 @@ export default class MockRemoteViewControllerFactory {
|
|
70
92
|
}
|
71
93
|
assert.fail(`You fetched the controller with the id '${id}' but you should not have.`);
|
72
94
|
}
|
73
|
-
assertFetchedRemoteController(
|
74
|
-
assert.isTrue(this.hasController(
|
95
|
+
assertFetchedRemoteController(name, options) {
|
96
|
+
assert.isTrue(this.hasController(name), `You never tried to fetch a controller with the name '${name}'. Try remote.RemoteController(...)`);
|
75
97
|
if (options) {
|
76
|
-
assert.isEqualDeep(this.
|
98
|
+
assert.isEqualDeep(this.lastRemoteCostructorOptions, options, `You did not pass the expected options to remote.RemoteController(${name}, options)`);
|
77
99
|
}
|
78
100
|
}
|
101
|
+
assertRemoteCardConstructorOptionsEqual(id, expected) {
|
102
|
+
assert.isEqualDeep(this.constructorOptionsById[id], expected, `The constructor options for the remote card with id '${id}' do not match the expected options. Make sure the card you are rendering has an id using this.views.Controller('card', { id })`);
|
103
|
+
}
|
79
104
|
hasController(name) {
|
80
105
|
var _a;
|
81
106
|
return (_a = this.loadedControllers[name]) !== null && _a !== void 0 ? _a : false;
|
82
107
|
}
|
83
|
-
RemoteController(
|
108
|
+
RemoteController(id, options) {
|
84
109
|
return __awaiter(this, void 0, void 0, function* () {
|
85
|
-
|
86
|
-
|
87
|
-
|
110
|
+
var _a, _b;
|
111
|
+
assert.isTruthy((_a = MockRemoteViewControllerFactory.controllers) === null || _a === void 0 ? void 0 : _a[id], `Could not find a remote card with the id '${id}'! Try MockRemoteViewControllerFactory.dropInRemoteController('${id}', Class) in your beforeEach().`);
|
112
|
+
this.loadedControllers[id] = true;
|
113
|
+
this.constructorOptionsById[(_b = options.id) !== null && _b !== void 0 ? _b : id] = options;
|
114
|
+
this.lastRemoteCostructorOptions = options;
|
115
|
+
return this.views.Controller(id, options);
|
88
116
|
});
|
89
117
|
}
|
90
118
|
}
|
119
|
+
MockRemoteViewControllerFactory.wasReset = false;
|
120
|
+
export default MockRemoteViewControllerFactory;
|