Skip to content

Commit

Permalink
fix(instantsearch): return instance in widgets methods (#4143)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour authored Sep 26, 2019
1 parent 443cb06 commit 6451dce
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib/InstantSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend
false,
'addWidget will still be supported in 4.x releases, but not further. It is replaced by `addWidgets([widget])`'
);
this.addWidgets([widget]);

return this.addWidgets([widget]);
}

/**
Expand Down Expand Up @@ -289,6 +290,8 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend
}

this.mainIndex.addWidgets(widgets);

return this;
}

/**
Expand All @@ -303,7 +306,8 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend
false,
'removeWidget will still be supported in 4.x releases, but not further. It is replaced by `removeWidgets([widget])`'
);
this.removeWidgets([widget]);

return this.removeWidgets([widget]);
}

/**
Expand All @@ -328,6 +332,8 @@ See: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend
}

this.mainIndex.removeWidgets(widgets);

return this;
}

/**
Expand Down
46 changes: 46 additions & 0 deletions src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,26 @@ describe('addWidget(s)', () => {

expect(search.mainIndex.getWidgets()).toHaveLength(1);
});

it('returns the search instance when calling `addWidget`', () => {
const searchClient = createSearchClient();
const search = new InstantSearch({
indexName: 'indexName',
searchClient,
});

expect(search.addWidget(createWidget())).toBe(search);
});

it('returns the search instance when calling `addWidgets`', () => {
const searchClient = createSearchClient();
const search = new InstantSearch({
indexName: 'indexName',
searchClient,
});

expect(search.addWidgets([createWidget()])).toBe(search);
});
});

describe('removeWidget(s)', () => {
Expand Down Expand Up @@ -311,6 +331,32 @@ describe('removeWidget(s)', () => {

expect(search.mainIndex.getWidgets()).toHaveLength(0);
});

it('returns the search instance when calling `removeWidget`', () => {
const searchClient = createSearchClient();
const search = new InstantSearch({
indexName: 'indexName',
searchClient,
});

const widget = createWidget();
search.addWidget(widget);

expect(search.removeWidget(widget)).toBe(search);
});

it('returns the search instance when calling `removeWidgets`', () => {
const searchClient = createSearchClient();
const search = new InstantSearch({
indexName: 'indexName',
searchClient,
});

const widget = createWidget();
search.addWidgets([widget]);

expect(search.removeWidgets([widget])).toBe(search);
});
});

describe('start', () => {
Expand Down

0 comments on commit 6451dce

Please sign in to comment.