Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pages-components): link's href not obfuscated #76

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading