PromucFlow_constructor/app/client/test/factories/AppIDEFactoryUtils.ts
Hetu Nandu 92ff6a9c7d
chore: Add tests for useGetPageFocusUrl hook (#32107)
## Description

- Create a new hookWrapper util to enable hook testing with redux state
- Create a util function to create EditorState Focus Info
- Small refactor of `useGetPageFocusUrl` hook
- Adds tests for `useGetPageFocusUrl` hook

Fixes #31871 

## Automation

/ok-to-test tags="@tag.IDE"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> Tests running at:
<https://github.com/appsmithorg/appsmith/actions/runs/8451092610>
> Commit: `a4660177de70be17d94928eef4fbe29a37f1a1d5`
> Workflow: `PR Automation test suite`
> Tags: `@tag.IDE`

<!-- end of auto-generated comment: Cypress test results  -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced a function to streamline the creation of editor focus
information, enhancing navigation within the IDE.
- **Refactor**
- Refactored logic for setting focus page URLs in the IDE, improving the
accuracy and reliability of navigation.
- **Tests**
- Added tests for the `useGetPageFocusUrl` hook, ensuring URL generation
behaves as expected.
- **Chores**
- Updated utility functions for IDE tests, facilitating better test
setup and execution.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-03-27 12:00:31 +00:00

85 lines
2.2 KiB
TypeScript

import store from "store";
import { EditorViewMode } from "@appsmith/entities/IDE/constants";
import type { AppState } from "@appsmith/reducers";
import MockPluginsState from "test/factories/MockPluginsState";
import type { Page } from "@appsmith/constants/ReduxActionConstants";
import type { Action } from "entities/Action";
import type { IDETabs } from "reducers/uiReducers/ideReducer";
import { IDETabsDefaultValue } from "reducers/uiReducers/ideReducer";
import type { JSCollection } from "entities/JSCollection";
import type { FocusHistory } from "reducers/uiReducers/focusHistoryReducer";
interface IDEStateArgs {
ideView?: EditorViewMode;
pages?: Page[];
actions?: Action[];
js?: JSCollection[];
tabs?: IDETabs;
branch?: string;
focusHistory?: FocusHistory;
}
export const getIDETestState = ({
actions = [],
branch,
focusHistory = {},
ideView = EditorViewMode.FullScreen,
js = [],
pages = [],
tabs = IDETabsDefaultValue,
}: IDEStateArgs): AppState => {
const initialState = store.getState();
const pageList = {
pages,
isGeneratingTemplatePage: false,
applicationId: "655716e035e2c9432e4bd94b",
currentPageId: pages[0]?.pageId,
defaultPageId: pages[0]?.pageId,
loading: {},
};
const actionData = actions.map((a) => ({ isLoading: false, config: a }));
const jsData = js.map((a) => ({ isLoading: false, config: a }));
return {
...initialState,
entities: {
...initialState.entities,
plugins: MockPluginsState,
pageList: pageList,
actions: actionData,
jsActions: jsData,
},
ui: {
...initialState.ui,
ide: {
...initialState.ui.ide,
view: ideView,
tabs,
},
focusHistory: {
history: {
...focusHistory,
},
},
editor: {
...initialState.ui.editor,
initialized: true,
},
applications: {
...initialState.ui.applications,
currentApplication: branch
? {
...initialState.ui.applications.currentApplication,
gitApplicationMetadata: {
branchName: branch || "",
},
}
: { ...initialState.ui.applications.currentApplication },
},
},
};
};