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

Commit 0528b55

Browse files
authored
fix(ssr): allow getWidgetState to be empty for createURL (#805)
* fix(ssr): allow getWidgetState to be empty for createURL This must have been caused by a wrong copy-paste * test(ssr): add case for createURL
1 parent 6ee1404 commit 0528b55

File tree

2 files changed

+66
-23
lines changed

2 files changed

+66
-23
lines changed

src/util/__tests__/createServerRootMixin.test.js

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -433,35 +433,78 @@ Object {
433433
);
434434
});
435435

436-
it('has a fake createURL', () => {
437-
const app = new Vue({
438-
mixins: [
439-
createServerRootMixin({
440-
searchClient: createFakeClient(),
441-
indexName: 'lol',
442-
}),
443-
],
444-
});
436+
describe('createURL', () => {
437+
it('returns # if instantsearch has no routing', () => {
438+
const app = new Vue({
439+
mixins: [
440+
createServerRootMixin({
441+
searchClient: createFakeClient(),
442+
indexName: 'lol',
443+
}),
444+
],
445+
});
445446

446-
const widget = {
447-
init: jest.fn(),
448-
render: jest.fn(),
449-
};
447+
const widget = {
448+
init: jest.fn(),
449+
render: jest.fn(),
450+
};
450451

451-
const instantSearchInstance = app.$data.instantsearch;
452+
const instantSearchInstance = app.$data.instantsearch;
452453

453-
instantSearchInstance.hydrate({
454-
lol: createSerializedState(),
454+
instantSearchInstance.hydrate({
455+
lol: createSerializedState(),
456+
});
457+
458+
instantSearchInstance.__forceRender(
459+
widget,
460+
instantSearchInstance.mainIndex
461+
);
462+
463+
const renderArgs = widget.render.mock.calls[0][0];
464+
465+
expect(renderArgs.createURL()).toBe('#');
455466
});
456467

457-
instantSearchInstance.__forceRender(
458-
widget,
459-
instantSearchInstance.mainIndex
460-
);
468+
it('allows for widgets without getWidgetState', () => {
469+
const app = new Vue({
470+
mixins: [
471+
createServerRootMixin({
472+
searchClient: createFakeClient(),
473+
indexName: 'lol',
474+
}),
475+
],
476+
});
477+
478+
const widget = {
479+
init: jest.fn(),
480+
render: jest.fn(),
481+
getWidgetState(uiState) {
482+
return uiState;
483+
},
484+
};
461485

462-
const renderArgs = widget.render.mock.calls[0][0];
486+
const widgetWithoutGetWidgetState = {
487+
init: jest.fn(),
488+
render: jest.fn(),
489+
};
490+
491+
const instantSearchInstance = app.$data.instantsearch;
492+
493+
instantSearchInstance.hydrate({
494+
lol: createSerializedState(),
495+
});
463496

464-
expect(renderArgs.createURL()).toBe('#');
497+
instantSearchInstance.addWidgets([widget, widgetWithoutGetWidgetState]);
498+
499+
instantSearchInstance.__forceRender(
500+
widget,
501+
instantSearchInstance.mainIndex
502+
);
503+
504+
const renderArgs = widget.render.mock.calls[0][0];
505+
506+
expect(renderArgs.createURL()).toBe('#');
507+
});
465508
});
466509
});
467510
});

src/util/createServerRootMixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function augmentInstantSearch(instantSearchOptions, searchClient, indexName) {
167167
.getWidgets()
168168
.filter(w => w.$$type !== 'ais.index')
169169
.reduce((uiState, w) => {
170-
if (!widget.getWidgetState) {
170+
if (!w.getWidgetState) {
171171
return uiState;
172172
}
173173

0 commit comments

Comments
 (0)