Skip to content

fix(site): validate group name before submitting to the backend #16115

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 1 commit into from
Jan 13, 2025

Conversation

ThomasK33
Copy link
Member

Fixes #13354

This PR adds the missing form validation for names when creating groups.


Change-Id: I6ffc2d571b2f6c6387ef143e0b0e74cf4196a551

Copy link

github-actions bot commented Jan 13, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ThomasK33
Copy link
Member Author

I have read the CLA Document and I hereby sign the CLA

cdrci2 added a commit to coder/cla that referenced this pull request Jan 13, 2025
Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look great! I’d suggest adding a test to ensure the name validation always works correctly by including at least one story in site/src/pages/GroupsPage/CreateGroupPageView.stories.tsx to cover the invalid state.

export const InvalidName: Story = {
	play: async ({ canvasElement }) => {
		const user = userEvent.setup();
		const input = await body.findByLabelText("Name");
		await user.type(input, "$om3 !nv@lid Name");
	},
};

For more details about the FE codebase, you can refer to this guide.

@ThomasK33 ThomasK33 force-pushed the thomaskosiewski/fix-site-validate-group-name branch from c592357 to 913d8a0 Compare January 13, 2025 14:46
@ThomasK33
Copy link
Member Author

The changes look great! I’d suggest adding a test to ensure the name validation always works correctly by including at least one story in site/src/pages/GroupsPage/CreateGroupPageView.stories.tsx to cover the invalid state.

export const InvalidName: Story = {
	play: async ({ canvasElement }) => {
		const user = userEvent.setup();
		const input = await body.findByLabelText("Name");
		await user.type(input, "$om3 !nv@lid Name");
	},
};

For more details about the FE codebase, you can refer to this guide.

Thanks @BrunoQuaresma. I've added a story for each component, as you suggested.

Change-Id: I6ffc2d571b2f6c6387ef143e0b0e74cf4196a551
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33 ThomasK33 force-pushed the thomaskosiewski/fix-site-validate-group-name branch from 913d8a0 to 83d95f4 Compare January 13, 2025 14:48
@BrunoQuaresma
Copy link
Collaborator

The changes look great! I’d suggest adding a test to ensure the name validation always works correctly by including at least one story in site/src/pages/GroupsPage/CreateGroupPageView.stories.tsx to cover the invalid state.

export const InvalidName: Story = {
	play: async ({ canvasElement }) => {
		const user = userEvent.setup();
		const input = await body.findByLabelText("Name");
		await user.type(input, "$om3 !nv@lid Name");
	},
};

For more details about the FE codebase, you can refer to this guide.

Thanks @BrunoQuaresma. I've added a story for each component, as you suggested.

You can always review and approve the stories yourself on Chromatic - they’re part of the commit checks. However, if you’d like a second opinion or an extra set of eyes on them, feel free to ping someone from the @coder/ts group.

@ThomasK33 ThomasK33 merged commit 8a8e7b1 into main Jan 13, 2025
30 checks passed
@ThomasK33 ThomasK33 deleted the thomaskosiewski/fix-site-validate-group-name branch January 13, 2025 16:54
@github-actions github-actions bot locked and limited conversation to collaborators Jan 13, 2025
const body = within(canvasElement.ownerDocument.body);
const input = await body.findByLabelText("Name");
await user.type(input, "$om3 !nv@lid Name");
input.blur();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrunoQuaresma I'm not sure if I'm missing something, but are these tests incomplete?

We're checking that the interactive elements exist and that the user can fill them out incorrectly, but then it looks like we're not asserting that anything happens in response to that? I would expect something like asserting that some kind of validation message appears

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chromatic will snapshot the final state, which will include the error message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that's good to know. I guess my worry is that without an expect-style assertion, somebody could accidentally accept the stories and miss that the validation message is no longer on screen

I'd prefer to force the test to fail if there's a good chance something is wrong, but maybe I subscribe too much to paranoia-driven development

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

site: restrict allowed characters in CreateGroupRequest.Name to ^[a-zA-Z0-9][a-zA-Z0-9\-]*
4 participants