@jpmorganchase/mosaic-store 0.1.0-beta.71 → 0.1.0-beta.73
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/package.json +4 -1
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -372
- package/src/__tests__/store.test.ts +0 -210
- package/src/__tests__/test-utils/utils.tsx +0 -26
- package/src/__tests__/useAppHeader.test.ts +0 -157
- package/src/__tests__/useBreadcrumbs.test.ts +0 -42
- package/src/__tests__/useColorMode.test.ts +0 -12
- package/src/__tests__/useFooter.test.ts +0 -64
- package/src/__tests__/useLayout.test.ts +0 -24
- package/src/__tests__/useMeta.test.ts +0 -35
- package/src/__tests__/useRoute.test.ts +0 -24
- package/src/__tests__/useSearchIndex.test.ts +0 -86
- package/src/__tests__/useStoreActions.test.ts +0 -35
- package/src/__tests__/useTableOfContents.test.ts +0 -32
- package/src/index.ts +0 -14
- package/src/store.ts +0 -140
- package/src/types/appHeader.ts +0 -80
- package/src/types/breadcrumbs.ts +0 -21
- package/src/types/colorMode.ts +0 -4
- package/src/types/footer.ts +0 -17
- package/src/types/helpLinks.ts +0 -13
- package/src/types/index.ts +0 -12
- package/src/types/layout.ts +0 -7
- package/src/types/meta.ts +0 -13
- package/src/types/navigation.ts +0 -23
- package/src/types/route.ts +0 -7
- package/src/types/searchIndex.ts +0 -21
- package/src/types/sharedConfig.ts +0 -15
- package/src/types/sidebar.ts +0 -24
- package/src/types/tableOfContents.ts +0 -19
- package/src/useAppHeader.ts +0 -46
- package/src/useBreadcrumbs.ts +0 -11
- package/src/useColorMode.ts +0 -8
- package/src/useFooter.ts +0 -10
- package/src/useLayout.ts +0 -9
- package/src/useMeta.ts +0 -17
- package/src/useNavigation.ts +0 -10
- package/src/useRoute.ts +0 -9
- package/src/useSearchIndex.ts +0 -17
- package/src/useSidebar.ts +0 -18
- package/src/useStoreActions.ts +0 -2
- package/src/useTableOfContents.ts +0 -8
- package/tsconfig.json +0 -8
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jpmorganchase/mosaic-store",
|
|
3
3
|
"description": "Mosaic - Store for site configuration",
|
|
4
|
-
"version": "0.1.0-beta.
|
|
4
|
+
"version": "0.1.0-beta.73",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "",
|
|
7
7
|
"repository": {
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
"default": "./dist/index.js"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
23
26
|
"scripts": {
|
|
24
27
|
"build": "npm-run-all --parallel build:*",
|
|
25
28
|
"build:bundle": "node ../../scripts/bundle.js",
|
package/.turbo/turbo-build.log
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
# @jpmorganchase/mosaic-store
|
|
2
|
-
|
|
3
|
-
## 0.1.0-beta.71
|
|
4
|
-
|
|
5
|
-
## 0.1.0-beta.70
|
|
6
|
-
|
|
7
|
-
## 0.1.0-beta.69
|
|
8
|
-
|
|
9
|
-
## 0.1.0-beta.68
|
|
10
|
-
|
|
11
|
-
## 0.1.0-beta.67
|
|
12
|
-
|
|
13
|
-
## 0.1.0-beta.66
|
|
14
|
-
|
|
15
|
-
## 0.1.0-beta.65
|
|
16
|
-
|
|
17
|
-
## 0.1.0-beta.64
|
|
18
|
-
|
|
19
|
-
## 0.1.0-beta.63
|
|
20
|
-
|
|
21
|
-
## 0.1.0-beta.62
|
|
22
|
-
|
|
23
|
-
## 0.1.0-beta.61
|
|
24
|
-
|
|
25
|
-
### Patch Changes
|
|
26
|
-
|
|
27
|
-
- cec89401: add `pluginTimeout` (20 secs) to fastify to prevent loading timeout
|
|
28
|
-
|
|
29
|
-
## 0.1.0-beta.60
|
|
30
|
-
|
|
31
|
-
### Patch Changes
|
|
32
|
-
|
|
33
|
-
- a3da0830: New Readme Source
|
|
34
|
-
|
|
35
|
-
This source pulls a single Readme.md from a remote Source repo.
|
|
36
|
-
Typically used for third-party repos which exist already or don't want to
|
|
37
|
-
create a full document hierachy and use `@jpmorganchase/mosaic-source-git-repo`.
|
|
38
|
-
By pulling a single page, we can add metadata to that page via the source's config.
|
|
39
|
-
It's also more performant as we do not need to pull a whole source repo.
|
|
40
|
-
|
|
41
|
-
## 0.1.0-beta.59
|
|
42
|
-
|
|
43
|
-
## 0.1.0-beta.58
|
|
44
|
-
|
|
45
|
-
## 0.1.0-beta.57
|
|
46
|
-
|
|
47
|
-
### Patch Changes
|
|
48
|
-
|
|
49
|
-
- d214d112: Add catch-all default exports for
|
|
50
|
-
|
|
51
|
-
- `@jpmorganchase/mosaic-store`
|
|
52
|
-
- `@jpmorganchase/mosaic-theme`
|
|
53
|
-
- `@jpmorganchase/mosaic-workflows`
|
|
54
|
-
|
|
55
|
-
This resolves an issue when running tests from an external repo which depends on these packages
|
|
56
|
-
|
|
57
|
-
## 0.1.0-beta.56
|
|
58
|
-
|
|
59
|
-
### Patch Changes
|
|
60
|
-
|
|
61
|
-
- 6d30e29f: Add new Storybook source
|
|
62
|
-
|
|
63
|
-
Storybook stories can be extracted from Storybook and embedded into Mosaic pages.
|
|
64
|
-
|
|
65
|
-
The stories are extracted based on a configured filter or matching tags.
|
|
66
|
-
|
|
67
|
-
With a page created for each Story, the author can create a dynamic index of matching stories.
|
|
68
|
-
|
|
69
|
-
eg. An index of patterns which match a specific tag
|
|
70
|
-
|
|
71
|
-
## 0.1.0-beta.55
|
|
72
|
-
|
|
73
|
-
## 0.1.0-beta.54
|
|
74
|
-
|
|
75
|
-
## 0.1.0-beta.53
|
|
76
|
-
|
|
77
|
-
## 0.1.0-beta.52
|
|
78
|
-
|
|
79
|
-
## 0.1.0-beta.51
|
|
80
|
-
|
|
81
|
-
## 0.1.0-beta.50
|
|
82
|
-
|
|
83
|
-
## 0.1.0-beta.49
|
|
84
|
-
|
|
85
|
-
## 0.1.0-beta.48
|
|
86
|
-
|
|
87
|
-
## 0.1.0-beta.47
|
|
88
|
-
|
|
89
|
-
### Patch Changes
|
|
90
|
-
|
|
91
|
-
- 19b4e49a: ### Fix
|
|
92
|
-
|
|
93
|
-
Ensure that help links in the sidebar are visible when they are present in the page `sharedConfig`
|
|
94
|
-
|
|
95
|
-
## 0.1.0-beta.46
|
|
96
|
-
|
|
97
|
-
### Patch Changes
|
|
98
|
-
|
|
99
|
-
- 32e86cfd: ## Fix
|
|
100
|
-
|
|
101
|
-
When a page does not specify a property that is part of the store default props, we use what the default props specify and not what is currently in the store.
|
|
102
|
-
|
|
103
|
-
## 0.1.0-beta.45
|
|
104
|
-
|
|
105
|
-
## 0.1.0-beta.44
|
|
106
|
-
|
|
107
|
-
## 0.1.0-beta.43
|
|
108
|
-
|
|
109
|
-
## 0.1.0-beta.42
|
|
110
|
-
|
|
111
|
-
## 0.1.0-beta.41
|
|
112
|
-
|
|
113
|
-
## 0.1.0-beta.40
|
|
114
|
-
|
|
115
|
-
## 0.1.0-beta.39
|
|
116
|
-
|
|
117
|
-
## 0.1.0-beta.38
|
|
118
|
-
|
|
119
|
-
## 0.1.0-beta.37
|
|
120
|
-
|
|
121
|
-
## 0.1.0-beta.36
|
|
122
|
-
|
|
123
|
-
## 0.1.0-beta.35
|
|
124
|
-
|
|
125
|
-
## 0.1.0-beta.34
|
|
126
|
-
|
|
127
|
-
## 0.1.0-beta.33
|
|
128
|
-
|
|
129
|
-
## 0.1.0-beta.32
|
|
130
|
-
|
|
131
|
-
## 0.1.0-beta.31
|
|
132
|
-
|
|
133
|
-
### Patch Changes
|
|
134
|
-
|
|
135
|
-
- b609fd0: Added support for containerization of the site and cli as well as providing config for kubernetes development (skaffold)
|
|
136
|
-
|
|
137
|
-
## @jpmorganchase/mosaic-cli
|
|
138
|
-
|
|
139
|
-
The cli package has been updated to support containerization.
|
|
140
|
-
|
|
141
|
-
## 0.1.0-beta.30
|
|
142
|
-
|
|
143
|
-
### Patch Changes
|
|
144
|
-
|
|
145
|
-
- 18ef436: The git repo source no longer generates a double slash between the repo host and repo path.
|
|
146
|
-
|
|
147
|
-
## 0.1.0-beta.29
|
|
148
|
-
|
|
149
|
-
### Minor Changes
|
|
150
|
-
|
|
151
|
-
- c78deb4: Flatten Sidebar
|
|
152
|
-
Search Optimisation
|
|
153
|
-
Public Assets Plugin
|
|
154
|
-
TOC Indentation
|
|
155
|
-
|
|
156
|
-
## 0.1.0-beta.28
|
|
157
|
-
|
|
158
|
-
### Patch Changes
|
|
159
|
-
|
|
160
|
-
- 27ac914: 1. Layout improvements. 2. Fix: if a user hits a url that lands on a directory, the index file within that directory is resolved as the content. 3. Fix: improve Table of Contents component highlighting.
|
|
161
|
-
|
|
162
|
-
## 0.1.0-beta.27
|
|
163
|
-
|
|
164
|
-
### Patch Changes
|
|
165
|
-
|
|
166
|
-
- b465413: Improvements to vercel deployments
|
|
167
|
-
|
|
168
|
-
## 0.1.0-beta.26
|
|
169
|
-
|
|
170
|
-
### Minor Changes
|
|
171
|
-
|
|
172
|
-
- 531c87a: ## Mosaic Theme
|
|
173
|
-
|
|
174
|
-
The theme variables are now globally scoped and prefixed with `mosaic`.
|
|
175
|
-
|
|
176
|
-
## BrokenLinksPlugin
|
|
177
|
-
|
|
178
|
-
The `BrokenLinksPlugin` uses a running instance of mosaic to verify that all links in the source pages are alive.
|
|
179
|
-
|
|
180
|
-
If mosaic is running behind a corporate proxy, the `proxyEndpoint` option is required to fetch external URLs.
|
|
181
|
-
|
|
182
|
-
Configuration:
|
|
183
|
-
|
|
184
|
-
```json
|
|
185
|
-
{
|
|
186
|
-
modulePath: '@jpmorganchase/mosaic-plugins/BrokenLinksPlugin',
|
|
187
|
-
priority: -1,
|
|
188
|
-
// Exclude this plugin in builds
|
|
189
|
-
runTimeOnly: true,
|
|
190
|
-
options: {
|
|
191
|
-
baseUrl: process.env.MOSAIC_ACTIVE_MODE_URL || 'http://localhost:8080',
|
|
192
|
-
proxyEndpoint: 'http://some-proxy-url'
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## Next/Prev button
|
|
198
|
-
|
|
199
|
-
The next and prev buttons are visible again on pages that have a layout that uses these buttons.
|
|
200
|
-
|
|
201
|
-
## 0.1.0-beta.25
|
|
202
|
-
|
|
203
|
-
### Minor Changes
|
|
204
|
-
|
|
205
|
-
- 93e9b07: The theme contract provided by the `@jpmorganchase/mosaic-theme` package now uses locally scoped variable names via a Vanilla Extract [Theme Contract](https://vanilla-extract.style/documentation/api/create-theme-contract/). Previously the theme variables were globally scoped resulting in conflicts with other design systems.
|
|
206
|
-
|
|
207
|
-
### Patch Changes
|
|
208
|
-
|
|
209
|
-
- a36219c: - Next/Prev page buttons were not appearing at the bottom of a page sequence
|
|
210
|
-
- Removed redundant snapshot page api
|
|
211
|
-
|
|
212
|
-
## 0.1.0-beta.24
|
|
213
|
-
|
|
214
|
-
### Patch Changes
|
|
215
|
-
|
|
216
|
-
- 049d9af: 1. Pip Salt version 2. Issues 155, make 500 error more specific 3. button and sidebar styles 4. search opt-out
|
|
217
|
-
|
|
218
|
-
## 0.1.0-beta.23
|
|
219
|
-
|
|
220
|
-
### Patch Changes
|
|
221
|
-
|
|
222
|
-
- 513d45f: Sidebar behavior and styling changes.
|
|
223
|
-
Add Client-side search feature.
|
|
224
|
-
Relax node engine requirements.
|
|
225
|
-
Removal of patches from the site package.
|
|
226
|
-
Update site generator templates.
|
|
227
|
-
|
|
228
|
-
## 0.1.0-beta.22
|
|
229
|
-
|
|
230
|
-
### Patch Changes
|
|
231
|
-
|
|
232
|
-
- be89e4f: fix markdown tables and update generator's Salt patches
|
|
233
|
-
|
|
234
|
-
- Salt patches in generator were out of sync with Mosaic repo
|
|
235
|
-
- Markdown now support github flavoured markdown, such as Tables
|
|
236
|
-
|
|
237
|
-
## 0.1.0-beta.21
|
|
238
|
-
|
|
239
|
-
### Patch Changes
|
|
240
|
-
|
|
241
|
-
- f75fd5e: fix sidebar which was generated after `beforeSend` had completed
|
|
242
|
-
|
|
243
|
-
## 0.1.0-beta.20
|
|
244
|
-
|
|
245
|
-
### Patch Changes
|
|
246
|
-
|
|
247
|
-
- 9c7b8ff: pip to beta.20
|
|
248
|
-
|
|
249
|
-
## 0.1.0-beta.19
|
|
250
|
-
|
|
251
|
-
### Patch Changes
|
|
252
|
-
|
|
253
|
-
- ad06d4c: ensure spinner is removed after page has loaded
|
|
254
|
-
|
|
255
|
-
## 0.1.0-beta.18
|
|
256
|
-
|
|
257
|
-
### Patch Changes
|
|
258
|
-
|
|
259
|
-
- 066efed: Update docs with quick-start guide
|
|
260
|
-
|
|
261
|
-
Sample docs now include a 'quick-start' guide to onboarding to AWS.
|
|
262
|
-
|
|
263
|
-
Also
|
|
264
|
-
|
|
265
|
-
- generator default directory is the current directory
|
|
266
|
-
- after generating a site, it will run `yarn` in the created directory. This simplifies the generator call to just `yarn mosaic-create-site`
|
|
267
|
-
|
|
268
|
-
## 0.1.0-beta.17
|
|
269
|
-
|
|
270
|
-
### Patch Changes
|
|
271
|
-
|
|
272
|
-
- b2f6d52: Fix `pre` block code block rendering
|
|
273
|
-
|
|
274
|
-
## 0.1.0-beta.16
|
|
275
|
-
|
|
276
|
-
### Patch Changes
|
|
277
|
-
|
|
278
|
-
- 3a5c88a: add missing `@types/node` dependency for generator
|
|
279
|
-
|
|
280
|
-
## 0.1.0-beta.15
|
|
281
|
-
|
|
282
|
-
### Patch Changes
|
|
283
|
-
|
|
284
|
-
- aaaf255: initial release of HTTP Source package.
|
|
285
|
-
|
|
286
|
-
An HTTP source accepts a collection of endpoints and a path to a transformer module.
|
|
287
|
-
The response from fetching is transformed and merged together into 1 single collection of pages.
|
|
288
|
-
Should 1 of the endpoints request fail then it will have no impact on the other requests.
|
|
289
|
-
|
|
290
|
-
## 0.1.0-beta.14
|
|
291
|
-
|
|
292
|
-
### Patch Changes
|
|
293
|
-
|
|
294
|
-
- dde3b5a: Feature release
|
|
295
|
-
|
|
296
|
-
- Enhanced generators now have defaults.
|
|
297
|
-
With one command (`yarn mosaic-create-site create`) it will generate a fully working site with both local and remote sources
|
|
298
|
-
- Fix an issue where we could not clone from the master branch of git repos
|
|
299
|
-
- Migrate to Next 13 image
|
|
300
|
-
|
|
301
|
-
## 0.1.0-beta.13
|
|
302
|
-
|
|
303
|
-
### Patch Changes
|
|
304
|
-
|
|
305
|
-
- d4da1df: incremental improvements
|
|
306
|
-
|
|
307
|
-
- move colormode into store
|
|
308
|
-
- ensure breadcrumbs and sidebar data is only added to frontmatter for pages which use a layout that has breadcrumbs or a sidebar
|
|
309
|
-
- improve changeset so it can work standalone without a monorepo
|
|
310
|
-
- resolev json5 vulnerability
|
|
311
|
-
|
|
312
|
-
## 0.1.0-beta.12
|
|
313
|
-
|
|
314
|
-
### Patch Changes
|
|
315
|
-
|
|
316
|
-
- 9ec358b: Upgrade React to version 18 and NextJs to version 13
|
|
317
|
-
- 3eb35bf: initial work to enable generators to run outside of the repo
|
|
318
|
-
|
|
319
|
-
## 0.1.0-beta.11
|
|
320
|
-
|
|
321
|
-
### Patch Changes
|
|
322
|
-
|
|
323
|
-
- fc5d7b5: Generators can now interactively add sources
|
|
324
|
-
|
|
325
|
-
Previously we were making local edits to our own site or examples to implement new features.
|
|
326
|
-
What we wanted was the ability to create a local rig, A local rig can be used for development purposes,
|
|
327
|
-
without touching our site code.
|
|
328
|
-
|
|
329
|
-
We have added Mosaic repo commands, to enable us to generates local rigs (`yarn gen:rig`) and deploy our own
|
|
330
|
-
tech docs via snapshot (`yarn gen`)
|
|
331
|
-
|
|
332
|
-
To generate a site+snapshot from sources defined in `mosaic-generators.js`, run `yarn gen`
|
|
333
|
-
To generate a dynamic site from sources defined in `mosaic-generators.js`, run `yarn gen:site`
|
|
334
|
-
To generate a rig `yarn gen:rig`
|
|
335
|
-
|
|
336
|
-
Equally these changes can be used to generate sites in other repos via the `mosaic-create-site` command.
|
|
337
|
-
|
|
338
|
-
`yarn mosaic-create-site init` will create a `mosaic.generators.js`.
|
|
339
|
-
|
|
340
|
-
Configure the `mosaic.generators.js` with your generator and sources, then run.
|
|
341
|
-
|
|
342
|
-
`yarn mosaic-create-site create -i -o path/to/my-site`
|
|
343
|
-
|
|
344
|
-
When this command is run, it will present an interactive menu of generators and output the site to `path/to/my-site`.
|
|
345
|
-
|
|
346
|
-
## 0.1.0-beta.10
|
|
347
|
-
|
|
348
|
-
### Patch Changes
|
|
349
|
-
|
|
350
|
-
- af2f579: Converted repo to ESM and Salt DS nomenclature
|
|
351
|
-
|
|
352
|
-
- Switch UITK nomenclature to Salt DS
|
|
353
|
-
Upgraded to first stable version of Salt DS version 1.0.0
|
|
354
|
-
- CommonJS code switched to ESM and upgraded to Node 16
|
|
355
|
-
- Removed example-nextjs-ssr package as un-required, can be replaced by documentation
|
|
356
|
-
- Sites can now generate immutable snapshots of content that loads content like a SGS (statically generated site)
|
|
357
|
-
Snapshots can be used as a serverless solution when deployed to Vercel.
|
|
358
|
-
- New Middleware package `@jpmorganchase/mosaic-site-middleware`
|
|
359
|
-
|
|
360
|
-
## 0.1.0-beta.9
|
|
361
|
-
|
|
362
|
-
### Minor Changes
|
|
363
|
-
|
|
364
|
-
- c3fee89: initial components package
|
|
365
|
-
|
|
366
|
-
- added JSDOM testing
|
|
367
|
-
|
|
368
|
-
## 0.1.0-beta.8
|
|
369
|
-
|
|
370
|
-
### Minor Changes
|
|
371
|
-
|
|
372
|
-
- 2dca0b1: initial release of Mosaic store package
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { renderHook } from '@testing-library/react';
|
|
2
|
-
|
|
3
|
-
import { createWrapper } from './test-utils/utils';
|
|
4
|
-
import { initializeStore, SiteState, useCreateStore, useStore } from '../store';
|
|
5
|
-
|
|
6
|
-
function getStateToVerify(currentState: SiteState) {
|
|
7
|
-
let { actions, ...stateToVerify } = currentState;
|
|
8
|
-
return stateToVerify;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
describe('GIVEN the store initializer', () => {
|
|
12
|
-
describe('WHEN no other state is provided', () => {
|
|
13
|
-
test('THEN the store api provides the initial default state', () => {
|
|
14
|
-
const storeApi = initializeStore();
|
|
15
|
-
expect(getStateToVerify(storeApi.getState())).toEqual({
|
|
16
|
-
breadcrumbs: [],
|
|
17
|
-
navigation: {},
|
|
18
|
-
sidebarData: [],
|
|
19
|
-
tableOfContents: [],
|
|
20
|
-
searchIndex: [],
|
|
21
|
-
searchConfig: {},
|
|
22
|
-
sharedConfig: {},
|
|
23
|
-
description: undefined,
|
|
24
|
-
layout: undefined,
|
|
25
|
-
route: undefined,
|
|
26
|
-
title: undefined,
|
|
27
|
-
colorMode: 'light'
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('WHEN additional state is preloaded', () => {
|
|
33
|
-
test('THEN the store api provides the initial default state plus the preloaded state', () => {
|
|
34
|
-
const state = {
|
|
35
|
-
description: 'description',
|
|
36
|
-
layout: 'layout',
|
|
37
|
-
route: 'route',
|
|
38
|
-
title: 'title'
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const storeApi = initializeStore(state);
|
|
42
|
-
expect(getStateToVerify(storeApi.getState())).toEqual({
|
|
43
|
-
breadcrumbs: [],
|
|
44
|
-
navigation: {},
|
|
45
|
-
searchIndex: [],
|
|
46
|
-
searchConfig: {},
|
|
47
|
-
sidebarData: [],
|
|
48
|
-
tableOfContents: [],
|
|
49
|
-
sharedConfig: {},
|
|
50
|
-
colorMode: 'light',
|
|
51
|
-
|
|
52
|
-
...state
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('GIVEN the `useCreateStore` hook', () => {
|
|
59
|
-
describe('WHEN executed on the client', () => {
|
|
60
|
-
test('THEN the store content is replaced', () => {
|
|
61
|
-
const state = { layout: 'layout', description: 'des' };
|
|
62
|
-
const { result, rerender } = renderHook(() => useCreateStore(state));
|
|
63
|
-
let currentState = result.current().getState();
|
|
64
|
-
|
|
65
|
-
expect(getStateToVerify(currentState)).toEqual({
|
|
66
|
-
breadcrumbs: [],
|
|
67
|
-
navigation: {},
|
|
68
|
-
searchIndex: [],
|
|
69
|
-
searchConfig: {},
|
|
70
|
-
sidebarData: [],
|
|
71
|
-
tableOfContents: [],
|
|
72
|
-
sharedConfig: {},
|
|
73
|
-
colorMode: 'light',
|
|
74
|
-
...state,
|
|
75
|
-
route: undefined,
|
|
76
|
-
title: undefined
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// update the state and rerender
|
|
80
|
-
state.layout = 'new';
|
|
81
|
-
state.description = 'description';
|
|
82
|
-
rerender();
|
|
83
|
-
|
|
84
|
-
currentState = result.current().getState();
|
|
85
|
-
expect(getStateToVerify(currentState)).toEqual({
|
|
86
|
-
breadcrumbs: [],
|
|
87
|
-
navigation: {},
|
|
88
|
-
sidebarData: [],
|
|
89
|
-
searchIndex: [],
|
|
90
|
-
searchConfig: {},
|
|
91
|
-
tableOfContents: [],
|
|
92
|
-
sharedConfig: {},
|
|
93
|
-
colorMode: 'light',
|
|
94
|
-
description: 'description',
|
|
95
|
-
layout: 'new',
|
|
96
|
-
route: undefined,
|
|
97
|
-
title: undefined
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
test('THEN defaults applied when page props do not include default state', () => {
|
|
101
|
-
const state: { layout?: string; description: string } = {
|
|
102
|
-
layout: 'layout',
|
|
103
|
-
description: 'des'
|
|
104
|
-
};
|
|
105
|
-
const { result, rerender } = renderHook(() => useCreateStore(state));
|
|
106
|
-
let currentState = result.current().getState();
|
|
107
|
-
|
|
108
|
-
expect(getStateToVerify(currentState)).toEqual({
|
|
109
|
-
breadcrumbs: [],
|
|
110
|
-
navigation: {},
|
|
111
|
-
searchIndex: [],
|
|
112
|
-
searchConfig: {},
|
|
113
|
-
sidebarData: [],
|
|
114
|
-
tableOfContents: [],
|
|
115
|
-
sharedConfig: {},
|
|
116
|
-
colorMode: 'light',
|
|
117
|
-
...state,
|
|
118
|
-
route: undefined,
|
|
119
|
-
title: undefined
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* we use delete here because the idea is that the page does not indicate a layout IN ANY WAY
|
|
124
|
-
* This is different from the page saying my layout is undefined
|
|
125
|
-
*/
|
|
126
|
-
delete state.layout;
|
|
127
|
-
state.description = 'description';
|
|
128
|
-
rerender();
|
|
129
|
-
|
|
130
|
-
currentState = result.current().getState();
|
|
131
|
-
expect(getStateToVerify(currentState)).toEqual({
|
|
132
|
-
breadcrumbs: [],
|
|
133
|
-
navigation: {},
|
|
134
|
-
sidebarData: [],
|
|
135
|
-
searchIndex: [],
|
|
136
|
-
searchConfig: {},
|
|
137
|
-
tableOfContents: [],
|
|
138
|
-
sharedConfig: {},
|
|
139
|
-
colorMode: 'light',
|
|
140
|
-
description: 'description',
|
|
141
|
-
layout: undefined,
|
|
142
|
-
route: undefined,
|
|
143
|
-
title: undefined
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe('WHEN executed on the server', () => {
|
|
149
|
-
test('THEN the store is always reinitialized', () => {
|
|
150
|
-
const state = { layout: 'layout', description: 'des' };
|
|
151
|
-
const { result, rerender } = renderHook(() => useCreateStore(state, true));
|
|
152
|
-
let currentState = result.current().getState();
|
|
153
|
-
|
|
154
|
-
expect(getStateToVerify(currentState)).toEqual({
|
|
155
|
-
breadcrumbs: [],
|
|
156
|
-
navigation: {},
|
|
157
|
-
searchIndex: [],
|
|
158
|
-
searchConfig: {},
|
|
159
|
-
sidebarData: [],
|
|
160
|
-
tableOfContents: [],
|
|
161
|
-
sharedConfig: {},
|
|
162
|
-
colorMode: 'light',
|
|
163
|
-
...state,
|
|
164
|
-
route: undefined,
|
|
165
|
-
title: undefined
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// update the state and rerender
|
|
169
|
-
state.layout = 'new';
|
|
170
|
-
state.description = 'description';
|
|
171
|
-
rerender();
|
|
172
|
-
|
|
173
|
-
currentState = result.current().getState();
|
|
174
|
-
|
|
175
|
-
expect(getStateToVerify(currentState)).toEqual({
|
|
176
|
-
breadcrumbs: [],
|
|
177
|
-
navigation: {},
|
|
178
|
-
sidebarData: [],
|
|
179
|
-
searchIndex: [],
|
|
180
|
-
searchConfig: {},
|
|
181
|
-
tableOfContents: [],
|
|
182
|
-
sharedConfig: {},
|
|
183
|
-
colorMode: 'light',
|
|
184
|
-
description: 'description',
|
|
185
|
-
layout: 'new',
|
|
186
|
-
route: undefined,
|
|
187
|
-
title: undefined
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
describe('GIVEN the `useStore` hook', () => {
|
|
194
|
-
describe('WHEN a selector is provided', () => {
|
|
195
|
-
test('THEN the hook applies the selector and returns the selected state', () => {
|
|
196
|
-
const { result } = renderHook(() => useStore(state => state.title), {
|
|
197
|
-
wrapper: createWrapper({ title: 'title' })
|
|
198
|
-
});
|
|
199
|
-
expect(result.current).toEqual('title');
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe('WHEN rendered outside of the StoreContext', () => {
|
|
204
|
-
test('THEN the hook throws an error', () => {
|
|
205
|
-
expect(() => renderHook(() => useStore(state => state.title))).toThrowError(
|
|
206
|
-
'Missing StoreProvider in the tree'
|
|
207
|
-
);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
|
|
4
|
-
import { useCreateStore, StoreProvider } from '../../store';
|
|
5
|
-
import type { SiteState } from '../../store';
|
|
6
|
-
|
|
7
|
-
export function renderWithStore(ui: React.ReactElement) {
|
|
8
|
-
const { rerender, ...result } = render(<Store>{ui}</Store>);
|
|
9
|
-
return {
|
|
10
|
-
...result,
|
|
11
|
-
rerender: (rerenderUi: React.ReactElement) => rerender(<Store>{rerenderUi}</Store>)
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function createWrapper(state?: Partial<SiteState>) {
|
|
16
|
-
return ({ children }: { children?: React.ReactNode }) => <Store state={state}>{children}</Store>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @param state: initial state for the site store
|
|
22
|
-
*/
|
|
23
|
-
const Store: React.FC<{ state?: Partial<SiteState> }> = ({ children, state = {} }) => {
|
|
24
|
-
const createStore = useCreateStore(state);
|
|
25
|
-
return <StoreProvider value={createStore()}>{children}</StoreProvider>;
|
|
26
|
-
};
|