Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(server side rendering): return a value from mock currentRefinemen…
Browse files Browse the repository at this point in the history
…t/metadata (#3078)

* WIP: return a value from mock currentRefinement

This is required, as transitionState gets called with the return of this; while the value isn't used anywhere really, it will cause an error if configure + currentRefinements is used in SSR context.

(longer description to come once test is written)

* write a test

* remove only
  • Loading branch information
Haroenv committed Jul 30, 2021
1 parent 225b12f commit 09f802b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ describe('createInstantSearchManager', () => {
});
});

describe('results hydratation', () => {
describe('results hydration', () => {
it('initializes the manager with a single index hydrated results', () => {
const ism = createInstantSearchManager({
indexName: 'index',
Expand Down Expand Up @@ -387,6 +387,55 @@ describe('createInstantSearchManager', () => {
});
});

describe('metadata hydration', () => {
test('replaces value with a function returning empty search state', () => {
const ism = createInstantSearchManager({
indexName: 'index',
searchClient: createSearchClient(),
resultsState: {
metadata: [
{ stuff: 1, items: [{ stuff: 2, items: [{ stuff: 3 }] }] },
],
rawResults: [
{
index: 'indexName',
query: 'query',
},
],
state: {
index: 'indexName',
query: 'query',
},
},
});

const hydratedMetadata = ism.store.getState().metadata;

expect(hydratedMetadata).toEqual([
{
value: expect.any(Function),
stuff: 1,
items: [
{
value: expect.any(Function),
stuff: 2,
items: [
{
value: expect.any(Function),
stuff: 3,
},
],
},
],
},
]);

expect(hydratedMetadata[0].value()).toEqual({});
expect(hydratedMetadata[0].items[0].value()).toEqual({});
expect(hydratedMetadata[0].items[0].items[0].value()).toEqual({});
});
});

describe('widget manager', () => {
it('triggers a search when a widget is added', async () => {
const searchClient = createSearchClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,17 +618,17 @@ function hydrateMetadata(resultsState) {

// add a value noop, which gets replaced once the widgets are mounted
return resultsState.metadata.map(datum => ({
value() {},
value: () => ({}),
...datum,
items:
datum.items &&
datum.items.map(item => ({
value() {},
value: () => ({}),
...item,
items:
item.items &&
item.items.map(nestedItem => ({
value() {},
value: () => ({}),
...nestedItem,
})),
})),
Expand Down

0 comments on commit 09f802b

Please sign in to comment.