@sprucelabs/spruce-heartwood-utils 19.6.0 → 19.6.2

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.
@@ -1,15 +1,19 @@
1
- import { ViewControllerMap, ControllerOptions, ViewController } from '@sprucelabs/heartwood-view-controllers';
1
+ import { ViewControllerMap, ControllerOptions, ViewController, SkillViewController } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { RemoteFactoryOptions, RemoteViewControllerFactory } from '../../skillViews/RemoteViewControllerFactory';
3
3
  export default class MockRemoteViewControllerFactory implements RemoteViewControllerFactory {
4
4
  private static instance?;
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];
14
+ static dropInRemoteController(id: string, Class: new (args: any) => ViewController<any>): void;
15
+ private static dropInControllers;
16
+ assertSkillViewRendersRemoteCard(vc: SkillViewController, id: string): void;
13
17
  static reset(): void;
14
18
  static getInstance(): MockRemoteViewControllerFactory;
15
19
  getTheme(_namespace?: string | undefined): undefined;
@@ -18,3 +22,4 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
18
22
  hasController(name: string): boolean;
19
23
  RemoteController(name: string, options: Record<string, any>): Promise<any>;
20
24
  }
25
+ export type MockDroppedInControllers = Record<string, new (args: any) => ViewController<any>>;
@@ -1,20 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
3
4
  const test_utils_1 = require("@sprucelabs/test-utils");
4
5
  class MockRemoteViewControllerFactory {
5
6
  constructor(options) {
6
7
  this.loadedControllers = {};
7
8
  MockRemoteViewControllerFactory.instance = this;
8
9
  this.views = options.vcFactory;
10
+ MockRemoteViewControllerFactory.dropInControllers(this);
9
11
  }
10
12
  fetchRemoteController(_name) {
11
- throw new Error('Method not implemented.');
13
+ throw new Error('Not implemented in mock.');
12
14
  }
13
15
  Controller(_name, _options) {
14
16
  return {};
15
17
  }
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
+ }
36
+ }
37
+ assertSkillViewRendersRemoteCard(vc, id) {
38
+ const cards = heartwood_view_controllers_1.vcAssert.assertSkillViewRendersCards(vc);
39
+ test_utils_1.assert.isTruthy(
40
+ //@ts-ignore
41
+ cards.find((c) => c.id === id), `Could not find the remote card with the id '${id}'!`);
42
+ }
16
43
  static reset() {
17
44
  delete this.instance;
45
+ delete this.controllers;
18
46
  }
19
47
  static getInstance() {
20
48
  if (!this.instance) {
@@ -1,15 +1,19 @@
1
- import { ViewControllerMap, ControllerOptions, ViewController } from '@sprucelabs/heartwood-view-controllers';
1
+ import { ViewControllerMap, ControllerOptions, ViewController, SkillViewController } from '@sprucelabs/heartwood-view-controllers';
2
2
  import { RemoteFactoryOptions, RemoteViewControllerFactory } from '../../skillViews/RemoteViewControllerFactory';
3
3
  export default class MockRemoteViewControllerFactory implements RemoteViewControllerFactory {
4
4
  private static instance?;
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];
14
+ static dropInRemoteController(id: string, Class: new (args: any) => ViewController<any>): void;
15
+ private static dropInControllers;
16
+ assertSkillViewRendersRemoteCard(vc: SkillViewController, id: string): void;
13
17
  static reset(): void;
14
18
  static getInstance(): MockRemoteViewControllerFactory;
15
19
  getTheme(_namespace?: string | undefined): undefined;
@@ -18,3 +22,4 @@ export default class MockRemoteViewControllerFactory implements RemoteViewContro
18
22
  hasController(name: string): boolean;
19
23
  RemoteController(name: string, options: Record<string, any>): Promise<any>;
20
24
  }
25
+ export type MockDroppedInControllers = Record<string, new (args: any) => ViewController<any>>;
@@ -7,21 +7,49 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { vcAssert, } from '@sprucelabs/heartwood-view-controllers';
10
11
  import { assert } from '@sprucelabs/test-utils';
11
12
  export default class MockRemoteViewControllerFactory {
12
13
  constructor(options) {
13
14
  this.loadedControllers = {};
14
15
  MockRemoteViewControllerFactory.instance = this;
15
16
  this.views = options.vcFactory;
17
+ MockRemoteViewControllerFactory.dropInControllers(this);
16
18
  }
17
19
  fetchRemoteController(_name) {
18
- throw new Error('Method not implemented.');
20
+ throw new Error('Not implemented in mock.');
19
21
  }
20
22
  Controller(_name, _options) {
21
23
  return {};
22
24
  }
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
+ }
43
+ }
44
+ assertSkillViewRendersRemoteCard(vc, id) {
45
+ const cards = vcAssert.assertSkillViewRendersCards(vc);
46
+ assert.isTruthy(
47
+ //@ts-ignore
48
+ cards.find((c) => c.id === id), `Could not find the remote card with the id '${id}'!`);
49
+ }
23
50
  static reset() {
24
51
  delete this.instance;
52
+ delete this.controllers;
25
53
  }
26
54
  static getInstance() {
27
55
  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.0",
4
+ "version": "19.6.2",
5
5
  "skill": {
6
6
  "namespace": "heartwood"
7
7
  },