Skip to content

Commit e503fd0

Browse files
committed
fix: add missing page parameter for union search pagination
- set commonParams.page from first search request when union is configured - add pagination tests for union search with multi-index result merging - ensure different results are shown when navigating between pages
1 parent 2e33a8f commit e503fd0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/SearchRequestAdapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ export class SearchRequestAdapter {
491491
// Add union parameter if configured
492492
if (this.configuration.union) {
493493
searchRequest.union = this.configuration.union;
494+
commonParams.page = searches[0].page;
494495
}
495496

496497

test/unionSearch.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,37 @@ describe("Union Search", () => {
5858
});
5959
});
6060
});
61+
62+
describe("pagination with union search", () => {
63+
beforeEach(async () => {
64+
return expect(page).toFill("#searchbox input[type=search]", "phone");
65+
});
66+
67+
it("renders pagination controls for merged results from multiple indices", async () => {
68+
await page.waitForSelector("#pagination a.ais-Pagination-link");
69+
70+
const paginationLinks = await page.$$("#pagination a.ais-Pagination-link");
71+
expect(paginationLinks.length).toBeGreaterThan(0);
72+
73+
await expect(page).toMatchElement("#hits .ais-Hits-item:nth-of-type(1)");
74+
});
75+
76+
it("shows different merged results when navigating to the second page", async () => {
77+
await page.waitForSelector("#pagination a.ais-Pagination-link");
78+
79+
const firstPageFirstResult = await page.$eval("#hits .ais-Hits-item:nth-of-type(1)", (el) => el.textContent);
80+
81+
await expect(page).toClick("#pagination a", { text: "2" });
82+
83+
await page.waitForSelector("#hits .ais-Hits-item:nth-of-type(1)");
84+
85+
const secondPageFirstResult = await page.$eval("#hits .ais-Hits-item:nth-of-type(1)", (el) => el.textContent);
86+
87+
expect(firstPageFirstResult).not.toBe(secondPageFirstResult);
88+
89+
await expect(page).toMatchElement("#hits");
90+
await expect(page).not.toMatchElement("#product-hits", { timeout: 1000 });
91+
await expect(page).not.toMatchElement("#brand-hits", { timeout: 1000 });
92+
});
93+
});
6194
});

0 commit comments

Comments
 (0)