Skip to content

Commit f910353

Browse files
committed
#266 fix search keyboard, add to test
1 parent e351214 commit f910353

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

data-browser/src/routes/SearchRoute.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ export function Search(): JSX.Element {
2323
scope: scope || drive,
2424
});
2525
const navigate = useNavigate();
26-
const htmlElRef = useRef<HTMLDivElement | null>(null);
26+
const resultsDiv = useRef<HTMLDivElement | null>(null);
2727

2828
function selectResult(index: number) {
2929
setSelected(index);
30-
const currentElm = htmlElRef?.current?.children[index];
30+
const currentElm = resultsDiv?.current?.children[index];
3131
currentElm?.scrollIntoView({ block: 'nearest' });
3232
}
3333

@@ -36,7 +36,7 @@ export function Search(): JSX.Element {
3636
e => {
3737
e.preventDefault();
3838
const subject =
39-
htmlElRef?.current?.children[selectedIndex]?.getAttribute('about');
39+
resultsDiv?.current?.children[selectedIndex]?.getAttribute('about');
4040

4141
if (subject) {
4242
//@ts-ignore blur does exist though
@@ -80,9 +80,10 @@ export function Search(): JSX.Element {
8080
}
8181

8282
return (
83-
<ContainerNarrow ref={htmlElRef}>
84-
{error && <ErrorLook>{error.message}</ErrorLook>}
85-
{query?.length !== 0 && results.length !== 0 ? (
83+
<ContainerNarrow>
84+
{error ? (
85+
<ErrorLook>{error.message}</ErrorLook>
86+
) : query?.length !== 0 && results.length !== 0 ? (
8687
<>
8788
<Heading>
8889
<FaSearch />
@@ -91,15 +92,17 @@ export function Search(): JSX.Element {
9192
<QueryText>{query}</QueryText>
9293
</span>
9394
</Heading>
94-
{results.map((subject, index) => (
95-
<ResourceCard
96-
initialInView={index < 5}
97-
small
98-
subject={subject}
99-
key={subject}
100-
highlight={index === selectedIndex}
101-
/>
102-
))}
95+
<div ref={resultsDiv}>
96+
{results.map((subject, index) => (
97+
<ResourceCard
98+
initialInView={index < 5}
99+
small
100+
subject={subject}
101+
key={subject}
102+
highlight={index === selectedIndex}
103+
/>
104+
))}
105+
</div>
103106
</>
104107
) : (
105108
<>{message}</>

data-browser/tests/e2e.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ test.describe('data-browser', async () => {
107107
await editProfileAndCommit(page);
108108
});
109109

110-
test('search', async ({ page }) => {
111-
await page.fill(addressBar, 'setup');
112-
await page.click('text=setup');
113-
await expect(page.locator('text=Use this Invite')).toBeVisible();
110+
test('text search', async ({ page }) => {
111+
await page.fill(addressBar, 'welcome');
112+
await expect(page.locator('text=Welcome to your')).toBeVisible();
113+
await page.keyboard.press('Enter');
114+
await expect(page.locator('text=resources:')).toBeVisible();
114115
});
115116

116117
test('scoped search', async ({ page }) => {

0 commit comments

Comments
 (0)