-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVPROD-9282: Add button to delete GitHub app credentials (#281)
- Loading branch information
Showing
15 changed files
with
295 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import styled from "@emotion/styled"; | ||
import Modal from "@leafygreen-ui/confirmation-modal"; | ||
import Modal, { Variant } from "@leafygreen-ui/confirmation-modal"; | ||
import { zIndex } from "constants/tokens"; | ||
|
||
export const ConfirmationModal = styled(Modal)` | ||
const ConfirmationModal = styled(Modal)` | ||
z-index: ${zIndex.modal}; | ||
`; | ||
export { ConfirmationModal, Variant }; |
This file contains 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
5 changes: 5 additions & 0 deletions
5
apps/spruce/src/gql/mutations/delete-github-app-credentials.graphql
This file contains 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,5 @@ | ||
mutation DeleteGithubAppCredentials($projectId: String!) { | ||
deleteGithubAppCredentials(opts: { projectId: $projectId }) { | ||
oldAppId | ||
} | ||
} |
This file contains 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 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 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
42 changes: 1 addition & 41 deletions
42
apps/spruce/src/pages/projectSettings/tabs/GithubAppSettingsTab/FieldTemplates.tsx
This file contains 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
95 changes: 95 additions & 0 deletions
95
...ruce/src/pages/projectSettings/tabs/GithubAppSettingsTab/Fields/GithubAppActions.test.tsx
This file contains 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,95 @@ | ||
import { MockedProvider } from "@apollo/client/testing"; | ||
import { FieldProps } from "@rjsf/core"; | ||
import { RenderFakeToastContext } from "context/toast/__mocks__"; | ||
import { | ||
DeleteGithubAppCredentialsMutation, | ||
DeleteGithubAppCredentialsMutationVariables, | ||
} from "gql/generated/types"; | ||
import { DELETE_GITHUB_APP_CREDENTIALS } from "gql/mutations"; | ||
import { renderWithRouterMatch as render, screen, userEvent } from "test_utils"; | ||
import { ApolloMock } from "types/gql"; | ||
import { GithubAppActions } from "."; | ||
|
||
const Field = ({ isAppDefined }: { isAppDefined: boolean }) => ( | ||
<MockedProvider mocks={[deleteAppCredentialsMock]}> | ||
<GithubAppActions | ||
{...({} as unknown as FieldProps)} | ||
uiSchema={{ | ||
options: { | ||
projectId: "evergreen", | ||
isAppDefined, | ||
}, | ||
}} | ||
/> | ||
</MockedProvider> | ||
); | ||
|
||
describe("githubAppActions", () => { | ||
describe("app is not defined", () => { | ||
it("renders the banner and not the button", () => { | ||
const { Component } = RenderFakeToastContext( | ||
<Field isAppDefined={false} />, | ||
); | ||
render(<Component />); | ||
expect( | ||
screen.getByDataCy("github-app-credentials-banner"), | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.queryByDataCy("delete-app-credentials-button"), | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("app is defined", () => { | ||
it("renders the button and not the banner", () => { | ||
const { Component } = RenderFakeToastContext(<Field isAppDefined />); | ||
render(<Component />); | ||
expect( | ||
screen.getByDataCy("delete-app-credentials-button"), | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.queryByDataCy("github-app-credentials-banner"), | ||
).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("can delete the credentials via the modal", async () => { | ||
const user = userEvent.setup(); | ||
|
||
const { Component, dispatchToast } = RenderFakeToastContext( | ||
<Field isAppDefined />, | ||
); | ||
render(<Component />); | ||
await user.click(screen.getByDataCy("delete-app-credentials-button")); | ||
expect( | ||
screen.getByDataCy("delete-github-credentials-modal"), | ||
).toBeInTheDocument(); | ||
const deleteButton = screen.getByRole("button", { | ||
name: "Delete", | ||
}); | ||
expect(deleteButton).toBeEnabled(); | ||
await user.click(deleteButton); | ||
expect(dispatchToast.success).toHaveBeenCalledWith( | ||
"GitHub app credentials were successfully deleted.", | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
const deleteAppCredentialsMock: ApolloMock< | ||
DeleteGithubAppCredentialsMutation, | ||
DeleteGithubAppCredentialsMutationVariables | ||
> = { | ||
request: { | ||
query: DELETE_GITHUB_APP_CREDENTIALS, | ||
variables: { | ||
projectId: "evergreen", | ||
}, | ||
}, | ||
result: { | ||
data: { | ||
deleteGithubAppCredentials: { | ||
oldAppId: 12344, | ||
}, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.