Skip to content

Commit 10223b1

Browse files
test(js): Add tests for render, renderNoResults and renderer (#494)
* test(js): Add tests for `render`, `renderNoResults` and `renderer` Co-authored-by: François Chalifour <[email protected]>
1 parent 6e67740 commit 10223b1

File tree

4 files changed

+1191
-105
lines changed

4 files changed

+1191
-105
lines changed

packages/autocomplete-js/src/__tests__/autocomplete.test.ts

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -358,108 +358,6 @@ describe('autocomplete-js', () => {
358358
});
359359
});
360360

361-
test('calls renderNoResults without noResults template on no results', async () => {
362-
const container = document.createElement('div');
363-
const panelContainer = document.createElement('div');
364-
const renderNoResults = jest.fn((_params, root) => {
365-
const div = document.createElement('div');
366-
div.innerHTML = 'No results render';
367-
368-
root.appendChild(div);
369-
});
370-
371-
document.body.appendChild(panelContainer);
372-
autocomplete<{ label: string }>({
373-
container,
374-
panelContainer,
375-
openOnFocus: true,
376-
getSources() {
377-
return [
378-
{
379-
sourceId: 'testSource',
380-
getItems() {
381-
return [];
382-
},
383-
templates: {
384-
item({ item }) {
385-
return item.label;
386-
},
387-
},
388-
},
389-
];
390-
},
391-
renderNoResults,
392-
});
393-
394-
const input = container.querySelector<HTMLInputElement>('.aa-Input');
395-
396-
fireEvent.input(input, { target: { value: 'a' } });
397-
398-
await waitFor(() => {
399-
expect(
400-
panelContainer.querySelector<HTMLElement>('.aa-Panel')
401-
).toHaveTextContent('No results render');
402-
});
403-
404-
expect(renderNoResults).toHaveBeenCalledWith(
405-
{
406-
state: expect.anything(),
407-
children: expect.anything(),
408-
sections: expect.any(Array),
409-
elements: expect.any(Object),
410-
createElement: expect.anything(),
411-
Fragment: expect.anything(),
412-
},
413-
expect.any(HTMLElement)
414-
);
415-
});
416-
417-
test('renders noResults template over renderNoResults method on no results', async () => {
418-
const container = document.createElement('div');
419-
const panelContainer = document.createElement('div');
420-
421-
document.body.appendChild(panelContainer);
422-
autocomplete<{ label: string }>({
423-
container,
424-
panelContainer,
425-
openOnFocus: true,
426-
getSources() {
427-
return [
428-
{
429-
sourceId: 'testSource',
430-
getItems() {
431-
return [];
432-
},
433-
templates: {
434-
item({ item }) {
435-
return item.label;
436-
},
437-
noResults() {
438-
return 'No results template';
439-
},
440-
},
441-
},
442-
];
443-
},
444-
renderNoResults(_params, root) {
445-
const div = document.createElement('div');
446-
div.innerHTML = 'No results render';
447-
448-
root.appendChild(div);
449-
},
450-
});
451-
452-
const input = container.querySelector<HTMLInputElement>('.aa-Input');
453-
454-
fireEvent.input(input, { target: { value: 'a' } });
455-
456-
await waitFor(() => {
457-
expect(
458-
panelContainer.querySelector<HTMLElement>('.aa-Panel')
459-
).toHaveTextContent('No results template');
460-
});
461-
});
462-
463361
test('allows user-provided shouldPanelOpen', () => {
464362
const container = document.createElement('div');
465363
const panelContainer = document.createElement('div');

0 commit comments

Comments
 (0)