Skip to content

Commit

Permalink
fix: disallow space only device names (#1014)
Browse files Browse the repository at this point in the history
* Makes sure need to enter some kind of text for device name

* Adds a test to make sure white spaces for a device name error out
  • Loading branch information
cimigree authored Mar 4, 2025
1 parent b2cf774 commit 5c1ae45
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/frontend/screens/Onboarding/DeviceNaming.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const DeviceNaming = ({
}: NativeStackScreenProps<OnboardingParamsList, 'DeviceNaming'>) => {
const [name, setName] = React.useState('');
const [errorTimeout, setErrorTimeout] = useTemporaryError();
const invalidName = name.length === 0 || name.length > 60;
const {formatMessage: t} = useIntl();

function setNameWithValidation(nameValue: string) {
Expand All @@ -48,12 +47,13 @@ export const DeviceNaming = ({
}

function handleAddNamePress() {
if (invalidName) {
const trimmedName = name.trim();
if (trimmedName.length === 0 || trimmedName.length > 60) {
setErrorTimeout();
return;
}

navigation.navigate('Success', {deviceName: name});
navigation.navigate('Success', {deviceName: trimmedName});
}
return (
<KeyboardAvoidingView style={{width: '100%', height: '100%'}}>
Expand Down
11 changes: 10 additions & 1 deletion tests/e2e/specs/onboarding/device-naming.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ describe('Device Naming Test', () => {

const successMessage = await $(byTextMatches('Success'));
await driver.waitUntil(async () => !(await successMessage.isExisting()), {
timeout: 5000,
timeout: 2000,
timeoutMsg: 'The success message did not appear within timeout',
});

await deviceNameInput.setValue(' ');
await addNameButton.click();

await driver.waitUntil(async () => !(await successMessage.isExisting()), {
timeout: 2000,
timeoutMsg:
'Success message should not appear when input is only spaces.',
});

await deviceNameInput.setValue(output.names.device);
await addNameButton.click();

Expand Down

0 comments on commit 5c1ae45

Please sign in to comment.