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 and Haroenv committed Oct 23, 2019
1 parent b641e23 commit 77ffb93
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 @@ -275,7 +275,8 @@ See ${createDocumentationLink({
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 @@ -307,6 +308,8 @@ See ${createDocumentationLink({
}

this.mainIndex.addWidgets(widgets);

return this;
}

/**
Expand All @@ -321,7 +324,8 @@ See ${createDocumentationLink({
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 @@ -346,6 +350,8 @@ See ${createDocumentationLink({
}

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 @@ -309,6 +309,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 @@ -349,6 +369,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 77ffb93

Please sign in to comment.