Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xrutayisire committed Aug 29, 2024
1 parent 7681993 commit 6d83ba2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
6 changes: 1 addition & 5 deletions src/PrismicNextLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,13 @@ export const PrismicNextLink = React.forwardRef<
});

const href = ("href" in restProps ? restProps.href : computedHref) || "";
const text = prismic.isFilled.link(field) ? field.text : undefined;

let rel = computedRel;
if ("rel" in restProps && typeof restProps.rel !== "function") {
rel = restProps.rel;
}

let text: string | undefined;
if (field && "text" in field) {
text = field.text;
}

return (
<Link ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
{children || text}
Expand Down
13 changes: 6 additions & 7 deletions test/PrismicNextLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,9 @@ it("forwards ref", (ctx) => {
expect(ref).toHaveBeenCalledWith({ tagName: "a" });
});

it("renders a next/link with text and without children", (ctx) => {
const field = ctx.mock.value.link({
type: "Web",
model: { type: "Link", config: { text: { type: "Text" } } },
});
it("renders a next/link with text", (ctx) => {
const model = ctx.mock.model.link({ text: true });
const field = ctx.mock.value.link({ type: "Web", model });

const actual = renderJSON(<PrismicNextLink field={field} />);
const expected = renderJSON(
Expand All @@ -254,8 +252,9 @@ it("renders a next/link with text and without children", (ctx) => {
expectLinkToEqual(actual, expected);
});

it("renders a next/link with text and children", (ctx) => {
const field = ctx.mock.value.link({ type: "Web" });
it("renders a next/link with the given children, overriding the link's text", (ctx) => {
const model = ctx.mock.model.link({ text: true });
const field = ctx.mock.value.link({ type: "Web", model });
const children = ctx.mock.value.keyText();

const actual = renderJSON(
Expand Down

0 comments on commit 6d83ba2

Please sign in to comment.