Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import { useNavigate } from "react-router";
import type { JSX } from "react";
import { colors } from "@wso2/oxygen-ui";
import { CalendarDays } from "@wso2/oxygen-ui-icons-react";
import RequestCard from "@components/support/request-cards/RequestCard";
import { CHANGE_REQUEST_BULLET_ITEMS } from "@constants/supportConstants";

/**
* Change Requests card for the Support page.
* Renders overview and CTA for change request management.
*
* @returns {JSX.Element} The Change Request card.
*/
export default function ChangeRequestCard(): JSX.Element {
const navigate = useNavigate();

return (
<RequestCard
title="Change Requests"
subtitle="Track infrastructure changes"
icon={CalendarDays}
paletteKey="secondary"
accentColor={colors.purple[600]}
infoBoxTitle="What are Change Requests?"
infoBoxDescription="Structured workflow for planned infrastructure changes:"
bulletItems={CHANGE_REQUEST_BULLET_ITEMS}
secondaryButtonLabel="View All Change Requests"
onSecondaryClick={() => navigate("../dashboard")}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ export default function RequestCard({
main?: string;
};

const iconBgColor = alpha(palette.light ?? palette.main ?? "secondary", 0.1);
const infoBoxBgColor = alpha(palette.light ?? palette.main ?? "primary", 0.1);
const iconBgColor = alpha(
palette.light ?? palette.main ?? theme.palette.grey[300],
0.1,
);
const infoBoxBgColor = alpha(
palette.light ?? palette.main ?? theme.palette.grey[300],
0.1,
);

return (
<Paper
Expand Down Expand Up @@ -125,6 +131,7 @@ export default function RequestCard({
display: "flex",
flexDirection: "column",
gap: 1,
listStyle: "n "
}}
>
{bulletItems.map((item) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { useNavigate } from "react-router";
import type { JSX } from "react";
import { colors } from "@wso2/oxygen-ui";
import { Server } from "@wso2/oxygen-ui-icons-react";
import SupportRequestCard from "@components/support/request-cards/RequestCard";

import RequestCard from "@components/support/request-cards/RequestCard";
import { SERVICE_REQUEST_BULLET_ITEMS } from "@constants/supportConstants";

/**
Expand All @@ -32,7 +31,7 @@ export default function ServiceRequestCard(): JSX.Element {
const navigate = useNavigate();

return (
<SupportRequestCard
<RequestCard
title="Service Requests"
subtitle="Manage deployment operations"
icon={Server}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { MemoryRouter } from "react-router";
import ChangeRequestCard from "@components/support/request-cards/ChangeRequestCard";
import { CHANGE_REQUEST_BULLET_ITEMS } from "@constants/supportConstants";

// Mock the child component to isolate the test
vi.mock("@components/support/request-cards/RequestCard", () => ({
default: ({
title,
subtitle,
bulletItems,
}: {
title: string;
subtitle: string;
bulletItems: string[];
}) => (
<div data-testid="mock-request-card">
<span data-testid="card-title">{title}</span>
<span data-testid="card-subtitle">{subtitle}</span>
<ul>
{bulletItems.map((item) => (
<li key={item} data-testid="card-item">
{item}
</li>
))}
</ul>
</div>
),
}));

describe("ChangeRequestCard", () => {
it("should render with correct props", () => {
render(
<MemoryRouter>
<ChangeRequestCard />
</MemoryRouter>,
);

expect(screen.getByTestId("mock-request-card")).toBeInTheDocument();
expect(screen.getByTestId("card-title")).toHaveTextContent(
"Change Requests",
);
expect(screen.getByTestId("card-subtitle")).toHaveTextContent(
"Track infrastructure changes",
);

const items = screen.getAllByTestId("card-item");
expect(items).toHaveLength(CHANGE_REQUEST_BULLET_ITEMS.length);
expect(items[0]).toHaveTextContent(CHANGE_REQUEST_BULLET_ITEMS[0]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright (c) 2026 WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import { render, screen, fireEvent } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import RequestCard from "@components/support/request-cards/RequestCard";

const MockIcon = () => <span data-testid="mock-icon">Icon</span>;

describe("RequestCard", () => {
it("should render title, subtitle, info box and buttons", () => {
render(
<RequestCard
title="Test Card"
subtitle="Test subtitle"
icon={MockIcon}
paletteKey="info"
accentColor="#1976D2"
infoBoxTitle="What is this?"
infoBoxDescription="A test description."
bulletItems={["Item one", "Item two"]}
secondaryButtonLabel="View All"
onSecondaryClick={vi.fn()}
/>,
);
Comment thread
dileepapeiris marked this conversation as resolved.
Resolved

expect(screen.getByText("Test Card")).toBeInTheDocument();
expect(screen.getByText("Test subtitle")).toBeInTheDocument();
expect(screen.getByText("What is this?")).toBeInTheDocument();
expect(screen.getByText("A test description.")).toBeInTheDocument();
expect(screen.getByText("Item one")).toBeInTheDocument();
expect(screen.getByText("Item two")).toBeInTheDocument();
expect(
screen.getByRole("button", { name: /view all/i }),
).toBeInTheDocument();
expect(screen.getByTestId("mock-icon")).toBeInTheDocument();
});

it("should render primary button when provided", () => {
render(
<RequestCard
title="Test"
subtitle="Sub"
icon={MockIcon}
paletteKey="info"
accentColor="#1976D2"
infoBoxTitle="Title"
infoBoxDescription="Desc"
bulletItems={[]}
secondaryButtonLabel="Secondary"
onSecondaryClick={vi.fn()}
primaryButton={{
label: "Create New",
onClick: vi.fn(),
icon: MockIcon,
}}
/>,
);

expect(
screen.getByRole("button", { name: /create new/i }),
).toBeInTheDocument();
});

it("should call onSecondaryClick when secondary button is clicked", () => {
const onSecondaryClick = vi.fn();
render(
<RequestCard
title="Test"
subtitle="Sub"
icon={MockIcon}
paletteKey="info"
accentColor="#1976D2"
infoBoxTitle="Title"
infoBoxDescription="Desc"
bulletItems={[]}
secondaryButtonLabel="View All"
onSecondaryClick={onSecondaryClick}
/>,
);

fireEvent.click(screen.getByRole("button", { name: /view all/i }));
expect(onSecondaryClick).toHaveBeenCalledTimes(1);
});

it("should call primaryButton.onClick when primary button is clicked", () => {
const onPrimaryClick = vi.fn();
render(
<RequestCard
title="Test"
subtitle="Sub"
icon={MockIcon}
paletteKey="info"
accentColor="#1976D2"
infoBoxTitle="Title"
infoBoxDescription="Desc"
bulletItems={[]}
secondaryButtonLabel="Secondary"
onSecondaryClick={vi.fn()}
primaryButton={{
label: "Create",
onClick: onPrimaryClick,
icon: MockIcon,
}}
/>,
);

fireEvent.click(screen.getByRole("button", { name: /create/i }));
expect(onPrimaryClick).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ vi.mock("@wso2/oxygen-ui", () => ({
blue: { 500: "#2196F3", 700: "#1D4ED8" },
green: { 500: "#4CAF50" },
purple: { 500: "#9C27B0", 400: "#A78BFA" },
orange: { 600: "#FB8C00" },
},
alpha: (color: string, opacity: number) => `${color}-${opacity}`,
Divider: () => <hr />,
Comment thread
dileepapeiris marked this conversation as resolved.
Resolved
Button: ({ children }: any) => <button>{children}</button>,
Card: ({ children, sx }: any) => <div style={sx}>{children}</div>,
Expand Down Expand Up @@ -100,11 +102,22 @@ vi.mock("@wso2/oxygen-ui", () => ({
</div>
),
Paper: ({ children }: any) => <div data-testid="paper">{children}</div>,
useTheme: () => ({
palette: {
primary: { main: "#1976D2", light: "#42A5F5" },
secondary: { main: "#9C27B0", light: "#BA68C8" },
info: { main: "#0288D1", light: "#03A9F4" },
warning: { main: "#ED6C02", light: "#FF9800" },
success: { main: "#2E7D32", light: "#4CAF50" },
error: { main: "#D32F2F", light: "#EF5350" },
},
}),
}));

// Mock icons
vi.mock("@wso2/oxygen-ui-icons-react", () => ({
Bot: () => <svg data-testid="icon-bot" />,
ArrowRight: () => <svg data-testid="icon-arrow-right" />,
CircleAlert: () => <svg data-testid="icon-alert" />,
CircleCheck: () => <svg data-testid="icon-check" />,
Clock: () => <svg data-testid="icon-clock" />,
Expand All @@ -126,6 +139,27 @@ vi.mock("@api/useGetProjectSupportStats", () => ({
useGetProjectSupportStats: (id: string) => mockUseGetProjectSupportStats(id),
}));

// Mock useGetProjectCases
vi.mock("@api/useGetProjectCases", () => ({
default: () => ({
data: { cases: [] },
isLoading: false,
Comment thread
dileepapeiris marked this conversation as resolved.
Resolved
}),
}));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

// Mock Request Cards
vi.mock("@components/support/request-cards/ServiceRequestCard", () => ({
default: () => (
<div data-testid="service-request-card">Service Request Card</div>
),
}));

vi.mock("@components/support/request-cards/ChangeRequestCard", () => ({
default: () => (
<div data-testid="change-request-card">Change Request Card</div>
),
}));

beforeEach(() => {
vi.clearAllMocks();
});
Expand All @@ -145,7 +179,7 @@ describe("SupportPage", () => {

const skeletons = screen.getAllByTestId("skeleton");
expect(skeletons).toHaveLength(4);
expect(screen.getByTestId("icon-file-text")).toBeInTheDocument();
expect(screen.getAllByTestId("icon-file-text")).toHaveLength(2);
expect(screen.getAllByTestId("icon-bot")).toHaveLength(2);
expect(mockLogger.debug).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -224,6 +258,28 @@ describe("SupportPage", () => {
screen.getByText("Need help with something new?"),
).toBeInTheDocument();
expect(screen.getByText("Start New Chat")).toBeInTheDocument();
expect(screen.getByText("Start New Chat")).toBeInTheDocument();
Comment thread
dileepapeiris marked this conversation as resolved.
Resolved
Comment thread
dileepapeiris marked this conversation as resolved.
Resolved
expect(screen.getAllByTestId("icon-bot")).toHaveLength(2);
});

it("should render the Service and Change Request cards", () => {
mockUseGetProjectSupportStats.mockReturnValue({
isLoading: false,
data: {
totalCases: 10,
activeChats: 5,
sessionChats: 15,
resolvedChats: 20,
},
});

render(
<MemoryRouter>
<SupportPage />
</MemoryRouter>,
);

expect(screen.getByTestId("service-request-card")).toBeInTheDocument();
expect(screen.getByTestId("change-request-card")).toBeInTheDocument();
});
});