PromucFlow_constructor/app/client/test/factories/AppIDEFactoryUtils.ts
Hetu Nandu 0a58544fc5
fix: The case of the missing tabs (#33066)
## Description

Solves scenarios where open tabs data was lost on page switches

Fixes #33032
Change the data structure of the tabs to now keep account different tabs
for each page instead of just one page at a time. Also removed tabs
state for focus retention.

Fixes #33045
Handles removing and navigating post move of JS and Queries to avoid
being in a bad state


## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9000257489>
> Commit: b39c8d7cca16ea739457f277290c29317317cef3
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9000257489&attempt=2"
target="_blank">Click here!</a>

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




















## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
2024-05-08 22:57:27 +05:30

99 lines
2.6 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,
ParentEntityIDETabs,
} from "reducers/uiReducers/ideReducer";
import { IDETabsDefaultValue } from "reducers/uiReducers/ideReducer";
import type { JSCollection } from "entities/JSCollection";
import type { FocusHistory } from "reducers/uiReducers/focusHistoryReducer";
import type { Datasource } from "entities/Datasource";
interface IDEStateArgs {
ideView?: EditorViewMode;
pages?: Page[];
actions?: Action[];
js?: JSCollection[];
tabs?: IDETabs;
branch?: string;
focusHistory?: FocusHistory;
datasources?: Datasource[];
}
export const getIDETestState = ({
actions = [],
branch,
datasources = [],
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: {},
};
let ideTabs: ParentEntityIDETabs = {};
if (pageList.currentPageId) {
ideTabs = { [pageList.currentPageId]: tabs };
}
const actionData = actions.map((a) => ({ isLoading: false, config: a }));
const jsData = js.map((a) => ({ isLoading: false, config: a }));
return {
...initialState,
entities: {
...initialState.entities,
datasources: {
...initialState.entities.datasources,
list: datasources,
},
plugins: MockPluginsState,
pageList: pageList,
actions: actionData,
jsActions: jsData,
},
ui: {
...initialState.ui,
ide: {
...initialState.ui.ide,
view: ideView,
tabs: ideTabs,
},
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 },
},
},
};
};