diff --git a/app/client/src/pages/Editor/Explorer/Entity/index.tsx b/app/client/src/pages/Editor/Explorer/Entity/index.tsx index 1ec18753f3..9870d7545a 100644 --- a/app/client/src/pages/Editor/Explorer/Entity/index.tsx +++ b/app/client/src/pages/Editor/Explorer/Entity/index.tsx @@ -29,6 +29,7 @@ import { createMessage, EXPLORER_BETA_ENTITY, } from "@appsmith/constants/messages"; +import classNames from "classnames"; export enum EntityClassNames { CONTEXT_MENU = "entity-context-menu", @@ -361,9 +362,12 @@ export const Entity = forwardRef( { // Close button is rendered getByRole("button", { name: "Close pane" }); }); + + it("Prevents edit of main JS object", () => { + const page = PageFactory.build(); + const Main_JS = JSObjectFactory.build({ + id: "js_id", + name: "Main", + pageId: page.pageId, + }); + Main_JS.isMainJSCollection = true; + + const Normal_JS = JSObjectFactory.build({ + id: "js_id2", + name: "Normal", + pageId: page.pageId, + }); + + const state = getIDETestState({ + pages: [page], + js: [Main_JS, Normal_JS], + tabs: { + [EditorEntityTab.QUERIES]: [], + [EditorEntityTab.JS]: ["js_id"], + }, + }); + + const { getByTestId } = render( + + + , + { + url: "/app/applicationSlug/pageSlug-page_id/edit/jsObjects/js_id", + initialState: state, + featureFlags: FeatureFlags, + }, + ); + + // Normal JS object should be editable + const normalJsObjectEntity = getByTestId("t--entity-item-Normal"); + expect(normalJsObjectEntity.classList.contains("editable")).toBe(true); + + // should have `t--context-menu` as a child of the normalJsObjectEntity + expect( + normalJsObjectEntity.querySelector(".t--context-menu"), + ).not.toBeNull(); + + // Main JS object should not be editable + const mainJsObjectEntity = getByTestId("t--entity-item-Main"); + expect(mainJsObjectEntity.classList.contains("editable")).toBe(false); + // should not have `t--context-menu` as a child of the mainJsObjectEntity + expect(mainJsObjectEntity.querySelector(".t--context-menu")).toBeNull(); + }); }); });