diff --git a/app/client/src/pages/Editor/IDE/ProtectedBranchIDE.test.tsx b/app/client/src/pages/Editor/IDE/ProtectedCallout.test.tsx similarity index 62% rename from app/client/src/pages/Editor/IDE/ProtectedBranchIDE.test.tsx rename to app/client/src/pages/Editor/IDE/ProtectedCallout.test.tsx index 3ed96a4306..c8f0e698f1 100644 --- a/app/client/src/pages/Editor/IDE/ProtectedBranchIDE.test.tsx +++ b/app/client/src/pages/Editor/IDE/ProtectedCallout.test.tsx @@ -6,8 +6,9 @@ import configureStore from "redux-mock-store"; import IDE from "."; import { BrowserRouter } from "react-router-dom"; import "@testing-library/jest-dom"; +import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants"; -const getMockStore = (override: Record = {}) => { +const getMockStore = (override: Record = {}): any => { const slice = { ui: { applications: { @@ -39,7 +40,16 @@ jest.mock("./RightPane", () => () =>
); jest.mock("./Sidebar", () => () =>
); jest.mock("components/BottomBar", () => () =>
); -describe("Protected view for IDE", () => { +const dispatch = jest.fn(); +jest.mock("react-redux", () => { + const originalModule = jest.requireActual("react-redux"); + return { + ...originalModule, + useDispatch: () => dispatch, + }; +}); + +describe("Protected callout test cases", () => { it("should render the protected view for IDE", () => { const store = getMockStore(); const { getByTestId } = render( @@ -78,4 +88,32 @@ describe("Protected view for IDE", () => { queryByTestId("t--git-protected-branch-callout"), ).not.toBeInTheDocument(); }); + it("should unprotect only the current branch if clicked on unprotect cta", () => { + const store = getMockStore({ + ui: { + applications: { + currentApplication: { + gitApplicationMetadata: { + branchName: "branch-1", + }, + }, + }, + gitSync: { + protectedBranches: ["main", "branch-1", "branch-2"], + }, + }, + }); + const { queryByTestId } = render( + + + + + , + ); + queryByTestId("t--git-protected-unprotect-branch-cta")?.click(); + expect(dispatch).lastCalledWith({ + type: ReduxActionTypes.GIT_UPDATE_PROTECTED_BRANCHES_INIT, + payload: { protectedBranches: ["main", "branch-2"] }, + }); + }); }); diff --git a/app/client/src/pages/Editor/IDE/ProtectedCallout.tsx b/app/client/src/pages/Editor/IDE/ProtectedCallout.tsx index a1330955c2..0b62be854a 100644 --- a/app/client/src/pages/Editor/IDE/ProtectedCallout.tsx +++ b/app/client/src/pages/Editor/IDE/ProtectedCallout.tsx @@ -6,7 +6,11 @@ import { setShowBranchPopupAction, updateGitProtectedBranchesInit, } from "actions/gitSyncActions"; -import { getIsUpdateProtectedBranchesLoading } from "selectors/gitSyncSelectors"; +import { + getCurrentGitBranch, + getIsUpdateProtectedBranchesLoading, + getProtectedBranchesSelector, +} from "selectors/gitSyncSelectors"; import { BRANCH_PROTECTION_CALLOUT_CREATE_BRANCH, BRANCH_PROTECTION_CALLOUT_MSG, @@ -23,15 +27,20 @@ const StyledCallout = styled(Callout)` function ProtectedCallout() { const dispatch = useDispatch(); const isLoading = useSelector(getIsUpdateProtectedBranchesLoading); + const currentBranch = useSelector(getCurrentGitBranch); + const protectedBranches = useSelector(getProtectedBranchesSelector); const handleClickOnNewBranch = () => { dispatch(setShowBranchPopupAction(true)); }; const handleClickOnUnprotect = () => { + const remainingBranches = protectedBranches.filter( + (protectedBranch) => protectedBranch !== currentBranch, + ); dispatch( updateGitProtectedBranchesInit({ - protectedBranches: [], + protectedBranches: remainingBranches, }), ); }; @@ -44,11 +53,13 @@ function ProtectedCallout() { links={[ { key: "create-branch", + "data-testid": "t--git-protected-create-branch-cta", children: createMessage(BRANCH_PROTECTION_CALLOUT_CREATE_BRANCH), onClick: handleClickOnNewBranch, }, { key: "unprotect", + "data-testid": "t--git-protected-unprotect-branch-cta", children: isLoading ? createMessage(BRANCH_PROTECTION_CALLOUT_UNPROTECT_LOADING) : createMessage(BRANCH_PROTECTION_CALLOUT_UNPROTECT),