Skip to content

Commit

Permalink
fix(instantsearch): remove addWidget, removeWidget methods (#6498)
Browse files Browse the repository at this point in the history
* fix(instantsearch): remove addWidget, removeWidget methdos

BREAKING CHANGE: use removeWidgets, addWidgets instead of removeWidget, addWidget

* !fixup
  • Loading branch information
Haroenv authored Dec 31, 2024
1 parent 301fc10 commit ed50154
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 114 deletions.
94 changes: 2 additions & 92 deletions packages/instantsearch-core/src/__tests__/instantsearch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -673,26 +673,7 @@ See https://www.algolia.com/doc/api-reference/widgets/configure/js/`);
});
});

describe('addWidget(s)', () => {
it('forwards the call of `addWidget` to the main index', () => {
const warn = jest.spyOn(global.console, 'warn');
warn.mockImplementation(() => {});

const searchClient = createSearchClient();
const search = new InstantSearch({
indexName: 'indexName',
searchClient,
});

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

expect(() => search.addWidget(createWidget())).toWarnDev(
'[InstantSearch]: addWidget will still be supported in 4.x releases, but not further. It is replaced by `addWidgets([widget])`'
);

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

describe('addWidgets', () => {
it('forwards the call of `addWidgets` to the main index', () => {
const searchClient = createSearchClient();
const search = new InstantSearch({
Expand All @@ -707,27 +688,6 @@ describe('addWidget(s)', () => {
expect(search.mainIndex.getWidgets()).toHaveLength(1);
});

it('returns the search instance when calling `addWidget`', () => {
const warn = jest.spyOn(global.console, 'warn');
warn.mockImplementation(() => {});

const searchClient = createSearchClient();
const search = new InstantSearch({
indexName: 'indexName',
searchClient,
});

let result: InstantSearch | null = null;

expect(() => {
result = search.addWidget(createWidget());
}).toWarnDev(
'[InstantSearch]: addWidget will still be supported in 4.x releases, but not further. It is replaced by `addWidgets([widget])`'
);

expect(result).toBe(search);
});

it('returns the search instance when calling `addWidgets`', () => {
const searchClient = createSearchClient();
const search = new InstantSearch({
Expand Down Expand Up @@ -764,30 +724,7 @@ describe('addWidget(s)', () => {
});
});

describe('removeWidget(s)', () => {
it('forwards the call to `removeWidget` to the main index', () => {
const warn = jest.spyOn(global.console, 'warn');
warn.mockImplementation(() => {});

const searchClient = createSearchClient();
const search = new InstantSearch({
indexName: 'indexName',
searchClient,
});

const widget = createWidget();

search.addWidgets([widget]);

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

expect(() => search.removeWidget(widget)).toWarnDev(
'[InstantSearch]: removeWidget will still be supported in 4.x releases, but not further. It is replaced by `removeWidgets([widget])`'
);

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

describe('removeWidgets', () => {
it('forwards the call to `removeWidgets` to the main index', () => {
const searchClient = createSearchClient();
const search = new InstantSearch({
Expand All @@ -806,33 +743,6 @@ describe('removeWidget(s)', () => {
expect(search.mainIndex.getWidgets()).toHaveLength(0);
});

it('returns the search instance when calling `removeWidget`', () => {
const warn = jest.spyOn(global.console, 'warn');
warn.mockImplementation(() => {});

const searchClient = createSearchClient();
const search = new InstantSearch({
indexName: 'indexName',
searchClient,
});

const widget = createWidget();

expect(() => search.addWidget(widget)).toWarnDev(
'[InstantSearch]: addWidget will still be supported in 4.x releases, but not further. It is replaced by `addWidgets([widget])`'
);

let result: InstantSearch | null = null;

expect(() => {
result = search.removeWidget(widget);
}).toWarnDev(
'[InstantSearch]: removeWidget will still be supported in 4.x releases, but not further. It is replaced by `removeWidgets([widget])`'
);

expect(result).toBe(search);
});

it('returns the search instance when calling `removeWidgets`', () => {
const searchClient = createSearchClient();
const search = new InstantSearch({
Expand Down
18 changes: 0 additions & 18 deletions packages/instantsearch-core/src/instantsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,6 @@ See ${createDocumentationLink({
return this;
}

addWidget(widget: Widget | IndexWidget) {
warning(
false,
'addWidget will still be supported in 4.x releases, but not further. It is replaced by `addWidgets([widget])`'
);

return this.addWidgets([widget]);
}

addWidgets(widgets: Array<Widget | IndexWidget>) {
if (!Array.isArray(widgets)) {
throw new Error(
Expand Down Expand Up @@ -284,15 +275,6 @@ See ${createDocumentationLink({
return this;
}

removeWidget(widget: Widget | IndexWidget) {
warning(
false,
'removeWidget will still be supported in 4.x releases, but not further. It is replaced by `removeWidgets([widget])`'
);

return this.removeWidgets([widget]);
}

removeWidgets(widgets: Array<Widget | IndexWidget>) {
if (!Array.isArray(widgets)) {
throw new Error(
Expand Down
2 changes: 0 additions & 2 deletions packages/instantsearch-core/test/createInstantSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ export const createInstantSearch = (
// See https://github.com/algolia/instantsearch/blob/f3213b2f118d75acac31a1f6cf4640241c438e9d/src/lib/utils/defer.ts#L13-L28
onInternalStateChange: jest.fn() as any,
createURL: jest.fn(() => '#'),
addWidget: jest.fn(),
addWidgets: jest.fn(),
removeWidget: jest.fn(),
removeWidgets: jest.fn(),
use: jest.fn(),
unuse: jest.fn(),
Expand Down
2 changes: 0 additions & 2 deletions packages/instantsearch.js/test/createInstantSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export const createInstantSearch = (
// See https://github.com/algolia/instantsearch/blob/f3213b2f118d75acac31a1f6cf4640241c438e9d/src/lib/utils/defer.ts#L13-L28
onInternalStateChange: jest.fn() as any,
createURL: jest.fn(() => '#'),
addWidget: jest.fn(),
addWidgets: jest.fn(),
removeWidget: jest.fn(),
removeWidgets: jest.fn(),
use: jest.fn(),
unuse: jest.fn(),
Expand Down

0 comments on commit ed50154

Please sign in to comment.