PromucFlow_constructor/app/client/src/sagas/getNextEntityAfterRemove.test.ts

58 lines
1.6 KiB
TypeScript
Raw Normal View History

import { EditorState, type EntityItem } from "ee/entities/IDE/constants";
feat: revamped logic for tabs removal and action/JS deletion (#32690) ## Description This PR has changed the logic of next item selection after deleting an item or removing a tab. The new logic is 1. If there is no more tabs left after removal of current item, navigate to first item from all items list 2. If all items list is empty, navigate to add 3. If the removed tab is not currently selected, no redirection required just close the tab 4. If removed tab is in 0th position, redirect to current tab + 1 5. if removed tab is not in 0th position, redirect to tab - 1 Fixes #32634 ## Automation /ok-to-test tags="@tag.Sanity, @tag.IDE" ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!CAUTION] > 🔴 🔴 🔴 Some tests have failed. > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/8748435770> > Commit: e3e9b51cc9a708fadf4d1b9f0e426b63e9f3c10a > Cypress dashboard: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8748435770&attempt=2&selectiontype=test&testsstatus=failed&specsstatus=fail" target="_blank"> Click here!</a> > The following are new failures, please fix them before merging the PR: <ol> > <li>cypress/e2e/Regression/ClientSide/ExplorerTests/Hide_Page_spec.js > <li>cypress/e2e/Regression/ClientSide/ExplorerTests/Page_Load_Spec.js </ol> > To know the list of identified flaky tests - <a href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master" target="_blank">Refer here</a> <!-- end of auto-generated comment: Cypress test results --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved the closing functionality for JavaScript and query action tabs in the IDE, enhancing user experience with smoother tab management. - **Refactor** - Aligned sagas and reducers with new action types for improved handling of tab closures and entity redirects within the IDE. - **Tests** - Updated test cases to reflect changes in IDE saga functions and logic, ensuring reliability and consistency in behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-04-19 06:49:24 +00:00
import { PluginType } from "entities/Action";
import * as FocusEntityObj from "navigation/FocusEntity";
import { RedirectAction, getNextEntityAfterRemove } from "./IDESaga";
import { FocusEntity } from "navigation/FocusEntity";
describe("getNextEntityAfterRemove function", () => {
const items: EntityItem[] = [
{
title: "API 1",
type: PluginType.API,
key: "1",
group: "Users",
},
{
title: "Google sheet 1",
type: PluginType.SAAS,
key: "2",
group: "AbGsheet",
},
];
jest
.spyOn(FocusEntityObj, "identifyEntityFromPath")
.mockImplementation(() => ({
entity: FocusEntity.QUERY,
id: "2",
appState: EditorState.EDITOR,
params: {},
}));
it("1. Removed item is not the current item then no redirect", () => {
expect(getNextEntityAfterRemove("5", items)).toEqual({
action: RedirectAction.NA,
});
});
it("2. Redirect to add, if nothing left after deletion", () => {
expect(getNextEntityAfterRemove("2", [])).toEqual({
action: RedirectAction.LIST,
});
});
it("3. Redirect to the previous item if current tab is not the first one", () => {
expect(getNextEntityAfterRemove("2", items)).toEqual({
action: RedirectAction.ITEM,
payload: items[0],
});
});
it("4. Redirect to the next item if current tab is the first one", () => {
expect(getNextEntityAfterRemove("2", items.reverse())).toEqual({
action: RedirectAction.ITEM,
payload: items[1],
});
});
});