Skip to content
1 change: 1 addition & 0 deletions api_app/serializers/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ class Meta:
"tags",
"comments",
"status",
"tlp",
"pivots_to_execute",
"analyzers_to_execute",
"analyzers_requested",
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/components/common/TLPTag.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new background/text color styling logic isn’t covered by any frontend unit test (there are no existing tests exercising TLPTag). Since this component is reused across multiple pages, add a small Jest test to assert the rendered badge has the expected backgroundColor and text color for at least one light TLP (e.g. CLEAR) and RED.

Copilot uses AI. Check for mistakes.
}}
{...rest}
>
Expand Down
80 changes: 80 additions & 0 deletions frontend/tests/components/common/TLPTag.test.jsx
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);
});
});
1 change: 1 addition & 0 deletions tests/api_app/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def test_retrieve_200(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(content["id"], self.job.id, msg=msg)
self.assertEqual(content["status"], self.job.status, msg=msg)
self.assertEqual(content["tlp"], self.job.tlp, msg=msg)
self.assertEqual(content["investigation_id"], self.investigation1.pk)
self.assertEqual(content["investigation_name"], self.investigation1.name)
self.assertEqual(content["analyzable_id"], self.analyzable.pk)
Expand Down
Loading