Skip to content

Commit c4f41e5

Browse files
authored
Feature/search result nav link (#378)
* feat: Added nav links to search results * fix: warning about events firing after test has ended
1 parent 4fdd0d9 commit c4f41e5

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/features/search/components/search.test.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,19 @@ describe('search', () => {
8686
return executeComponentTest(
8787
() => render(<Search />, undefined, myStore),
8888
async (component, user) => {
89-
const input = component.getByPlaceholderText(searchPlaceholderLabel)
90-
await user.type(input, id)
91-
const results = (await component.findAllByText(label, undefined, { timeout: 1000 })).map((result) => result.parentElement)
92-
const result = results.find((result) => result!.textContent!.includes(type))!
93-
await user.click(result)
94-
9589
await waitFor(
9690
async () => {
91+
const input = component.getByPlaceholderText(searchPlaceholderLabel)
92+
await user.type(input, id)
93+
94+
const results = (await component.findAllByText(label, undefined, { timeout: 1000 })).map((result) => result.parentElement)
95+
results.forEach((result) => {
96+
const link = result!.querySelector('a')
97+
expect(link).toHaveTextContent(label)
98+
})
99+
100+
const result = results.find((result) => result!.textContent!.includes(type))!
101+
await user.click(result)
97102
expect(mockNavigate).toHaveBeenCalledWith(`/localnet/${type.toLowerCase()}/${id}`)
98103
},
99104
{ timeout: 10000 }

src/features/search/components/search.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { cn } from '@/features/common/utils'
1111
import { useCallback, useEffect, useRef } from 'react'
1212
import { RenderLoadable } from '@/features/common/components/render-loadable'
13-
import { useNavigate } from 'react-router-dom'
13+
import { useNavigate, NavLink } from 'react-router-dom'
1414
import { useSearch } from '../data'
1515
import { Loader2 as Loader } from 'lucide-react'
1616
import { useLocationChange } from '@/features/common/hooks/use-location-change'
@@ -93,7 +93,9 @@ export function Search() {
9393
{results.map((result) => {
9494
return (
9595
<CommandItem key={`${result.type}-${result.id}`} value={result.url} onSelect={handleSelection}>
96-
<span>{result.label}</span>
96+
<NavLink className="truncate text-primary underline" to={result.url}>
97+
{result.label}
98+
</NavLink>
9799
<span className={cn('ml-auto text-xs')}>{result.type}</span>
98100
</CommandItem>
99101
)

0 commit comments

Comments
 (0)