Skip to content
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

fix(app): Update robot rename rule #10318

Merged
merged 3 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/src/assets/localization/en/device_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@
"use_older_aspirate": "Use older aspirate behavior",
"use_older_aspirate_description": "Aspirate with the less accurate volumetric calibrations that were used before version 3.7.0. Use this if you need consistency with pre-v3.7.0 results. This only affects GEN1 P10S, P10M, P50M, and P300S pipettes.",
"rename_robot_slideout_title": "Rename Robot",
"rename_robot_slideout_description": "Please enter 35 characters max using valid inputs: letters, numbers, spaces and these special characters: !?$*’-_.",
"rename_robot_slideout_label": "Robot Name",
"rename_robot_button": "Rename robot",
"rename_robot_input_limitation_label": "35 characters max",
"rename_robot_input_error_message": "Please enter 35 characters max using valid inputs: letters, numbers, spaces and these special characters: !?$*’-_.",
"rename_robot_input_limitation_detail": "Please enter 35 characters max using valid inputs: letters and numbers",
"factory_reset_slideout_title": "Factory Reset",
"factory_reset_slideout_description": "Select the robot data to clear.",
"factory_reset_slideout_warning_message": "Factory resets cannot be undone",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ interface FormikErrors {
}

/* max length is 35 and min length is 1
allow users to use alphabets, numbers, space, ', !, ?, $, _, .(dot), and -
not allow users to use space at the beginning of a new name
allow users to use alphabets(a-z & A-Z) and numbers
https://github.com/Opentrons/opentrons/issues/10214
*/
const REGEX_RENAME_ROBOT_PATTERN = /^\S([a-zA-Z0-9\s-_.!$?*]{0,35})$/
const REGEX_RENAME_ROBOT_PATTERN = /^([a-zA-Z0-9]{0,35})$/
const regexPattern = new RegExp(REGEX_RENAME_ROBOT_PATTERN)

export function RenameRobotSlideout({
Expand Down Expand Up @@ -62,7 +62,7 @@ export function RenameRobotSlideout({
const errors: FormikErrors = {}
const newName = values.newRobotName
if (!regexPattern.test(newName)) {
errors.newRobotName = t('rename_robot_input_error_message')
errors.newRobotName = t('rename_robot_input_limitation_detail')
}
return errors
},
Expand Down Expand Up @@ -100,7 +100,7 @@ export function RenameRobotSlideout({
>
<Flex flexDirection={DIRECTION_COLUMN}>
<StyledText as="p" marginBottom={SPACING.spacing4}>
{t('rename_robot_slideout_description')}
{t('rename_robot_input_limitation_detail')}
</StyledText>
<StyledText
as="label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('RobotSettings RenameRobotSlideout', () => {

getByText('Rename Robot')
getByText(
'Please enter 35 characters max using valid inputs: letters, numbers, spaces and these special characters: !?$*’-_.'
'Please enter 35 characters max using valid inputs: letters and numbers'
)
getByText('Robot Name')
getByText('35 characters max')
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('RobotSettings RenameRobotSlideout', () => {
expect(input).toHaveValue('mockInput@@@')
const renameButton = getByRole('button', { name: 'Rename robot' })
const error = await findByText(
'Please enter 35 characters max using valid inputs: letters, numbers, spaces and these special characters: !?$*’-_.'
'Please enter 35 characters max using valid inputs: letters and numbers'
)
await waitFor(() => {
expect(renameButton).toBeDisabled()
Expand All @@ -73,12 +73,29 @@ describe('RobotSettings RenameRobotSlideout', () => {
const [{ getByRole, findByText }] = render()
const input = getByRole('textbox')
fireEvent.change(input, {
target: { value: 'This is more than 35 characters This is a mock' },
target: { value: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' },
})
expect(input).toHaveValue('This is more than 35 characters This is a mock')
expect(input).toHaveValue('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
const renameButton = getByRole('button', { name: 'Rename robot' })
const error = await findByText(
'Please enter 35 characters max using valid inputs: letters, numbers, spaces and these special characters: !?$*’-_.'
'Please enter 35 characters max using valid inputs: letters and numbers'
)
await waitFor(() => {
expect(renameButton).toBeDisabled()
expect(error).toBeInTheDocument()
})
})

it('button should be disabled and render the error message when a user tries to use space', async () => {
const [{ getByRole, findByText }] = render()
const input = getByRole('textbox')
fireEvent.change(input, {
target: { value: 'Hello world123' },
})
expect(input).toHaveValue('Hello world123')
const renameButton = getByRole('button', { name: 'Rename robot' })
const error = await findByText(
'Please enter 35 characters max using valid inputs: letters and numbers'
)
await waitFor(() => {
expect(renameButton).toBeDisabled()
Expand All @@ -95,14 +112,14 @@ describe('RobotSettings RenameRobotSlideout', () => {
expect(input).toHaveValue(' ')
const renameButton = getByRole('button', { name: 'Rename robot' })
const error = await findByText(
'Please enter 35 characters max using valid inputs: letters, numbers, spaces and these special characters: !?$*’-_.'
'Please enter 35 characters max using valid inputs: letters and numbers'
)
await waitFor(() => {
expect(renameButton).toBeDisabled()
expect(error).toBeInTheDocument()
})
})
// TODO: The following test case will be tested in the future
// TODO: kj The following test case will be tested in the future
// it('should close the slideout when a user change the name successfully', () => {
// const [{ getByRole }, store] = render()
// expect(store.dispatch).toHaveBeenCalledWith(removeRobot('otie'))
Expand Down