Skip to content

Commit 0954e0e

Browse files
chore: add test click flag row (#34)
Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org>
1 parent ee16b92 commit 0954e0e

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

client/src/routes/authenticatedRoutes/flags/flagRow.test.tsx

+35
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ vi.mock("../../../api/goffApi.ts", () => ({
1515
updateFeatureFlagStatusById: vi.fn(),
1616
deleteFeatureFlagById: vi.fn(),
1717
}));
18+
const mockedUsedNavigate = vi.fn();
1819

1920
describe("flag row", () => {
2021
const handleDelete = vi.fn();
@@ -53,6 +54,40 @@ describe("flag row", () => {
5354
version: "0.0.1",
5455
};
5556
});
57+
58+
describe("click flag details", () => {
59+
it("should redirect to the flag details page by clicking on the row", async () => {
60+
vi.mock("react-router-dom", async () => {
61+
const actual = await vi.importActual("react-router-dom");
62+
return {
63+
...actual,
64+
useNavigate: () => mockedUsedNavigate,
65+
};
66+
});
67+
68+
render(
69+
<MemoryRouter>
70+
<Table hoverable>
71+
<TableBody className="divide-y">
72+
<FlagRow
73+
handleDelete={handleDelete}
74+
handleDisable={handleDisable}
75+
flag={defaultFlag}
76+
/>
77+
</TableBody>
78+
</Table>
79+
</MemoryRouter>,
80+
);
81+
expect(screen.getByText(defaultFlag.name ?? "")).toBeVisible();
82+
await userEvent.click(screen.getByText(defaultFlag.name ?? ""), {
83+
delay: 100,
84+
});
85+
expect(mockedUsedNavigate).toHaveBeenCalledWith(
86+
`/flags/${defaultFlag.id}`,
87+
);
88+
});
89+
});
90+
5691
describe("labels", () => {
5792
it("should display a labels (version, variations, type) of the flag", () => {
5893
render(

client/src/routes/authenticatedRoutes/flags/flagRow.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ export function FlagRow({
119119
<TableCell className={"max-w-fit"}>
120120
<div className={"right-1 flex justify-end"}>
121121
<Link to={flagDetailsPageLocation}>
122-
<Button size="sm" className={"mr-5"}>
122+
<Button
123+
size="sm"
124+
className={"mr-5"}
125+
data-testid={"flag-row-info-button"}
126+
>
123127
<Tooltip content={t(`${translationBaseKey}.tooltip.info`)}>
124128
<HiInformationCircle className="h-4 w-4" />
125129
</Tooltip>

0 commit comments

Comments
 (0)