@sprucelabs/spruce-heartwood-utils 19.6.1 → 19.6.3

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.
@@ -5,12 +5,14 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
5
5
  private loadedControllers;
6
6
  private remoteControllerOptions?;
7
7
  private views;
8
+ private static controllers?;
8
9
  constructor(options: RemoteFactoryOptions);
9
10
  fetchRemoteController(_name: string): Promise<(new () => ViewController<any>) & {
10
11
  id: string;
11
12
  }>;
12
13
  Controller<N extends keyof ViewControllerMap, O extends ControllerOptions<N>>(_name: N, _options: O): ViewControllerMap[N];
13
- dropInRemoteController(id: string, Class: new (args: any) => ViewController<any>): void;
14
+ static dropInRemoteController(id: string, Class: new (args: any) => ViewController<any>): void;
15
+ private static dropInControllers;
14
16
  assertSkillViewRendersRemoteCard(vc: SkillViewController, id: string): void;
15
17
  static reset(): void;
16
18
  static getInstance(): MockRemoteViewControllerFactory;
@@ -20,3 +22,4 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
20
22
  hasController(name: string): boolean;
21
23
  RemoteController(name: string, options: Record<string, any>): Promise<any>;
22
24
  }
25
+ export type MockDroppedInControllers = Record<string, new (args: any) => ViewController<any>>;
@@ -7,24 +7,43 @@ class MockRemoteViewControllerFactory {
7
7
  this.loadedControllers = {};
8
8
  MockRemoteViewControllerFactory.instance = this;
9
9
  this.views = options.vcFactory;
10
+ MockRemoteViewControllerFactory.dropInControllers(this);
10
11
  }
11
12
  fetchRemoteController(_name) {
12
- throw new Error('Method not implemented.');
13
+ throw new Error('Not implemented in mock.');
13
14
  }
14
15
  Controller(_name, _options) {
15
16
  return {};
16
17
  }
17
- dropInRemoteController(id, Class) {
18
- this.views.setController(id, Class);
18
+ static dropInRemoteController(id, Class) {
19
+ if (!this.controllers) {
20
+ this.controllers = {};
21
+ }
22
+ this.controllers[id] = Class;
23
+ if (this.instance) {
24
+ const instance = this.instance;
25
+ this.dropInControllers(instance);
26
+ }
27
+ }
28
+ static dropInControllers(instance) {
29
+ const controllers = this.controllers;
30
+ if (controllers) {
31
+ for (const key of Object.keys(controllers)) {
32
+ const vc = controllers[key];
33
+ instance.views.setController(key, vc);
34
+ }
35
+ }
19
36
  }
20
37
  assertSkillViewRendersRemoteCard(vc, id) {
21
38
  const cards = heartwood_view_controllers_1.vcAssert.assertSkillViewRendersCards(vc);
22
- test_utils_1.assert.isTruthy(
23
39
  //@ts-ignore
24
- cards.find((c) => c.id === id), `Could not find the remote card with the id '${id}'!`);
40
+ const match = cards.find((c) => c.id === id);
41
+ test_utils_1.assert.isTruthy(match, `Could not find the remote card with the id '${id}'!`);
42
+ heartwood_view_controllers_1.vcAssert.assertControllerInstanceOf(match, MockRemoteViewControllerFactory.controllers[id]);
25
43
  }
26
44
  static reset() {
27
45
  delete this.instance;
46
+ delete this.controllers;
28
47
  }
29
48
  static getInstance() {
30
49
  if (!this.instance) {
@@ -5,12 +5,14 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
5
5
  private loadedControllers;
6
6
  private remoteControllerOptions?;
7
7
  private views;
8
+ private static controllers?;
8
9
  constructor(options: RemoteFactoryOptions);
9
10
  fetchRemoteController(_name: string): Promise<(new () => ViewController<any>) & {
10
11
  id: string;
11
12
  }>;
12
13
  Controller<N extends keyof ViewControllerMap, O extends ControllerOptions<N>>(_name: N, _options: O): ViewControllerMap[N];
13
- dropInRemoteController(id: string, Class: new (args: any) => ViewController<any>): void;
14
+ static dropInRemoteController(id: string, Class: new (args: any) => ViewController<any>): void;
15
+ private static dropInControllers;
14
16
  assertSkillViewRendersRemoteCard(vc: SkillViewController, id: string): void;
15
17
  static reset(): void;
16
18
  static getInstance(): MockRemoteViewControllerFactory;
@@ -20,3 +22,4 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
20
22
  hasController(name: string): boolean;
21
23
  RemoteController(name: string, options: Record<string, any>): Promise<any>;
22
24
  }
25
+ export type MockDroppedInControllers = Record<string, new (args: any) => ViewController<any>>;
@@ -14,24 +14,43 @@ export default class MockRemoteViewControllerFactory {
14
14
  this.loadedControllers = {};
15
15
  MockRemoteViewControllerFactory.instance = this;
16
16
  this.views = options.vcFactory;
17
+ MockRemoteViewControllerFactory.dropInControllers(this);
17
18
  }
18
19
  fetchRemoteController(_name) {
19
- throw new Error('Method not implemented.');
20
+ throw new Error('Not implemented in mock.');
20
21
  }
21
22
  Controller(_name, _options) {
22
23
  return {};
23
24
  }
24
- dropInRemoteController(id, Class) {
25
- this.views.setController(id, Class);
25
+ static dropInRemoteController(id, Class) {
26
+ if (!this.controllers) {
27
+ this.controllers = {};
28
+ }
29
+ this.controllers[id] = Class;
30
+ if (this.instance) {
31
+ const instance = this.instance;
32
+ this.dropInControllers(instance);
33
+ }
34
+ }
35
+ static dropInControllers(instance) {
36
+ const controllers = this.controllers;
37
+ if (controllers) {
38
+ for (const key of Object.keys(controllers)) {
39
+ const vc = controllers[key];
40
+ instance.views.setController(key, vc);
41
+ }
42
+ }
26
43
  }
27
44
  assertSkillViewRendersRemoteCard(vc, id) {
28
45
  const cards = vcAssert.assertSkillViewRendersCards(vc);
29
- assert.isTruthy(
30
46
  //@ts-ignore
31
- cards.find((c) => c.id === id), `Could not find the remote card with the id '${id}'!`);
47
+ const match = cards.find((c) => c.id === id);
48
+ assert.isTruthy(match, `Could not find the remote card with the id '${id}'!`);
49
+ vcAssert.assertControllerInstanceOf(match, MockRemoteViewControllerFactory.controllers[id]);
32
50
  }
33
51
  static reset() {
34
52
  delete this.instance;
53
+ delete this.controllers;
35
54
  }
36
55
  static getInstance() {
37
56
  if (!this.instance) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-heartwood-utils",
3
3
  "description": "Heartwood Utilities",
4
- "version": "19.6.1",
4
+ "version": "19.6.3",
5
5
  "skill": {
6
6
  "namespace": "heartwood"
7
7
  },