-
Notifications
You must be signed in to change notification settings - Fork 2
feat: expose text color fields #1326
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
Changes from all commits
248f082
f5ecdd9
0fa5082
21222f2
b0154a6
5491a3b
205aca6
11d3b98
82cb7e9
95635ef
59812b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import React from "react"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { CTA, CTAProps } from "./cta.tsx"; | ||
|
|
||
| vi.mock("../../hooks/useDocument.tsx", () => ({ | ||
| useDocument: () => ({}), | ||
| })); | ||
|
|
||
| vi.mock("../../hooks/useBackground.tsx", () => ({ | ||
| useBackground: () => ({ | ||
| selectedColor: "white", | ||
| contrastingColor: "black", | ||
| isDarkColor: false, | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("@yext/pages-components", () => ({ | ||
| getDirections: () => "#", | ||
| Link: ({ | ||
| children, | ||
| cta: _cta, | ||
| eventName: _eventName, | ||
| ...props | ||
| }: { | ||
| children: React.ReactNode; | ||
| cta: unknown; | ||
| eventName?: string; | ||
| } & React.AnchorHTMLAttributes<HTMLAnchorElement>) => | ||
| React.createElement("a", { href: "#", ...props }, children), | ||
| })); | ||
|
|
||
| const renderCta = (props: Partial<CTAProps> = {}): void => { | ||
| render( | ||
| React.createElement(CTA, { | ||
| label: "Call to action", | ||
| link: "#", | ||
| normalizeLink: false, | ||
| variant: "primary", | ||
| ...props, | ||
| }) | ||
| ); | ||
| }; | ||
|
|
||
| describe("CTA text color", () => { | ||
| it("uses a palette color for primary link text and icons", () => { | ||
| renderCta({ | ||
| textColor: { | ||
| selectedColor: "palette-secondary", | ||
| contrastingColor: "palette-secondary-contrast", | ||
| }, | ||
| }); | ||
|
|
||
| const link = screen.getByRole("link"); | ||
| expect(link.style.color).toBe("var(--colors-palette-secondary)"); | ||
| expect(link.querySelector("svg")?.style.color).toBe(""); | ||
| }); | ||
|
|
||
| it("uses a custom color for a primary button", () => { | ||
| renderCta({ | ||
| actionType: "button", | ||
| textColor: { selectedColor: "[#00E5FF]", contrastingColor: "black" }, | ||
| }); | ||
|
|
||
| expect(screen.getByRole("button").style.color).toBe("rgb(0, 229, 255)"); | ||
| }); | ||
|
|
||
| it("uses the fill contrast color when text color is Default", () => { | ||
| renderCta({ | ||
| color: { | ||
| selectedColor: "palette-primary", | ||
| contrastingColor: "palette-primary-contrast", | ||
| }, | ||
| }); | ||
|
|
||
| expect(screen.getByRole("link").style.color).toBe( | ||
| "var(--colors-palette-primary-contrast)" | ||
| ); | ||
| }); | ||
|
|
||
| it("uses the selected text color for a disabled primary CTA", () => { | ||
| renderCta({ | ||
| disabled: true, | ||
| textColor: { selectedColor: "black", contrastingColor: "white" }, | ||
| }); | ||
|
|
||
| expect(screen.getByRole("button").style.color).toBe("black"); | ||
| }); | ||
|
|
||
| it("ignores text color for non-primary CTAs", () => { | ||
| renderCta({ | ||
| variant: "secondary", | ||
| color: { | ||
| selectedColor: "palette-primary", | ||
| contrastingColor: "palette-primary-contrast", | ||
| }, | ||
| textColor: { | ||
| selectedColor: "palette-secondary", | ||
| contrastingColor: "palette-secondary-contrast", | ||
| }, | ||
| }); | ||
|
|
||
| expect(screen.getByRole("link").style.color).toBe( | ||
| "var(--colors-palette-primary)" | ||
| ); | ||
| }); | ||
|
|
||
| it("lets an external-link icon inherit the primary text color", () => { | ||
| renderCta({ | ||
| openInNewTab: true, | ||
| textColor: { selectedColor: "white", contrastingColor: "black" }, | ||
| }); | ||
|
|
||
| const link = screen.getByRole("link"); | ||
| expect(link.style.color).toBe("white"); | ||
| expect(link.querySelectorAll("svg")).toHaveLength(2); | ||
| expect( | ||
| Array.from(link.querySelectorAll("svg")).every( | ||
| (icon) => icon.style.color === "" | ||
| ) | ||
| ).toBe(true); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.