-
-
Notifications
You must be signed in to change notification settings - Fork 579
fix: add background color to TLP badges and include TLP in job API. C… #3284
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
d5ee7a8
bacebc7
7927e3b
93c1928
2cc5161
d03ad72
ce70068
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,11 +5,21 @@ import { TLPColors } from "../../constants/colorConst"; | |
| import { TLPDescriptions } from "../../constants/miscConst"; | ||
| import { TlpChoices } from "../../constants/advancedSettingsConst"; | ||
|
|
||
| let idCounter = 0; | ||
|
|
||
| export function TLPTag(props) { | ||
| const { value, ...rest } = props; | ||
| const badgeId = `tlptag-badge__${value}`; | ||
| const uniqueId = React.useRef(idCounter).current; | ||
| idCounter += 1; | ||
| const badgeId = `tlptag-badge__${value}__${uniqueId}`; | ||
| const color = TLPColors?.[value] || "#dfe1e2"; | ||
| const tooltipText = TLPDescriptions?.[value] || "invalid"; | ||
| const textColorMap = { | ||
| CLEAR: "#000000", | ||
| GREEN: "#000000", | ||
| AMBER: "#000000", | ||
| }; | ||
| const textColor = textColorMap[value] || "#FFFFFF"; | ||
|
|
||
| return value ? ( | ||
| <Badge | ||
|
|
@@ -18,7 +28,9 @@ export function TLPTag(props) { | |
| style={{ | ||
| borderRadius: 5, | ||
| userSelect: "none", | ||
| backgroundColor: color, | ||
| border: `1px solid ${color}`, | ||
| color: textColor, | ||
|
Comment on lines
17
to
33
|
||
| }} | ||
| {...rest} | ||
| > | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import React from "react"; | ||
| import "@testing-library/jest-dom"; | ||
| import { render } from "@testing-library/react"; | ||
| import { TLPTag } from "../../../src/components/common/TLPTag"; | ||
| import { TLPColors } from "../../../src/constants/colorConst"; | ||
|
|
||
| describe("TLPTag component", () => { | ||
| test("CLEAR TLP renders with correct background and text color", () => { | ||
| const { container } = render(<TLPTag value="CLEAR" />); | ||
|
|
||
| const badge = container.querySelector('[id^="tlptag-badge__CLEAR"]'); | ||
| expect(badge).toBeInTheDocument(); | ||
| expect(badge).toHaveTextContent("CLEAR"); | ||
|
|
||
| // CLEAR should have white background and black text | ||
| expect(badge).toHaveStyle({ | ||
| backgroundColor: TLPColors.CLEAR, | ||
| color: "#000000", | ||
| }); | ||
| }); | ||
|
|
||
| test("RED TLP renders with correct background and text color", () => { | ||
| const { container } = render(<TLPTag value="RED" />); | ||
|
|
||
| const badge = container.querySelector('[id^="tlptag-badge__RED"]'); | ||
| expect(badge).toBeInTheDocument(); | ||
| expect(badge).toHaveTextContent("RED"); | ||
|
|
||
| // RED should have red background and white text | ||
| expect(badge).toHaveStyle({ | ||
| backgroundColor: TLPColors.RED, | ||
| color: "#FFFFFF", | ||
| }); | ||
| }); | ||
|
|
||
| test("GREEN TLP renders with correct background and text color", () => { | ||
| const { container } = render(<TLPTag value="GREEN" />); | ||
|
|
||
| const badge = container.querySelector('[id^="tlptag-badge__GREEN"]'); | ||
| expect(badge).toBeInTheDocument(); | ||
| expect(badge).toHaveTextContent("GREEN"); | ||
|
|
||
| // GREEN should have green background and black text | ||
| expect(badge).toHaveStyle({ | ||
| backgroundColor: TLPColors.GREEN, | ||
| color: "#000000", | ||
| }); | ||
| }); | ||
|
|
||
| test("AMBER TLP renders with correct background and text color", () => { | ||
| const { container } = render(<TLPTag value="AMBER" />); | ||
|
|
||
| const badge = container.querySelector('[id^="tlptag-badge__AMBER"]'); | ||
| expect(badge).toBeInTheDocument(); | ||
| expect(badge).toHaveTextContent("AMBER"); | ||
|
|
||
| // AMBER should have amber background and black text | ||
| expect(badge).toHaveStyle({ | ||
| backgroundColor: TLPColors.AMBER, | ||
| color: "#000000", | ||
| }); | ||
| }); | ||
|
|
||
| test("Multiple TLPTag instances with same value have unique IDs", () => { | ||
| const { container } = render( | ||
| <> | ||
| <TLPTag value="RED" /> | ||
| <TLPTag value="RED" /> | ||
| </>, | ||
| ); | ||
|
|
||
| const badges = container.querySelectorAll('[id^="tlptag-badge__RED"]'); | ||
| expect(badges).toHaveLength(2); | ||
|
|
||
| // Ensure each badge has a unique ID | ||
| const id1 = badges[0].getAttribute("id"); | ||
| const id2 = badges[1].getAttribute("id"); | ||
| expect(id1).not.toEqual(id2); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.