Skip to content

Commit

Permalink
Updated the test
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed May 17, 2022
1 parent b366a46 commit 47fa8b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface FormikErrors {
allow users to use alphabets(a-z & A-Z) and numbers
https://github.com/Opentrons/opentrons/issues/10214
*/
const REGEX_RENAME_ROBOT_PATTERN = /([a-zA-Z0-9]{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
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,26 @@ 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 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'
Expand Down

0 comments on commit 47fa8b5

Please sign in to comment.