- Notifications
You must be signed in to change notification settings - Fork928
fix: only allow submitting form if changes have been made#14602
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
13ca57d
0f4657d
c947bc6
230de7f
bdc659d
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -61,7 +61,9 @@ test("Submit the workspace settings page successfully", async () => { | ||
); | ||
await user.clear(parameter2); | ||
await user.type(parameter2, "1"); | ||
await user.click( | ||
within(form).getByRole("button", { name: "Submit and restart" }), | ||
); | ||
// Assert that the API calls were made with the correct data | ||
await waitFor(() => { | ||
expect(postWorkspaceBuildSpy).toHaveBeenCalledWith(MockWorkspace.id, { | ||
@@ -73,3 +75,58 @@ test("Submit the workspace settings page successfully", async () => { | ||
}); | ||
}); | ||
}); | ||
test("Submit button is only enabled when changes are made", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think for now, having a test for this in Jest is ok, but in the future, you can try to usestorybook and interaction tests :) | ||
// Mock the API calls that loads data | ||
jest | ||
.spyOn(API, "getWorkspaceByOwnerAndName") | ||
.mockResolvedValueOnce(MockWorkspace); | ||
jest.spyOn(API, "getTemplateVersionRichParameters").mockResolvedValueOnce([ | ||
MockTemplateVersionParameter1, | ||
MockTemplateVersionParameter2, | ||
// Immutable parameters | ||
MockTemplateVersionParameter4, | ||
]); | ||
jest.spyOn(API, "getWorkspaceBuildParameters").mockResolvedValueOnce([ | ||
MockWorkspaceBuildParameter1, | ||
MockWorkspaceBuildParameter2, | ||
// Immutable value | ||
MockWorkspaceBuildParameter4, | ||
]); | ||
// Setup event and rendering | ||
const user = userEvent.setup(); | ||
renderWithWorkspaceSettingsLayout(<WorkspaceParametersPage />, { | ||
route: "/@test-user/test-workspace/settings", | ||
path: "/:username/:workspace/settings", | ||
// Need this because after submit the user is redirected | ||
extraRoutes: [{ path: "/:username/:workspace", element: <div /> }], | ||
}); | ||
await waitForLoaderToBeRemoved(); | ||
const submitButton: HTMLButtonElement = screen.getByRole("button", { | ||
name: "Submit and restart", | ||
}); | ||
const form = screen.getByTestId("form"); | ||
const parameter1 = within(form).getByLabelText( | ||
MockWorkspaceBuildParameter1.name, | ||
{ exact: false }, | ||
); | ||
// There are no changes, the button should be disabled. | ||
expect(submitButton.disabled).toBeTruthy(); | ||
// Make changes to the form | ||
await user.clear(parameter1); | ||
await user.type(parameter1, "new-value"); | ||
// There are now changes, the button should be enabled. | ||
expect(submitButton.disabled).toBeFalsy(); | ||
// Change form value back to default | ||
await user.clear(parameter1); | ||
await user.type(parameter1, MockWorkspaceBuildParameter1.value); | ||
// There are now no changes, the button should be disabled. | ||
expect(submitButton.disabled).toBeTruthy(); | ||
}); |
Uh oh!
There was an error while loading.Please reload this page.