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

Commit

Permalink
fix(ssr): allow getWidgetState to be empty for createURL (#805)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Haroenv authored Jun 18, 2020
1 parent 6ee1404 commit 0528b55
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 23 deletions.
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

0 comments on commit 0528b55

Please sign in to comment.