diff --git a/packages/react-instantsearch-hooks/src/components/__tests__/InstantSearch.test.tsx b/packages/react-instantsearch-hooks/src/components/__tests__/InstantSearch.test.tsx
index 25961be81a..5c3acb3680 100644
--- a/packages/react-instantsearch-hooks/src/components/__tests__/InstantSearch.test.tsx
+++ b/packages/react-instantsearch-hooks/src/components/__tests__/InstantSearch.test.tsx
@@ -1,5 +1,5 @@
import { act, render, waitFor } from '@testing-library/react';
-import React, { version as ReactVersion } from 'react';
+import React, { Suspense, version as ReactVersion } from 'react';
import { createSearchClient } from '../../../../../test/mock';
import { wait } from '../../../../../test/utils';
@@ -162,7 +162,7 @@ describe('InstantSearch', () => {
expect(searchClient.search).toHaveBeenCalledTimes(1);
});
- test('renders components and their lifecycles in StrictMode', async () => {
+ test('renders components in Strict Mode', async () => {
const searchClient = createSearchClient({});
act(() => {
@@ -180,6 +180,95 @@ describe('InstantSearch', () => {
await waitFor(() => {
expect(searchClient.search).toHaveBeenCalledTimes(1);
+ expect(searchClient.search).toHaveBeenCalledWith([
+ {
+ indexName: 'indexName',
+ params: { facets: [], query: '', tagFilters: '' },
+ },
+ {
+ indexName: 'subIndexName',
+ params: {
+ facets: ['brand'],
+ maxValuesPerFacet: 10,
+ query: '',
+ tagFilters: '',
+ },
+ },
+ ]);
+ });
+ });
+
+ test('renders components in Strict Mode with a Suspense boundary', async () => {
+ const searchClient = createSearchClient({});
+
+ act(() => {
+ render(
+
+
+
+
+
+
+
+
+
+
+ );
+ });
+
+ await waitFor(() => {
+ expect(searchClient.search).toHaveBeenCalledTimes(1);
+ expect(searchClient.search).toHaveBeenCalledWith([
+ {
+ indexName: 'indexName',
+ params: { facets: [], query: '', tagFilters: '' },
+ },
+ {
+ indexName: 'subIndexName',
+ params: {
+ facets: ['brand'],
+ maxValuesPerFacet: 10,
+ query: '',
+ tagFilters: '',
+ },
+ },
+ ]);
+ });
+ });
+
+ test('renders components with a Suspense boundary', async () => {
+ const searchClient = createSearchClient({});
+
+ act(() => {
+ render(
+
+
+
+
+
+
+
+
+ );
+ });
+
+ await waitFor(() => {
+ expect(searchClient.search).toHaveBeenCalledTimes(1);
+ expect(searchClient.search).toHaveBeenCalledWith([
+ {
+ indexName: 'indexName',
+ params: { facets: [], query: '', tagFilters: '' },
+ },
+ {
+ indexName: 'subIndexName',
+ params: {
+ facets: ['brand'],
+ maxValuesPerFacet: 10,
+ query: '',
+ tagFilters: '',
+ },
+ },
+ ]);
});
});
});
diff --git a/packages/react-instantsearch-hooks/src/components/__tests__/InstantSearchSSRProvider.test.tsx b/packages/react-instantsearch-hooks/src/components/__tests__/InstantSearchSSRProvider.test.tsx
index ed1ae46341..115099ecb4 100644
--- a/packages/react-instantsearch-hooks/src/components/__tests__/InstantSearchSSRProvider.test.tsx
+++ b/packages/react-instantsearch-hooks/src/components/__tests__/InstantSearchSSRProvider.test.tsx
@@ -2,7 +2,7 @@ import { render, screen, waitFor } from '@testing-library/react';
import { history } from 'instantsearch.js/es/lib/routers';
import { simple } from 'instantsearch.js/es/lib/stateMappings';
import React from 'react';
-import { Hits, SearchBox } from 'react-instantsearch-hooks-web';
+import { Hits, RefinementList, SearchBox } from 'react-instantsearch-hooks-web';
import { createSearchClient } from '../../../../../test/mock';
import { wait } from '../../../../../test/utils';
@@ -178,6 +178,96 @@ describe('InstantSearchSSRProvider', () => {
});
});
+ test('renders refinements from initial results state', async () => {
+ const searchClient = createSearchClient({});
+ const initialResults = {
+ indexName: {
+ state: {
+ facets: [],
+ disjunctiveFacets: ['brand'],
+ hierarchicalFacets: [],
+ facetsRefinements: {},
+ facetsExcludes: {},
+ disjunctiveFacetsRefinements: { brand: ['Apple'] },
+ numericRefinements: {},
+ tagRefinements: [],
+ hierarchicalFacetsRefinements: {},
+ index: 'indexName',
+ query: '',
+ },
+ results: [
+ {
+ hits: [
+ {
+ name: 'Apple - MacBook Air® (Latest Model) - 13.3" Display - Intel Core i5 - 8GB Memory - 128GB Flash Storage - Silver',
+ objectID: '6443034',
+ },
+ {
+ name: 'Apple - EarPods™ with Remote and Mic - White',
+ objectID: '6848136',
+ },
+ ],
+ nbHits: 442,
+ page: 0,
+ nbPages: 23,
+ hitsPerPage: 2,
+ facets: { brand: { Apple: 442, Samsung: 633 } },
+ exhaustiveFacetsCount: true,
+ exhaustiveNbHits: true,
+ exhaustiveTypo: true,
+ query: '',
+ queryAfterRemoval: '',
+ params: '',
+ index: 'indexName',
+ processingTimeMS: 1,
+ },
+ {
+ hits: [
+ {
+ name: 'Amazon - Fire TV Stick with Alexa Voice Remote - Black',
+ objectID: '5477500',
+ },
+ ],
+ nbHits: 21469,
+ page: 0,
+ nbPages: 1000,
+ hitsPerPage: 1,
+ facets: {
+ brand: { Samsung: 633, Apple: 442 },
+ },
+ exhaustiveFacetsCount: true,
+ exhaustiveNbHits: true,
+ exhaustiveTypo: true,
+ query: '',
+ queryAfterRemoval: '',
+ params: '',
+ index: 'indexName',
+ processingTimeMS: 1,
+ },
+ ],
+ },
+ };
+
+ function App() {
+ return (
+
+
+
+
+
+ );
+ }
+
+ render();
+
+ await waitFor(() => {
+ expect(screen.getByRole('checkbox', { name: 'Apple 442' })).toBeChecked();
+ expect(
+ screen.getByRole('checkbox', { name: 'Samsung 633' })
+ ).not.toBeChecked();
+ });
+ });
+
test('without server state renders children', async () => {
const searchClient = createSearchClient({});