Skip to content

Commit

Permalink
fix(ssr): allow getWidgetState to be empty for createURL (algolia/vue…
Browse files Browse the repository at this point in the history
…-instantsearch#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
  • Loading branch information
Haroenv authored Jun 18, 2020
1 parent 4a7b570 commit 3807c7f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 23 deletions.
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('#');
});
});
});
});
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 3807c7f

Please sign in to comment.