Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): name the search load-more button by its action

Yudhi Armyndharis02aa7098b645
diff --git a/dashboard/src/components/GlobalSearch.test.ts b/dashboard/src/components/GlobalSearch.test.ts
index 236d200f9..7e2111bd4 100644
--- a/dashboard/src/components/GlobalSearch.test.ts
+++ b/dashboard/src/components/GlobalSearch.test.ts
@@ -46,14 +46,18 @@ function installFetchStub(): void {
}
let rtl: typeof import('@testing-library/react');
+// The label of the button that loads the next page when 20 of 40 hits are shown. It names the action;
+// a bare "40 results" says nothing about what a click does.
+let more40: string;
let GlobalSearch: (typeof import('./GlobalSearch.tsx'))['GlobalSearch'];
before(async () => {
const { installJsdomGlobals } = await import('../test-helpers/jsdom.ts');
await installJsdomGlobals();
installFetchStub();
- const { i18nReady } = await import('../i18n/index.ts');
+ const { i18nReady, default: i18n } = await import('../i18n/index.ts');
await i18nReady;
+ more40 = i18n.t('search.loadMore', { shown: 20, total: 40 });
rtl = await import('@testing-library/react');
({ GlobalSearch } = await import('./GlobalSearch.tsx'));
});
@@ -160,7 +164,7 @@ test('a mouse click on "more" keeps the results open and appends the next page',
input.focus();
await typeAndWaitForRequest(input, 'refund');
await act(async () => pending.get('refund')!(page(0), 40));
- const more = await screen.findByRole('button', { name: '40 results' });
+ const more = await screen.findByRole('button', { name: more40 });
// A real mousedown moves focus off the input; cancelling it is what keeps the input focused.
assert.equal(fireEvent.mouseDown(more), false, 'mousedown on "more" was not cancelled');
@@ -179,14 +183,14 @@ test('a failed "more" keeps the results already shown and offers the button agai
input.focus();
await typeAndWaitForRequest(input, 'refund');
await act(async () => pending.get('refund')!(page(0), 40));
- fireEvent.click(await screen.findByRole('button', { name: '40 results' }));
+ fireEvent.click(await screen.findByRole('button', { name: more40 }));
await waitFor(() => assert.deepEqual(offsets, ['0', '20']));
await act(async () => failing.get('refund')!(500));
await screen.findByText('Search failed. Try again.');
assert.equal(screen.getAllByRole('option').length, 20, 'the first page was dropped');
// The retry runs the same page again, and its success clears the error.
- fireEvent.click(screen.getByRole('button', { name: '40 results' }));
+ fireEvent.click(screen.getByRole('button', { name: more40 }));
await waitFor(() => assert.deepEqual(offsets, ['0', '20', '20']));
await act(async () => pending.get('refund')!(page(20), 40));
await waitFor(() => assert.equal(screen.getAllByRole('option').length, 40));
@@ -200,13 +204,13 @@ test('a failed search shows only the error', async () => {
input.focus();
await typeAndWaitForRequest(input, 'refund');
await act(async () => pending.get('refund')!(page(0), 40));
- await screen.findByRole('button', { name: '40 results' });
+ await screen.findByRole('button', { name: more40 });
await typeAndWaitForRequest(input, 'refunds');
await act(async () => failing.get('refunds')!(500));
await screen.findByText('Search failed. Try again.');
assert.equal(screen.queryAllByRole('option').length, 0, "the previous query's hits stayed on screen");
- assert.equal(screen.queryByRole('button', { name: '40 results' }), null);
+ assert.equal(screen.queryByRole('button', { name: more40 }), null);
assert.equal(screen.queryByText('No messages found.'), null);
});
@@ -217,7 +221,7 @@ test('Tab then Enter on "more" keeps the results open and returns focus to the i
input.focus();
await typeAndWaitForRequest(input, 'refund');
await act(async () => pending.get('refund')!(page(0), 40));
- const more = await screen.findByRole('button', { name: '40 results' });
+ const more = await screen.findByRole('button', { name: more40 });
// Tabbing moves focus from the input to the button; the results must outlive the close timer.
act(() => more.focus());
@@ -345,7 +349,7 @@ test('Escape with focus on "more" closes the results and is consumed', async ()
input.focus();
await typeAndWaitForRequest(input, 'refund');
await act(async () => pending.get('refund')!(page(0), 40));
- const more = await screen.findByRole('button', { name: '40 results' });
+ const more = await screen.findByRole('button', { name: more40 });
act(() => more.focus());
// Unconsumed, the key would reach the Chats page handler and close the open conversation instead.
assert.equal(fireEvent.keyDown(more, { key: 'Escape' }), false, 'Escape on "more" was not consumed');
diff --git a/dashboard/src/components/GlobalSearch.tsx b/dashboard/src/components/GlobalSearch.tsx
index a9cd0aa4e..943b13863 100644
--- a/dashboard/src/components/GlobalSearch.tsx
+++ b/dashboard/src/components/GlobalSearch.tsx
@@ -197,7 +197,7 @@ export function GlobalSearch({ onHit, currentSessionId }: GlobalSearchProps) {
// preventDefault on mousedown keeps focus in the input, so a mouse click does not start the
// close timer; click still fires for the mouse and for Enter/Space.
<button className="global-search-more" onMouseDown={e => e.preventDefault()} onClick={loadMore}>
- {t('search.results', { count: total })}
+ {t('search.loadMore', { shown: hits.length, total })}
</button>
)}
</div>