-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autocomplete): link to text fragment
- Loading branch information
1 parent
ee26428
commit c9b04ce
Showing
2 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
apps/site/assets/ts/ui/__tests__/autocomplete-templates-test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { LinkForItem } from "../autocomplete/templates/algolia"; | ||
import { AutocompleteItem } from "../autocomplete/__autocomplete"; | ||
|
||
test("LinkForItem renders simplelink", () => { | ||
const contentItem = { | ||
_content_url: "/page1", | ||
_content_type: "page", | ||
content_title: "Page One", | ||
index: "drupal", | ||
objectID: "sdfsda", | ||
_highlightResult: { content_title: { matchedWords: ["one"] } } | ||
} as AutocompleteItem; | ||
render( | ||
<LinkForItem item={contentItem} query="one"> | ||
<div>Content</div> | ||
</LinkForItem> | ||
); | ||
|
||
expect(screen.getByRole("link")).toHaveAttribute("href", "/page1"); | ||
}); | ||
|
||
test("LinkForItem renders link to text fragment", () => { | ||
const contentItemNoMatch = { | ||
_content_url: "/page2", | ||
_content_type: "page", | ||
content_title: "Page Two", | ||
index: "drupal", | ||
objectID: "sdfsda", | ||
_highlightResult: { content_title: { matchedWords: [] } } | ||
} as AutocompleteItem; | ||
render( | ||
<LinkForItem item={contentItemNoMatch} query="searched text"> | ||
<div>Content</div> | ||
</LinkForItem> | ||
); | ||
|
||
expect(screen.getByRole("link")).toHaveAttribute( | ||
"href", | ||
"/page2#:~:text=searched%20text" | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters