@equinor/fusion-framework-module-bookmark 4.0.3 → 4.1.0-next.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/CHANGELOG.md +59 -0
- package/README.md +42 -0
- package/dist/esm/BookmarkModuleConfigurator.js +2 -1
- package/dist/esm/BookmarkModuleConfigurator.js.map +1 -1
- package/dist/esm/__tests__/mock/bookmark-mock.test.js +151 -0
- package/dist/esm/__tests__/mock/bookmark-mock.test.js.map +1 -0
- package/dist/esm/mock/BookmarkMockClient.js +281 -0
- package/dist/esm/mock/BookmarkMockClient.js.map +1 -0
- package/dist/esm/mock/BookmarkMockConfigurator.js +138 -0
- package/dist/esm/mock/BookmarkMockConfigurator.js.map +1 -0
- package/dist/esm/mock/index.js +26 -0
- package/dist/esm/mock/index.js.map +1 -0
- package/dist/esm/mock/module.js +42 -0
- package/dist/esm/mock/module.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/BookmarkModuleConfigurator.d.ts +1 -0
- package/dist/types/__tests__/mock/bookmark-mock.test.d.ts +1 -0
- package/dist/types/mock/BookmarkMockClient.d.ts +121 -0
- package/dist/types/mock/BookmarkMockConfigurator.d.ts +86 -0
- package/dist/types/mock/index.d.ts +25 -0
- package/dist/types/mock/module.d.ts +43 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +20 -11
- package/src/BookmarkModuleConfigurator.ts +2 -1
- package/src/__tests__/mock/bookmark-mock.test.ts +199 -0
- package/src/mock/BookmarkMockClient.ts +310 -0
- package/src/mock/BookmarkMockConfigurator.ts +159 -0
- package/src/mock/index.ts +25 -0
- package/src/mock/module.ts +64 -0
- package/src/version.ts +1 -1
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { BookmarkModuleConfigurator } from '../BookmarkModuleConfigurator';
|
|
3
|
+
import { BookmarkMockClient } from './BookmarkMockClient';
|
|
4
|
+
/**
|
|
5
|
+
* Fallback application resolver used when the mock is configured standalone,
|
|
6
|
+
* without a real `app` module registered.
|
|
7
|
+
*/
|
|
8
|
+
const mockApplicationResolver = async () => ({
|
|
9
|
+
appKey: 'mock-app',
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Fallback context resolver used when the mock is configured standalone,
|
|
13
|
+
* without a real `context` module registered.
|
|
14
|
+
*/
|
|
15
|
+
const mockContextResolver = async () => undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The real bookmark configurator, backed by an in-memory {@link BookmarkMockClient}.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Extends {@link BookmarkModuleConfigurator} directly, so the whole builder API
|
|
21
|
+
* (source system, filters, resolvers, `setParent`) stays available. Only a
|
|
22
|
+
* default client is added — through the same
|
|
23
|
+
* {@link BookmarkModuleConfigurator.setClient | setClient} seam a caller would
|
|
24
|
+
* use to plug in their own client — so an explicit `setClient()` call still
|
|
25
|
+
* replaces it outright, exactly as it would on the real configurator.
|
|
26
|
+
*
|
|
27
|
+
* Seeded bookmarks and favorites flow through the real `BookmarkProvider` and
|
|
28
|
+
* `bookmark-flows/` epics unmodified: create, update, delete, and favorite
|
|
29
|
+
* calls all reach {@link BookmarkMockClient}, not a stand-in.
|
|
30
|
+
*
|
|
31
|
+
* @example Seed bookmarks and a current bookmark
|
|
32
|
+
* ```typescript
|
|
33
|
+
* enableBookmarkMock(configurator, (builder) => {
|
|
34
|
+
* builder.setBookmarks([myBookmark]);
|
|
35
|
+
* builder.setCurrentBookmark(myBookmark.id);
|
|
36
|
+
* builder.setFavorite(myBookmark.id, true);
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Take full control of the client
|
|
41
|
+
* ```typescript
|
|
42
|
+
* enableBookmarkMock(configurator, (builder) => {
|
|
43
|
+
* builder.setClient(myOwnBookmarkClient);
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export class BookmarkMockConfigurator extends BookmarkModuleConfigurator {
|
|
48
|
+
#client = new BookmarkMockClient();
|
|
49
|
+
#currentId;
|
|
50
|
+
/**
|
|
51
|
+
* Seeds the bookmarks the mock client resolves through `getAllBookmarks`,
|
|
52
|
+
* `getBookmarkById`, and `getBookmarkData`.
|
|
53
|
+
*
|
|
54
|
+
* @param items - The bookmarks to seed. Replaces any previously seeded bookmarks.
|
|
55
|
+
* @returns `this`, for chaining.
|
|
56
|
+
*/
|
|
57
|
+
setBookmarks(items) {
|
|
58
|
+
this.#client.setBookmarks(items);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Declares which seeded bookmark `IBookmarkProvider.currentBookmark` reports
|
|
63
|
+
* as active once the module initializes.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* `BookmarkProvider` only reads its initial current bookmark from a parent
|
|
67
|
+
* provider (see {@link BookmarkModuleConfigurator.setParent}), so this
|
|
68
|
+
* registers a synthetic parent exposing the seeded bookmark — the same seam
|
|
69
|
+
* a real nested-portal provider would use, just standing in for one.
|
|
70
|
+
*
|
|
71
|
+
* @param bookmarkId - The id of a bookmark previously passed to {@link setBookmarks},
|
|
72
|
+
* or `undefined` to leave the current bookmark unset.
|
|
73
|
+
* @returns `this`, for chaining.
|
|
74
|
+
*/
|
|
75
|
+
setCurrentBookmark(bookmarkId) {
|
|
76
|
+
this.#currentId = bookmarkId;
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Marks a seeded bookmark as a favorite, or clears it, reflected through
|
|
81
|
+
* `IBookmarkClient.isBookmarkFavorite`.
|
|
82
|
+
*
|
|
83
|
+
* @param bookmarkId - The id of the bookmark to update.
|
|
84
|
+
* @param isFavorite - `true` to favorite the bookmark, `false` to clear it. Defaults to `true`.
|
|
85
|
+
* @returns `this`, for chaining.
|
|
86
|
+
*/
|
|
87
|
+
setFavorite(bookmarkId, isFavorite = true) {
|
|
88
|
+
this.#client.setFavorite(bookmarkId, isFavorite);
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Installs the mock client and a synthetic current-bookmark parent before
|
|
93
|
+
* building the configuration, unless the caller already declared their own.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* Also falls back to trivial application/context resolvers when neither an
|
|
97
|
+
* `app` nor a `context` module is registered alongside this mock — both are
|
|
98
|
+
* required by {@link BookmarkModuleConfig}'s schema, but a standalone test
|
|
99
|
+
* has no reason to pull in either module just to satisfy it. Registering a
|
|
100
|
+
* real `app`/`context` module still wins, exactly as it does on the real
|
|
101
|
+
* configurator.
|
|
102
|
+
*
|
|
103
|
+
* @param init - The config builder callback arguments.
|
|
104
|
+
* @param initial - An optional initial config to merge into the returned config.
|
|
105
|
+
* @returns The observable configuration, produced by the real configurator.
|
|
106
|
+
*/
|
|
107
|
+
_createConfig(init, initial) {
|
|
108
|
+
// only stand in a mock client when the caller hasn't set their own
|
|
109
|
+
if (!this._has('client')) {
|
|
110
|
+
this.setClient(this.#client);
|
|
111
|
+
}
|
|
112
|
+
// only stand in a synthetic parent when a current bookmark was seeded and
|
|
113
|
+
// the caller hasn't declared their own parent provider
|
|
114
|
+
if (this.#currentId && !this._has('parent')) {
|
|
115
|
+
const current = this.#client.getBookmark(this.#currentId) ?? null;
|
|
116
|
+
const parent = {
|
|
117
|
+
currentBookmark: current,
|
|
118
|
+
currentBookmark$: of(current),
|
|
119
|
+
};
|
|
120
|
+
this.setParent(parent);
|
|
121
|
+
}
|
|
122
|
+
// no app module means the real default resolver would resolve to `undefined`, which fails
|
|
123
|
+
// the required `resolve.application` schema field — but `initial.resolve.application` may
|
|
124
|
+
// already carry a resolver inherited from a parent config, which must not be overwritten
|
|
125
|
+
if (!this._has('resolve.application') &&
|
|
126
|
+
!initial?.resolve?.application &&
|
|
127
|
+
!init.hasModule('app')) {
|
|
128
|
+
this.setApplicationResolver(async () => mockApplicationResolver);
|
|
129
|
+
}
|
|
130
|
+
// no context module means the real default resolver would resolve to `undefined`, which
|
|
131
|
+
// fails the required `resolve.context` schema field — same inherited-config caveat as above
|
|
132
|
+
if (!this._has('resolve.context') && !initial?.resolve?.context && !init.hasModule('context')) {
|
|
133
|
+
this.setContextResolver(async () => mockContextResolver);
|
|
134
|
+
}
|
|
135
|
+
return super._createConfig(init, initial);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=BookmarkMockConfigurator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BookmarkMockConfigurator.js","sourceRoot":"","sources":["../../../src/mock/BookmarkMockConfigurator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAI1B,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAI3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;GAGG;AACH,MAAM,uBAAuB,GAAmD,KAAK,IAAI,EAAE,CAAC,CAAC;IAC3F,MAAM,EAAE,UAAU;CACnB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,mBAAmB,GAA+C,KAAK,IAAI,EAAE,CAAC,SAAS,CAAC;AAE9F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,wBAAyB,SAAQ,0BAA0B;IACtE,OAAO,GAAG,IAAI,kBAAkB,EAAE,CAAC;IACnC,UAAU,CAAU;IAEpB;;;;;;OAMG;IACI,YAAY,CAAC,KAAyB;QAC3C,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;OAaG;IACI,kBAAkB,CAAC,UAA8B;QACtD,IAAI,CAAC,UAAU,G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AC,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9F,IAAI,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE,CAAC,mBAAmB,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock bookmark module for tests: real provider, real configurator, in-memory client.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Substituting `IBookmarkClient` is the smallest change that removes the
|
|
6
|
+
* Fusion Core Services backend from a test. Everything above it — the
|
|
7
|
+
* `BookmarkProvider` store, `bookmark-flows/` epics, payload generators, and
|
|
8
|
+
* events — is the production code path.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { enableBookmarkMock } from '@equinor/fusion-framework-module-bookmark/mock';
|
|
13
|
+
*
|
|
14
|
+
* enableBookmarkMock(configurator, (builder) => {
|
|
15
|
+
* builder.setBookmarks([myBookmark]);
|
|
16
|
+
* builder.setCurrentBookmark(myBookmark.id);
|
|
17
|
+
* builder.setFavorite(myBookmark.id, true);
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
*/
|
|
23
|
+
export { BookmarkMockClient } from './BookmarkMockClient';
|
|
24
|
+
export { BookmarkMockConfigurator } from './BookmarkMockConfigurator';
|
|
25
|
+
export { enableBookmarkMock, bookmarkMockModule } from './module';
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mock/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAA6B,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { module } from '../bookmark-module';
|
|
2
|
+
import { BookmarkMockConfigurator } from './BookmarkMockConfigurator';
|
|
3
|
+
/**
|
|
4
|
+
* The bookmark module with a mock, in-memory client instead of a live
|
|
5
|
+
* `@equinor/fusion-framework-module-services` connection.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Only `configure` differs from the real module. `initialize` is the
|
|
9
|
+
* production one, untouched, so the real `BookmarkProvider` and
|
|
10
|
+
* `bookmark-flows/` epics run exactly as they do in production — a test
|
|
11
|
+
* observes the real create/update/delete/favorite flow, not a rehearsal of it.
|
|
12
|
+
*/
|
|
13
|
+
export const bookmarkMockModule = {
|
|
14
|
+
...module,
|
|
15
|
+
configure: () => new BookmarkMockConfigurator(),
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Enables the bookmark module against an in-memory mock client, so a test
|
|
19
|
+
* needs no network and no real Fusion Core Services backend.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Registered last, this replaces whichever bookmark module the configurator
|
|
23
|
+
* already carries, so it works on a `FrameworkConfigurator` that pre-registers
|
|
24
|
+
* the real one.
|
|
25
|
+
*
|
|
26
|
+
* @param configurator - The modules configurator to register on.
|
|
27
|
+
* @param configure - Optional callback to seed bookmarks, the current bookmark, or favorites.
|
|
28
|
+
* @template TModules - The array of module descriptors managed by `configurator`.
|
|
29
|
+
* @template TRef - Reference type forwarded to `configure`, inferred from `configurator`.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* enableBookmarkMock(configurator, (builder) => {
|
|
34
|
+
* builder.setBookmarks([myBookmark]);
|
|
35
|
+
* builder.setCurrentBookmark(myBookmark.id);
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export const enableBookmarkMock = (configurator, configure) => {
|
|
40
|
+
configurator.addConfig({ module: bookmarkMockModule, configure });
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/mock/module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAuB,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAmB;IAChD,GAAG,MAAM;IACT,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,wBAAwB,EAAE;CAChD,CAAC;AAYF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAIhC,YAAkD,EAClD,SAAsC,EAChC,EAAE;IACR,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,SAAS,EAE7D,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC"}
|