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

fix(ssr): allow getWidgetState to be empty for createURL #805

Merged
merged 2 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 65 additions & 22 deletions src/util/__tests__/createServerRootMixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,35 +433,78 @@ Object {
);
});

it('has a fake createURL', () => {
const app = new Vue({
mixins: [
createServerRootMixin({
searchClient: createFakeClient(),
indexName: 'lol',
}),
],
});
describe('createURL', () => {
it('returns # if instantsearch has no routing', () => {
const app = new Vue({
mixins: [
createServerRootMixin({
searchClient: createFakeClient(),
indexName: 'lol',
}),
],
});

const widget = {
init: jest.fn(),
render: jest.fn(),
};
const widget = {
init: jest.fn(),
render: jest.fn(),
};

const instantSearchInstance = app.$data.instantsearch;
const instantSearchInstance = app.$data.instantsearch;

instantSearchInstance.hydrate({
lol: createSerializedState(),
instantSearchInstance.hydrate({
lol: createSerializedState(),
});

instantSearchInstance.__forceRender(
widget,
instantSearchInstance.mainIndex
);

const renderArgs = widget.render.mock.calls[0][0];

expect(renderArgs.createURL()).toBe('#');
});

instantSearchInstance.__forceRender(
widget,
instantSearchInstance.mainIndex
);
it('allows for widgets without getWidgetState', () => {
const app = new Vue({
mixins: [
createServerRootMixin({
searchClient: createFakeClient(),
indexName: 'lol',
}),
],
});

const widget = {
init: jest.fn(),
render: jest.fn(),
getWidgetState(uiState) {
return uiState;
},
};

const renderArgs = widget.render.mock.calls[0][0];
const widgetWithoutGetWidgetState = {
init: jest.fn(),
render: jest.fn(),
};

const instantSearchInstance = app.$data.instantsearch;

instantSearchInstance.hydrate({
lol: createSerializedState(),
});

expect(renderArgs.createURL()).toBe('#');
instantSearchInstance.addWidgets([widget, widgetWithoutGetWidgetState]);

instantSearchInstance.__forceRender(
widget,
instantSearchInstance.mainIndex
);

const renderArgs = widget.render.mock.calls[0][0];

expect(renderArgs.createURL()).toBe('#');
});
});
});
});
2 changes: 1 addition & 1 deletion src/util/createServerRootMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function augmentInstantSearch(instantSearchOptions, searchClient, indexName) {
.getWidgets()
.filter(w => w.$$type !== 'ais.index')
.reduce((uiState, w) => {
if (!widget.getWidgetState) {
if (!w.getWidgetState) {
return uiState;
}

Expand Down