Skip to content

Commit

Permalink
update button to function as link
Browse files Browse the repository at this point in the history
  • Loading branch information
Rocio De Santiago authored and Rocio De Santiago committed Nov 27, 2024
1 parent 28d5b38 commit 466a5e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
15 changes: 3 additions & 12 deletions services/ui-src/src/components/report/StatusTable.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { StatusTableElement } from "./StatusTable";
import { MemoryRouter } from "react-router-dom";
import { useStore } from "utils";
Expand All @@ -8,12 +7,6 @@ jest.mock("utils", () => ({
useStore: jest.fn(),
}));

const mockNavigate = jest.fn();
jest.mock("react-router-dom", () => ({
...jest.requireActual("react-router-dom"),
useNavigate: () => mockNavigate,
}));

const report = {
type: "QM",
id: "mock-report-id",
Expand Down Expand Up @@ -64,11 +57,9 @@ describe("StatusTableElement", () => {
</MemoryRouter>
);

const editButton = screen.getAllByRole("button", { name: /Edit/i })[0];
await userEvent.click(editButton);

expect(editButton).toBeVisible();
expect(mockNavigate).toHaveBeenCalled();
const editButton = screen.getByRole("link", { name: /Edit/i });
const editButtonPath = `/report/${report.type}/${report.state}/${report.id}/id-1`;
expect(editButton).toHaveAttribute("href", editButtonPath);
});

test("when the Review PDF button is clicked, navigate to PDF", async () => {
Expand Down
12 changes: 3 additions & 9 deletions services/ui-src/src/components/report/StatusTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link as RouterLink, useNavigate, useParams } from "react-router-dom";
import { Link as RouterLink } from "react-router-dom";
import {
Button,
Image,
Expand All @@ -20,8 +20,6 @@ import { reportBasePath } from "utils/other/routing";

export const StatusTableElement = () => {
const { pageMap, report } = useStore();
const { reportType, state, reportId } = useParams();
const navigate = useNavigate();

if (!pageMap) {
return null;
Expand All @@ -35,11 +33,6 @@ export const StatusTableElement = () => {
return report?.pages[pageIdx] as ParentPageTemplate;
});

const handleEditClick = (sectionId: string) => {
const path = `/report/${reportType}/${state}/${reportId}/${sectionId}`;
navigate(path);
};

// Build Rows
const rows = sections.map((section, index) => {
if (!section) return null;
Expand All @@ -55,9 +48,10 @@ export const StatusTableElement = () => {
</Td>
<Td>
<Button
as={RouterLink}
to={reportBasePath(report!) + `/${section.id}`}
variant="outline"
leftIcon={<Image src={editIconPrimary} />}
onClick={() => handleEditClick(section.id)}
>
Edit
</Button>
Expand Down

0 comments on commit 466a5e3

Please sign in to comment.