Skip to content

Commit d3e4e43

Browse files
committed
test: enhance MenuItem tests with useNavigateToAnotherPage mock
### Changes Made - Added a mock for the `useNavigateToAnotherPage` hook in `MenuItem.test.tsx` to improve test coverage for navigation functionality. - Implemented a mock implementation of the hook to simulate navigation actions based on the application mode, ensuring accurate testing of the `MenuItem` component's behavior in different scenarios. - Updated the test suite to utilize the mocked hook, enhancing the robustness of the component tests.
1 parent 082f414 commit d3e4e43

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

app/client/src/pages/AppViewer/Navigation/components/MenuItem/MenuItem.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ jest.mock("ee/RouteBuilder", () => ({
6565
viewerURL: jest.fn(),
6666
builderURL: jest.fn(),
6767
}));
68+
69+
// Mock the useNavigateToAnotherPage hook
70+
jest.mock("../../hooks/useNavigateToAnotherPage", () => ({
71+
__esModule: true,
72+
default: jest.fn(() => jest.fn()),
73+
}));
74+
6875
const mockPage: Page = {
6976
pageId: "page1_id",
7077
pageName: "Test Page 1",
@@ -131,6 +138,27 @@ describe("MenuItem Component", () => {
131138
pathname: currentPathname,
132139
});
133140

141+
// Mock the useNavigateToAnotherPage hook
142+
const useNavigateToAnotherPageMock =
143+
require("../../hooks/useNavigateToAnotherPage").default;
144+
145+
useNavigateToAnotherPageMock.mockImplementation(() => {
146+
return () => {
147+
const pageURL =
148+
testState.entities.app.mode === APP_MODE.PUBLISHED
149+
? `/viewer/${mockPage.basePageId}`
150+
: `/builder/${mockPage.basePageId}`;
151+
152+
store.dispatch(
153+
navigateToAnotherPage({
154+
pageURL,
155+
query: mockQuery,
156+
state: { invokedBy: NavigationMethod.AppNavigation },
157+
}),
158+
);
159+
};
160+
});
161+
134162
return render(
135163
<Provider store={store}>
136164
<MenuItem

0 commit comments

Comments
 (0)