Skip to content

Commit 952c4cb

Browse files
committed
chore(core): move tests to core
these were still in instantsearch.js but actually are for the "core" domain now.
1 parent a9b623e commit 952c4cb

14 files changed

+105
-105
lines changed

packages/instantsearch.js/src/lib/__tests__/RoutingManager-test.ts renamed to packages/instantsearch-core/src/__tests__/RoutingManager.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import { createSearchClient } from '@instantsearch/mocks';
66
import { wait } from '@instantsearch/testutils/wait';
77
import qs from 'qs';
88

9-
import instantsearch from '../..';
10-
import { createWidget } from '../../../test/createWidget';
11-
import { connectHitsPerPage, connectSearchBox } from '../../connectors';
12-
import historyRouter from '../routers/history';
13-
14-
import type { Router, UiState, StateMapping, IndexUiState } from '../../types';
9+
import {
10+
instantsearch,
11+
historyRouter,
12+
connectHitsPerPage,
13+
connectSearchBox,
14+
} from '..';
15+
import { createWidget } from '../../test/createWidget';
16+
17+
import type { Router, UiState, StateMapping, IndexUiState } from '../types';
1518
import type { JSDOM } from 'jsdom';
1619

1720
declare const jsdom: JSDOM;

packages/instantsearch.js/src/lib/__tests__/InstantSearch-integration-test.ts renamed to packages/instantsearch-core/src/__tests__/instantsearch-integration.test.ts

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import { castToJestMock } from '@instantsearch/testutils';
88
import { wait } from '@instantsearch/testutils/wait';
99
import { getByText, fireEvent } from '@testing-library/dom';
1010

11-
import { connectConfigure, connectSearchBox } from '../../connectors';
12-
import instantsearch from '../../index.es';
13-
import { configure, frequentlyBoughtTogether, searchBox } from '../../widgets';
11+
import {
12+
instantsearch,
13+
connectConfigure,
14+
connectSearchBox,
15+
connectFrequentlyBoughtTogether,
16+
} from '..';
1417

15-
import type { MiddlewareDefinition } from '../../types';
18+
import type { MiddlewareDefinition } from '../types';
1619

1720
describe('configure', () => {
1821
it('provides up-to-date uiState to onStateChange', () => {
@@ -38,8 +41,10 @@ describe('configure', () => {
3841
}
3942
});
4043
search.addWidgets([
41-
configure({
42-
hitsPerPage: 10,
44+
connectConfigure(() => {})({
45+
searchParameters: {
46+
hitsPerPage: 10,
47+
},
4348
}),
4449
customComp({ searchParameters: {} }),
4550
]);
@@ -57,7 +62,6 @@ describe('configure', () => {
5762

5863
describe('middleware', () => {
5964
it("runs middlewares' onStateChange when uiState changes", async () => {
60-
const container = document.createElement('div');
6165
const search = instantsearch({
6266
indexName: 'instant_search',
6367
searchClient: createSearchClient(),
@@ -74,25 +78,17 @@ describe('middleware', () => {
7478

7579
search.use(() => middlewareDefinition);
7680

77-
search.addWidgets([
78-
searchBox({
79-
container,
80-
placeholder: 'search',
81-
}),
82-
]);
81+
search.addWidgets([connectSearchBox(() => {})({})]);
8382

8483
search.start();
8584

86-
fireEvent.input(container.querySelector('input')!, {
87-
target: { value: 'q' },
88-
});
85+
search.renderState.instant_search.searchBox!.refine('q');
8986

9087
await wait(0);
9188
expect(middlewareDefinition.onStateChange).toHaveBeenCalledTimes(1);
9289
});
9390

9491
it("runs middlewares' onStateChange when uiState changes with user-provided onStateChange param", async () => {
95-
const container = document.createElement('div');
9692
const search = instantsearch({
9793
indexName: 'instant_search',
9894
searchClient: createSearchClient(),
@@ -112,27 +108,18 @@ describe('middleware', () => {
112108

113109
search.use(() => middlewareDefinition);
114110

115-
search.addWidgets([
116-
searchBox({
117-
container,
118-
placeholder: 'search',
119-
}),
120-
]);
111+
search.addWidgets([connectSearchBox(() => {})({})]);
121112

122113
search.start();
123114

124-
fireEvent.input(container.querySelector('input')!, {
125-
target: { value: 'q' },
126-
});
115+
search.renderState.instant_search.searchBox!.refine('q');
127116

128117
await wait(0);
129118
expect(middlewareDefinition.onStateChange).toHaveBeenCalledTimes(1);
130119
});
131120
});
132121

133122
describe('errors', () => {
134-
const virtualSearchBox = connectSearchBox(() => {});
135-
136123
it('client errors can be handled', () => {
137124
const search = instantsearch({
138125
searchClient: createSearchClient({
@@ -143,7 +130,7 @@ describe('errors', () => {
143130
indexName: '123',
144131
});
145132

146-
search.addWidgets([virtualSearchBox({})]);
133+
search.addWidgets([connectSearchBox(() => {})({})]);
147134

148135
expect.assertions(4);
149136

@@ -184,7 +171,7 @@ describe('network requests', () => {
184171
indexName: 'indexName',
185172
searchClient,
186173
})
187-
.addWidgets([searchBox({ container: document.createElement('div') })])
174+
.addWidgets([connectSearchBox(() => {})({})])
188175
.start();
189176

190177
await wait(0);
@@ -212,9 +199,8 @@ describe('network requests', () => {
212199
searchClient,
213200
})
214201
.addWidgets([
215-
frequentlyBoughtTogether({
202+
connectFrequentlyBoughtTogether(() => {})({
216203
objectIDs: ['one'],
217-
container: document.createElement('div'),
218204
}),
219205
])
220206
.start();
@@ -250,10 +236,9 @@ describe('network requests', () => {
250236
searchClient,
251237
})
252238
.addWidgets([
253-
searchBox({ container: document.createElement('div') }),
254-
frequentlyBoughtTogether({
239+
connectSearchBox(() => {})({}),
240+
connectFrequentlyBoughtTogether(() => {})({
255241
objectIDs: ['one'],
256-
container: document.createElement('div'),
257242
}),
258243
])
259244
.start();
@@ -327,7 +312,7 @@ describe('network requests', () => {
327312
searchClient,
328313
insights: true,
329314
})
330-
.addWidgets([searchBox({ container: document.createElement('div') })])
315+
.addWidgets([connectSearchBox(() => {})({})])
331316
.start();
332317

333318
await wait(0);
@@ -358,9 +343,8 @@ describe('network requests', () => {
358343
insights: true,
359344
})
360345
.addWidgets([
361-
frequentlyBoughtTogether({
346+
connectFrequentlyBoughtTogether(() => {})({
362347
objectIDs: ['one'],
363-
container: document.createElement('div'),
364348
}),
365349
])
366350
.start();
@@ -397,10 +381,9 @@ describe('network requests', () => {
397381
insights: true,
398382
})
399383
.addWidgets([
400-
searchBox({ container: document.createElement('div') }),
401-
frequentlyBoughtTogether({
384+
connectSearchBox(() => {})({}),
385+
connectFrequentlyBoughtTogether(() => {})({
402386
objectIDs: ['one'],
403-
container: document.createElement('div'),
404387
}),
405388
])
406389
.start();
@@ -476,7 +459,7 @@ describe('network requests', () => {
476459
searchClient,
477460
insights: true,
478461
})
479-
.addWidgets([searchBox({ container: document.createElement('div') })])
462+
.addWidgets([connectSearchBox(() => {})({})])
480463
.start();
481464

482465
await wait(0);
@@ -507,9 +490,8 @@ describe('network requests', () => {
507490
insights: true,
508491
})
509492
.addWidgets([
510-
frequentlyBoughtTogether({
493+
connectFrequentlyBoughtTogether(() => {})({
511494
objectIDs: ['one'],
512-
container: document.createElement('div'),
513495
}),
514496
])
515497
.start();
@@ -546,10 +528,9 @@ describe('network requests', () => {
546528
insights: true,
547529
})
548530
.addWidgets([
549-
searchBox({ container: document.createElement('div') }),
550-
frequentlyBoughtTogether({
531+
connectSearchBox(() => {})({}),
532+
connectFrequentlyBoughtTogether(() => {})({
551533
objectIDs: ['one'],
552-
container: document.createElement('div'),
553534
}),
554535
])
555536
.start();
@@ -592,12 +573,11 @@ describe('network requests', () => {
592573
describe('interactive life cycle', () => {
593574
it('sends no queries when widgets are removed', async () => {
594575
const searchClient = createRecommendSearchClient();
595-
const searchBoxWidget = searchBox({
596-
container: document.createElement('div'),
597-
});
598-
const frequentlyBoughtTogetherWidget = frequentlyBoughtTogether({
576+
const searchBoxWidget = connectSearchBox(() => {})({});
577+
const frequentlyBoughtTogetherWidget = connectFrequentlyBoughtTogether(
578+
() => {}
579+
)({
599580
objectIDs: ['one'],
600-
container: document.createElement('div'),
601581
});
602582
const search = instantsearch({
603583
indexName: 'indexName',

packages/instantsearch.js/src/lib/__tests__/InstantSearch-test.tsx renamed to packages/instantsearch-core/src/__tests__/instantsearch.test.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@ import { wait } from '@instantsearch/testutils/wait';
1414
import originalHelper from 'algoliasearch-helper';
1515
import { h, render, createRef } from 'preact';
1616

17-
import { createRenderOptions, createWidget } from '../../../test/createWidget';
18-
import { connectSearchBox, connectPagination } from '../../connectors';
19-
import { createInsightsMiddleware } from '../../middlewares';
20-
import { index } from '../../widgets';
21-
import InstantSearch from '../InstantSearch';
17+
import {
18+
InstantSearch,
19+
index,
20+
createInsightsMiddleware,
21+
connectSearchBox,
22+
connectPagination,
23+
} from '..';
24+
import { createRenderOptions, createWidget } from '../../test/createWidget';
2225
import version from '../version';
2326

2427
import type {
25-
UiState,
26-
Widget,
27-
IndexWidget,
2828
PaginationConnectorParams,
2929
PaginationWidgetDescription,
3030
SearchBoxWidgetDescription,
3131
SearchBoxConnectorParams,
32-
} from '../../types';
32+
} from '..';
33+
import type { UiState, Widget, IndexWidget } from '../types';
3334
import type { RefObject } from 'preact';
3435

3536
type SearchBoxWidgetInstance = Widget<
@@ -318,12 +319,9 @@ describe('InstantSearch', () => {
318319
searchClient,
319320
});
320321

321-
expect(searchClient.addAlgoliaAgent).toHaveBeenCalledTimes(2);
322-
expect(searchClient.addAlgoliaAgent).toHaveBeenCalledWith(
323-
expect.stringMatching(/^instantsearch-core \(.*\)$/)
324-
);
322+
expect(searchClient.addAlgoliaAgent).toHaveBeenCalledTimes(1);
325323
expect(searchClient.addAlgoliaAgent).toHaveBeenCalledWith(
326-
`instantsearch.js (${version})`
324+
`instantsearch-core (${version})`
327325
);
328326
});
329327

packages/instantsearch.js/src/lib/__tests__/server.test.ts renamed to packages/instantsearch-core/src/__tests__/server.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import {
44
} from '@instantsearch/mocks';
55

66
import {
7+
getInitialResults,
8+
waitForResults,
9+
instantsearch,
10+
index,
711
connectConfigure,
812
connectHierarchicalMenu,
913
connectSearchBox,
10-
} from '../../connectors';
11-
import instantsearch from '../../index.es';
12-
import { index } from '../../widgets';
13-
import { getInitialResults, waitForResults } from '../server';
14+
} from '..';
1415

1516
describe('waitForResults', () => {
1617
test('waits for the results from the search instance', async () => {

packages/instantsearch.js/src/lib/__tests__/status.test.ts renamed to packages/instantsearch-core/src/__tests__/status.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createSearchClient } from '@instantsearch/mocks';
22
import { wait } from '@instantsearch/testutils/wait';
33

4-
import { connectSearchBox } from '../../connectors';
5-
import instantsearch from '../../index.es';
4+
import { connectSearchBox } from '../connectors';
5+
import { instantsearch } from '../instantsearch';
66

7-
import type InstantSearch from '../InstantSearch';
7+
import type { InstantSearch } from '../instantsearch';
88

99
function createDelayedSearchClient(timeout: number) {
1010
const searchClient = createSearchClient();

packages/instantsearch.js/src/lib/__tests__/routing/correct-urls.test.ts renamed to packages/instantsearch-core/src/routing/__tests__/correct-urls.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import { createSearchClient } from '@instantsearch/mocks';
66
import { wait } from '@instantsearch/testutils/wait';
77

8-
import { connectPagination, connectSearchBox } from '../../../connectors';
9-
import instantsearch from '../../../index.es';
10-
import { index } from '../../../widgets';
11-
import historyRouter from '../../routers/history';
8+
import {
9+
instantsearch,
10+
index,
11+
historyRouter,
12+
connectPagination,
13+
connectSearchBox,
14+
} from '../..';
1215

1316
beforeEach(() => {
1417
window.history.pushState({}, '', '/');

packages/instantsearch.js/src/lib/__tests__/routing/dispose-start-test.ts renamed to packages/instantsearch-core/src/routing/__tests__/dispose-start.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
import { createSearchClient } from '@instantsearch/mocks';
66
import { wait } from '@instantsearch/testutils/wait';
77

8-
import instantsearch from '../../..';
9-
import { connectSearchBox } from '../../../connectors';
10-
import historyRouter from '../../routers/history';
8+
import { instantsearch, historyRouter, connectSearchBox } from '../..';
119

12-
import type InstantSearch from '../../InstantSearch';
10+
import type { InstantSearch } from '../..';
1311

1412
/* eslint no-lone-blocks: "off" */
1513

packages/instantsearch.js/src/lib/__tests__/routing/duplicate-url-test.ts renamed to packages/instantsearch-core/src/routing/__tests__/duplicate-url.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
import { createSearchClient } from '@instantsearch/mocks';
66
import { wait } from '@instantsearch/testutils/wait';
77

8-
import instantsearch from '../../..';
9-
import { connectPagination, connectSearchBox } from '../../../connectors';
10-
import historyRouter from '../../routers/history';
8+
import {
9+
instantsearch,
10+
historyRouter,
11+
connectPagination,
12+
connectSearchBox,
13+
} from '../..';
1114

1215
/* eslint no-lone-blocks: "off" */
1316

packages/instantsearch.js/src/lib/__tests__/routing/external-influence-test.ts renamed to packages/instantsearch-core/src/routing/__tests__/external-influence.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import { createSearchClient } from '@instantsearch/mocks';
66
import { wait } from '@instantsearch/testutils/wait';
77

8-
import instantsearch from '../../..';
9-
import { connectSearchBox } from '../../../connectors';
10-
import historyRouter from '../../routers/history';
8+
import { instantsearch, historyRouter, connectSearchBox } from '../..';
119

1210
/* eslint no-lone-blocks: "off" */
1311

packages/instantsearch.js/src/lib/__tests__/routing/modal-test.ts renamed to packages/instantsearch-core/src/routing/__tests__/modal.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import { createSearchClient } from '@instantsearch/mocks';
66
import { wait } from '@instantsearch/testutils/wait';
77

8-
import instantsearch from '../../..';
9-
import { connectSearchBox } from '../../../connectors';
10-
import historyRouter from '../../routers/history';
8+
import { instantsearch, historyRouter, connectSearchBox } from '../..';
119

1210
/* eslint no-lone-blocks: "off" */
1311

0 commit comments

Comments
 (0)