Skip to content

Commit

Permalink
chore: add test click flag row (#34)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant authored Dec 10, 2024
1 parent ee16b92 commit 0954e0e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
35 changes: 35 additions & 0 deletions client/src/routes/authenticatedRoutes/flags/flagRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ vi.mock("../../../api/goffApi.ts", () => ({
updateFeatureFlagStatusById: vi.fn(),
deleteFeatureFlagById: vi.fn(),
}));
const mockedUsedNavigate = vi.fn();

describe("flag row", () => {
const handleDelete = vi.fn();
Expand Down Expand Up @@ -53,6 +54,40 @@ describe("flag row", () => {
version: "0.0.1",
};
});

describe("click flag details", () => {
it("should redirect to the flag details page by clicking on the row", async () => {
vi.mock("react-router-dom", async () => {
const actual = await vi.importActual("react-router-dom");
return {
...actual,
useNavigate: () => mockedUsedNavigate,
};
});

render(
<MemoryRouter>
<Table hoverable>
<TableBody className="divide-y">
<FlagRow
handleDelete={handleDelete}
handleDisable={handleDisable}
flag={defaultFlag}
/>
</TableBody>
</Table>
</MemoryRouter>,
);
expect(screen.getByText(defaultFlag.name ?? "")).toBeVisible();
await userEvent.click(screen.getByText(defaultFlag.name ?? ""), {
delay: 100,
});
expect(mockedUsedNavigate).toHaveBeenCalledWith(
`/flags/${defaultFlag.id}`,
);
});
});

describe("labels", () => {
it("should display a labels (version, variations, type) of the flag", () => {
render(
Expand Down
6 changes: 5 additions & 1 deletion client/src/routes/authenticatedRoutes/flags/flagRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ export function FlagRow({
<TableCell className={"max-w-fit"}>
<div className={"right-1 flex justify-end"}>
<Link to={flagDetailsPageLocation}>
<Button size="sm" className={"mr-5"}>
<Button
size="sm"
className={"mr-5"}
data-testid={"flag-row-info-button"}
>
<Tooltip content={t(`${translationBaseKey}.tooltip.info`)}>
<HiInformationCircle className="h-4 w-4" />
</Tooltip>
Expand Down

0 comments on commit 0954e0e

Please sign in to comment.