This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
224 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
describe("Name change modal", () => { | ||
beforeEach(() => { | ||
cy.visit("version/5f74d99ab2373627c047c5e5"); | ||
}); | ||
|
||
it("Use the name change modal to change the name of a patch", () => { | ||
const originalName = "main: EVG-7823 add a commit queue message (#4048)"; | ||
cy.contains(originalName); | ||
cy.dataCy("name-change-modal-trigger").click(); | ||
const newName = "a different name"; | ||
cy.get("textarea").clear().type(newName); | ||
cy.contains("Confirm").click(); | ||
cy.get("textarea").should("not.exist"); | ||
cy.contains(newName); | ||
cy.validateToast("success", "Patch name was successfully updated.", true); | ||
// revert name change | ||
cy.dataCy("name-change-modal-trigger").click(); | ||
cy.get("textarea").clear().type(originalName); | ||
cy.contains("Confirm").click(); | ||
cy.get("textarea").should("not.exist"); | ||
cy.validateToast("success", "Patch name was successfully updated.", true); | ||
cy.contains(originalName); | ||
}); | ||
|
||
it("The confirm button is disabled when the text area value is empty or greater than 300 characters", () => { | ||
cy.dataCy("name-change-modal-trigger").click(); | ||
cy.get("textarea").clear(); | ||
cy.contains("button", "Confirm").should("be.disabled"); | ||
cy.get("textarea").type("lol"); | ||
cy.contains("button", "Confirm").should("not.be.disabled"); | ||
const over300Chars = | ||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | ||
cy.get("textarea").type(over300Chars); | ||
cy.contains("button", "Confirm").should("be.disabled"); | ||
cy.contains("should NOT be longer than 300 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
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
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,10 @@ | ||
#import "../fragments/basePatch.graphql" | ||
|
||
mutation UpdatePatchDescription($patchId: String!, $description: String!) { | ||
schedulePatch( | ||
patchId: $patchId | ||
configure: { variantsTasks: [], description: $description } | ||
) { | ||
...BasePatch | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { SpruceFormProps } from "components/SpruceForm/types"; | ||
|
||
export const getFormSchema = ( | ||
name: string | ||
): { | ||
schema: SpruceFormProps["schema"]; | ||
uiSchema: SpruceFormProps["uiSchema"]; | ||
} => ({ | ||
schema: { | ||
type: "object" as "object", | ||
properties: { | ||
newPatchName: { | ||
title: "New Patch Name", | ||
type: "string" as "string", | ||
default: name, | ||
maxLength: 300, | ||
minLength: 1, | ||
}, | ||
}, | ||
}, | ||
uiSchema: { | ||
newPatchName: { | ||
"ui:widget": "textarea", | ||
"ui:focusOnMount": true, | ||
}, | ||
}, | ||
}); |
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,86 @@ | ||
import { useState } from "react"; | ||
import { useMutation } from "@apollo/client"; | ||
import styled from "@emotion/styled"; | ||
import IconButton from "@leafygreen-ui/icon-button"; | ||
import { ConfirmationModal } from "components/ConfirmationModal"; | ||
import Icon from "components/Icon"; | ||
import { SpruceForm } from "components/SpruceForm"; | ||
import { size } from "constants/tokens"; | ||
import { useToastContext } from "context/toast"; | ||
import { | ||
UpdatePatchDescriptionMutation, | ||
UpdatePatchDescriptionMutationVariables, | ||
} from "gql/generated/types"; | ||
import { UPDATE_PATCH_DESCRIPTION } from "gql/mutations"; | ||
import { getFormSchema } from "./getFormSchema"; | ||
|
||
interface NameChangeModalProps { | ||
originalPatchName: string; | ||
patchId: string; | ||
} | ||
export const NameChangeModal: React.VFC<NameChangeModalProps> = ({ | ||
originalPatchName, | ||
patchId, | ||
}) => { | ||
const [formState, setFormState] = useState<{ newPatchName?: string }>({}); | ||
const [hasFormError, setHasFormError] = useState(false); | ||
const [isOpen, setIsOpen] = useState(false); | ||
const { schema, uiSchema } = getFormSchema(originalPatchName); | ||
const dispatchToast = useToastContext(); | ||
const [updateDescription, { loading }] = useMutation< | ||
UpdatePatchDescriptionMutation, | ||
UpdatePatchDescriptionMutationVariables | ||
>(UPDATE_PATCH_DESCRIPTION, { | ||
onCompleted() { | ||
setIsOpen(false); | ||
dispatchToast.success("Patch name was successfully updated."); | ||
}, | ||
onError({ message }) { | ||
dispatchToast.error(`Error updating patch name: ${message}.`); | ||
}, | ||
refetchQueries: ["Version"], | ||
}); | ||
|
||
const { newPatchName } = formState; | ||
|
||
return ( | ||
<> | ||
<StyledIconButton | ||
onClick={() => setIsOpen(true)} | ||
data-cy="name-change-modal-trigger" | ||
aria-label="name-change-modal-trigger" | ||
> | ||
<Icon glyph="Edit" /> | ||
</StyledIconButton> | ||
<ConfirmationModal | ||
buttonText="Confirm" | ||
onCancel={() => setIsOpen(false)} | ||
onConfirm={() => { | ||
updateDescription({ | ||
variables: { patchId, description: newPatchName }, | ||
}); | ||
}} | ||
open={isOpen} | ||
title="Update Patch Name" | ||
submitDisabled={ | ||
newPatchName === originalPatchName || hasFormError || loading | ||
} | ||
> | ||
<SpruceForm | ||
schema={schema} | ||
uiSchema={uiSchema} | ||
formData={formState} | ||
onChange={({ formData, errors }) => { | ||
setHasFormError(!!errors.length); | ||
setFormState(formData); | ||
}} | ||
/> | ||
</ConfirmationModal> | ||
</> | ||
); | ||
}; | ||
|
||
const StyledIconButton = styled(IconButton)` | ||
vertical-align: top; | ||
margin-left: ${size.xxs}; | ||
`; |