-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from prismicio/xru/support-link-text
feat: support link text
- Loading branch information
Showing
6 changed files
with
86 additions
and
151 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,33 @@ | ||
// @vitest-environment happy-dom | ||
import { expect, it } from "vitest"; | ||
|
||
import { render } from "@testing-library/svelte"; | ||
|
||
import PrismicLinkTestWrapper from "./PrismicLinkTestWrapper.svelte"; | ||
|
||
it("renders the link's text if no children are provided", (ctx) => { | ||
const model = ctx.mock.model.link({ | ||
allowText: true, | ||
allowTargetBlank: false, | ||
}); | ||
const field = ctx.mock.value.link({ type: "Web", model, withText: true }); | ||
const { container } = render(PrismicLinkTestWrapper, { field }); | ||
|
||
expect(container.innerHTML).toBe( | ||
`<div><a href="${field.url}" rel="noreferrer">${field.text}</a></div>`, | ||
); | ||
}); | ||
|
||
it("renders the given children, overriding the link's text", (ctx) => { | ||
const model = ctx.mock.model.link({ | ||
allowText: true, | ||
allowTargetBlank: false, | ||
}); | ||
const field = ctx.mock.value.link({ type: "Web", model, withText: true }); | ||
const children = ctx.mock.value.keyText(); | ||
const { container } = render(PrismicLinkTestWrapper, { field, children }); | ||
|
||
expect(container.innerHTML).toBe( | ||
`<div><a href="${field.url}" rel="noreferrer">${children}</a></div>`, | ||
); | ||
}); |
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,18 @@ | ||
<!-- | ||
This file is a wrapper for the PrismicLink component to be used in tests as | ||
passing slot content to the PrismicLink component is not easy in tests. | ||
--> | ||
|
||
<script lang="ts"> | ||
import { FilledLinkToWebField } from "@prismicio/client"; | ||
import { PrismicLink } from "../src"; | ||
export let field: FilledLinkToWebField; | ||
export let children: string | undefined = undefined; | ||
</script> | ||
|
||
{#if children} | ||
<PrismicLink {field}>{children}</PrismicLink> | ||
{:else} | ||
<PrismicLink {field} /> | ||
{/if} |