-
Notifications
You must be signed in to change notification settings - Fork 47
Add branch delete modal to get choice for branch deletion #8592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
aa297d0
add branch delete modal to check which modal to display
pa-lem 0503b88
update actions to use new modal
pa-lem d779c0d
fix import
pa-lem 30ba3a9
betterer
pa-lem 45b1804
Merge branch 'develop' of github.com:opsmill/infrahub into ple-delete…
pa-lem 0181d65
update layers
pa-lem 7ac6489
add const
pa-lem f9572db
update logic to delete from git too
pa-lem 534b8d8
Merge branch 'develop' of github.com:opsmill/infrahub into ple-delete…
pa-lem 4c3d4c2
reset option on close
pa-lem a33608a
fix checks and loading state
pa-lem c740160
add test
pa-lem bce9ad2
update test
pa-lem e2e5e01
remove useeffect
pa-lem 01876b4
add changelog
pa-lem fc85bfb
lint
pa-lem 83cc9b9
lint
pa-lem 400eab3
update types
pa-lem 164f433
lint
pa-lem 648de08
improve action
pa-lem bb8a902
update borders
pa-lem ed5919a
update gql cache
bilalabbad 1695982
update type nme
pa-lem cb6544f
Merge branch 'ple-delete-branch-IFC-2331' of github.com:opsmill/infra…
pa-lem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added a delete branch modal with the option to also delete the branch from Git |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
frontend/app/src/entities/branches/ui/modal-delete-branch.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import { describe, expect, test, vi } from "vitest"; | ||
|
|
||
| import { useObjectsCount } from "@/entities/nodes/object/ui/queries/get-objects-count.query"; | ||
|
|
||
| import { render } from "../../../../tests/components/render"; | ||
| import { DELETE_BRANCH_SCOPE, ModalDeleteBranch } from "./modal-delete-branch"; | ||
|
|
||
| vi.mock("@/entities/nodes/object/ui/queries/get-objects-count.query"); | ||
|
|
||
| describe("ModalDeleteBranch", () => { | ||
| const useObjectsCountMock = vi.mocked(useObjectsCount); | ||
| const defaultProps = { | ||
| isOpen: true, | ||
| onOpenChange: vi.fn(), | ||
| onDelete: vi.fn(), | ||
| isLoading: false, | ||
| }; | ||
|
|
||
| test("shows scope choice when branch has sync_with_git and repositories exist", async () => { | ||
| // GIVEN | ||
| useObjectsCountMock.mockReturnValue({ data: 1, isLoading: false } as ReturnType< | ||
| typeof useObjectsCount | ||
| >); | ||
| const branches = [{ name: "feature-1", sync_with_git: true }]; | ||
|
|
||
| // WHEN | ||
| const component = await render(<ModalDeleteBranch {...defaultProps} branches={branches} />); | ||
|
|
||
| // THEN | ||
| await expect | ||
| .element(component.getByRole("radiogroup", { name: "Deletion scope" })) | ||
| .toBeVisible(); | ||
| }); | ||
|
|
||
| test("does not show scope choice when branch has no sync_with_git", async () => { | ||
| // GIVEN | ||
| useObjectsCountMock.mockReturnValue({ data: 0, isLoading: false } as ReturnType< | ||
| typeof useObjectsCount | ||
| >); | ||
| const branches = [{ name: "feature-1", sync_with_git: false }]; | ||
|
|
||
| // WHEN | ||
| const component = await render(<ModalDeleteBranch {...defaultProps} branches={branches} />); | ||
|
|
||
| // THEN | ||
| expect(component.getByRole("radiogroup", { name: "Deletion scope" }).query()).toBeNull(); | ||
| }); | ||
|
|
||
| test("defaults to LOCAL scope when modal opens", async () => { | ||
| // GIVEN | ||
| useObjectsCountMock.mockReturnValue({ data: 1, isLoading: false } as ReturnType< | ||
| typeof useObjectsCount | ||
| >); | ||
| const branches = [{ name: "feature-1", sync_with_git: true }]; | ||
|
|
||
| // WHEN | ||
| const component = await render(<ModalDeleteBranch {...defaultProps} branches={branches} />); | ||
|
|
||
| // THEN | ||
| const localRadio = component.getByRole("radio", { name: /Local only/i }); | ||
| await expect.element(localRadio).toBeChecked(); | ||
| }); | ||
|
|
||
| test("calls onDelete with LOCAL scope when clicking Delete with default selection", async () => { | ||
| // GIVEN | ||
| useObjectsCountMock.mockReturnValue({ data: 1, isLoading: false } as ReturnType< | ||
| typeof useObjectsCount | ||
| >); | ||
| const onDelete = vi.fn(); | ||
| const branches = [{ name: "feature-1", sync_with_git: true }]; | ||
|
|
||
| // WHEN | ||
| const component = await render( | ||
| <ModalDeleteBranch {...defaultProps} branches={branches} onDelete={onDelete} /> | ||
| ); | ||
| await component.getByTestId("modal-delete-confirm").click(); | ||
|
|
||
| // THEN | ||
| expect(onDelete).toHaveBeenCalledWith(DELETE_BRANCH_SCOPE.LOCAL); | ||
| }); | ||
|
|
||
| test("calls onDelete with LOCAL_AND_REMOTE scope after selecting that option", async () => { | ||
| // GIVEN | ||
| useObjectsCountMock.mockReturnValue({ data: 1, isLoading: false } as ReturnType< | ||
| typeof useObjectsCount | ||
| >); | ||
| const onDelete = vi.fn(); | ||
| const branches = [{ name: "feature-1", sync_with_git: true }]; | ||
|
|
||
| // WHEN | ||
| const component = await render( | ||
| <ModalDeleteBranch {...defaultProps} branches={branches} onDelete={onDelete} /> | ||
| ); | ||
| await component.getByText("Local and remote").click(); | ||
| await component.getByTestId("modal-delete-confirm").click(); | ||
|
|
||
| // THEN | ||
| expect(onDelete).toHaveBeenCalledWith(DELETE_BRANCH_SCOPE.LOCAL_AND_REMOTE); | ||
| }); | ||
|
|
||
| test("shows scope choice for mixed branches and handles both scope selections", async () => { | ||
| // GIVEN | ||
| useObjectsCountMock.mockReturnValue({ data: 1, isLoading: false } as ReturnType< | ||
| typeof useObjectsCount | ||
| >); | ||
| const onDelete = vi.fn(); | ||
| const branches = [ | ||
| { name: "feature-1", sync_with_git: true }, | ||
| { name: "feature-2", sync_with_git: false }, | ||
| ]; | ||
|
|
||
| // WHEN | ||
| const component = await render( | ||
| <ModalDeleteBranch {...defaultProps} branches={branches} onDelete={onDelete} /> | ||
| ); | ||
|
|
||
| // THEN - radiogroup is visible and default is LOCAL | ||
| await expect | ||
| .element(component.getByRole("radiogroup", { name: "Deletion scope" })) | ||
| .toBeVisible(); | ||
| await expect.element(component.getByRole("radio", { name: /Local only/i })).toBeChecked(); | ||
|
|
||
| // Confirm with default LOCAL selection | ||
| await component.getByTestId("modal-delete-confirm").click(); | ||
| expect(onDelete).toHaveBeenCalledWith(DELETE_BRANCH_SCOPE.LOCAL); | ||
|
|
||
| // Select "Local and remote" and confirm | ||
| onDelete.mockClear(); | ||
| await component.getByText("Local and remote").click(); | ||
| await component.getByTestId("modal-delete-confirm").click(); | ||
| expect(onDelete).toHaveBeenCalledWith(DELETE_BRANCH_SCOPE.LOCAL_AND_REMOTE); | ||
| }); | ||
|
|
||
| test("calls onDelete with LOCAL scope directly when showScopeChoice is false", async () => { | ||
| // GIVEN | ||
| useObjectsCountMock.mockReturnValue({ data: 0, isLoading: false } as ReturnType< | ||
| typeof useObjectsCount | ||
| >); | ||
| const onDelete = vi.fn(); | ||
| const branches = [{ name: "feature-1", sync_with_git: false }]; | ||
|
|
||
| // WHEN | ||
| const component = await render( | ||
| <ModalDeleteBranch {...defaultProps} branches={branches} onDelete={onDelete} /> | ||
| ); | ||
| await component.getByTestId("modal-delete-confirm").click(); | ||
|
|
||
| // THEN | ||
| expect(onDelete).toHaveBeenCalledWith(DELETE_BRANCH_SCOPE.LOCAL); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.