|
9 | 9 | import { autocomplete } from '../autocomplete'; |
10 | 10 |
|
11 | 11 | describe('render', () => { |
| 12 | + const sourceId1 = 'testSource1'; |
| 13 | + const sourceId2 = 'testSource2'; |
| 14 | + |
12 | 15 | beforeEach(() => { |
13 | 16 | document.body.innerHTML = ''; |
14 | 17 | }); |
@@ -181,8 +184,6 @@ describe('render', () => { |
181 | 184 | }); |
182 | 185 |
|
183 | 186 | test('provides the elements', async () => { |
184 | | - const sourceId1 = 'testSource1'; |
185 | | - const sourceId2 = 'testSource2'; |
186 | 187 | const container = document.createElement('div'); |
187 | 188 | const panelContainer = document.createElement('div'); |
188 | 189 |
|
@@ -253,8 +254,6 @@ describe('render', () => { |
253 | 254 | }); |
254 | 255 |
|
255 | 256 | test('provides the sections', async () => { |
256 | | - const sourceId1 = 'testSource1'; |
257 | | - const sourceId2 = 'testSource2'; |
258 | 257 | const container = document.createElement('div'); |
259 | 258 | const panelContainer = document.createElement('div'); |
260 | 259 |
|
@@ -536,4 +535,75 @@ describe('render', () => { |
536 | 535 | }, |
537 | 536 | }); |
538 | 537 | }); |
| 538 | + |
| 539 | + test('does not render the sections without results and noResults template on multi sources', async () => { |
| 540 | + const container = document.createElement('div'); |
| 541 | + const panelContainer = document.createElement('div'); |
| 542 | + |
| 543 | + document.body.appendChild(panelContainer); |
| 544 | + autocomplete<{ label: string }>({ |
| 545 | + container, |
| 546 | + panelContainer, |
| 547 | + openOnFocus: true, |
| 548 | + getSources() { |
| 549 | + return [ |
| 550 | + { |
| 551 | + sourceId: sourceId1, |
| 552 | + getItems() { |
| 553 | + return []; |
| 554 | + }, |
| 555 | + templates: { |
| 556 | + header() { |
| 557 | + return sourceId1; |
| 558 | + }, |
| 559 | + item({ item }) { |
| 560 | + return item.label; |
| 561 | + }, |
| 562 | + footer() { |
| 563 | + return sourceId1; |
| 564 | + }, |
| 565 | + }, |
| 566 | + }, |
| 567 | + { |
| 568 | + sourceId: sourceId2, |
| 569 | + getItems() { |
| 570 | + return [{ label: '2' }]; |
| 571 | + }, |
| 572 | + templates: { |
| 573 | + header() { |
| 574 | + return sourceId2; |
| 575 | + }, |
| 576 | + item({ item }) { |
| 577 | + return item.label; |
| 578 | + }, |
| 579 | + footer() { |
| 580 | + return sourceId2; |
| 581 | + }, |
| 582 | + }, |
| 583 | + }, |
| 584 | + ]; |
| 585 | + }, |
| 586 | + }); |
| 587 | + |
| 588 | + const input = container.querySelector<HTMLInputElement>('.aa-Input'); |
| 589 | + |
| 590 | + fireEvent.input(input, { target: { value: 'a' } }); |
| 591 | + |
| 592 | + await waitFor(() => { |
| 593 | + expect( |
| 594 | + panelContainer.querySelector<HTMLElement>('.aa-Panel') |
| 595 | + ).toBeInTheDocument(); |
| 596 | + |
| 597 | + expect( |
| 598 | + panelContainer.querySelector( |
| 599 | + `[data-autocomplete-source-id="${sourceId1}"]` |
| 600 | + ) |
| 601 | + ).not.toBeInTheDocument(); |
| 602 | + expect( |
| 603 | + panelContainer.querySelector( |
| 604 | + `[data-autocomplete-source-id="${sourceId2}"]` |
| 605 | + ) |
| 606 | + ).toBeInTheDocument(); |
| 607 | + }); |
| 608 | + }); |
539 | 609 | }); |
0 commit comments