Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/documentation/search/SearchResultList.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* (c) 2026, Micro:bit Educational Foundation and contributors
*
* SPDX-License-Identifier: MIT
*/
import { render, screen } from "@testing-library/react";
import { IntlProvider } from "react-intl";
import { MemoryRouter } from "react-router";
import { Result } from "./common";
import SearchResultList from "./SearchResultList";

describe("SearchResultList", () => {
it("marks matched terms so assistive technology can announce them", () => {
const result: Result = {
id: "loops",
navigation: { tab: "reference", slug: { id: "loops" } },
containerTitle: "Loops",
title: "Loops",
extract: {
title: [{ type: "match", extract: "Loops" }],
content: [
{ type: "match", extract: "Loops" },
{ type: "text", extract: " repeat sections of code." },
],
},
};
render(
<IntlProvider locale="en">
<MemoryRouter>
<SearchResultList
title="Reference"
results={[result]}
viewedResults={[]}
onViewResult={() => {}}
/>
</MemoryRouter>
</IntlProvider>
);
const marks = screen.getAllByRole("mark");
expect(marks.map((m) => m.textContent)).toEqual(["Loops", "Loops"]);
});
});
11 changes: 9 additions & 2 deletions src/documentation/search/SearchResultList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,15 @@ const ExtractText = ({ extract, title, ...props }: ExtractTextProps) => {
{t.extract}
</Text>
) : (
// eslint-disable-next-line @eslint-react/no-array-index-key -- position is the only identity here
<Text key={i} as="span" bgColor="#6C4BC14D" borderRadius="md" p="0.5">
<Text
// eslint-disable-next-line @eslint-react/no-array-index-key -- position is the only identity here
key={i}
as="mark"
color="inherit"
bgColor="#6C4BC14D"
borderRadius="md"
p="0.5"
>
{t.extract}
</Text>
)
Expand Down
Loading