diff --git a/src/documentation/search/SearchResultList.test.tsx b/src/documentation/search/SearchResultList.test.tsx new file mode 100644 index 000000000..d7d5dfec2 --- /dev/null +++ b/src/documentation/search/SearchResultList.test.tsx @@ -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( + + + {}} + /> + + + ); + const marks = screen.getAllByRole("mark"); + expect(marks.map((m) => m.textContent)).toEqual(["Loops", "Loops"]); + }); +}); diff --git a/src/documentation/search/SearchResultList.tsx b/src/documentation/search/SearchResultList.tsx index b5e02c006..24933f3a2 100644 --- a/src/documentation/search/SearchResultList.tsx +++ b/src/documentation/search/SearchResultList.tsx @@ -116,8 +116,15 @@ const ExtractText = ({ extract, title, ...props }: ExtractTextProps) => { {t.extract} ) : ( - // eslint-disable-next-line @eslint-react/no-array-index-key -- position is the only identity here - + {t.extract} )