Skip to content

Commit

Permalink
fix(pages-components): link's href not obfuscated (#76)
Browse files Browse the repository at this point in the history
* fix(pages-components): link's href not obfuscated

* Update snapshots

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
mkilpatrick and github-actions[bot] authored Jan 7, 2025
1 parent 09bf670 commit 8e102cc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions packages/pages-components/src/components/link/link.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ describe("Link", () => {
it("throws an error when cta link is not set", () => {
expect(() => render(<Link cta={{} as CTA} />)).toThrowError();
});

it("renders with obfuscated email when using cta link", () => {
render(<Link cta={{ link: "mailto:test.com" }} />);
const link = screen.getByRole("link");
expect(link.getAttribute("href")).toEqual("bWFpbHRvOnRlc3QuY29t");
});

it("renders with obfuscated email when using href", () => {
render(<Link href="mailto:test.com" />);
const link = screen.getByRole("link");
expect(link.getAttribute("href")).toEqual("bWFpbHRvOnRlc3QuY29t");
});
});

vi.mock("../../components/analytics", () => {
Expand Down Expand Up @@ -71,7 +83,5 @@ describe("Link Component Handles Analytics Failures", () => {

// TODO: Add tests
// Check target="_blank" present on newTab
// Check obfuscated label
// Check obfuscated href
// Check children is label if present
// Check fallback to link for label
2 changes: 1 addition & 1 deletion packages/pages-components/src/components/link/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(

// hydration warnings suppressed because they will show when the xYextDebug query param is used
return (
<a {...attributes} {...rest} suppressHydrationWarning={true}>
<a {...rest} {...attributes} suppressHydrationWarning={true}>
{children || link.label || renderedLink}
</a>
);
Expand Down

0 comments on commit 8e102cc

Please sign in to comment.