-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #589 from nick2432/Fix-6279-wrong-validation-of-pr…
…ojectid
- Loading branch information
Showing
6 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
import { FormItem } from '.'; | ||
import TextCounter from './textCounter.svelte'; | ||
export let value = ''; | ||
export let autofocus = true; | ||
let element: HTMLInputElement; | ||
let icon = 'info'; | ||
const pattern = String.raw`^[a-z0-9][a-z0-9\-]*$`; | ||
onMount(() => { | ||
if (element && autofocus) { | ||
element.focus(); | ||
} | ||
}); | ||
const handleInvalid = (event: Event) => { | ||
event.preventDefault(); | ||
if (element.validity.patternMismatch) { | ||
icon = 'exclamation'; | ||
return; | ||
} | ||
}; | ||
$: if (value) { | ||
icon = 'info'; | ||
} | ||
</script> | ||
|
||
<FormItem> | ||
<div class="input-text-wrapper"> | ||
<input | ||
id="id" | ||
placeholder="Enter ID" | ||
maxlength={36} | ||
{pattern} | ||
autocomplete="off" | ||
type="text" | ||
class="input-text" | ||
bind:value | ||
bind:this={element} | ||
on:invalid={handleInvalid} /> | ||
<TextCounter count={value?.length ?? 0} max={36} /> | ||
</div> | ||
</FormItem> | ||
<div | ||
class="u-flex u-gap-4 u-margin-block-start-8 u-small" | ||
class:u-color-text-warning={icon === 'exclamation'}> | ||
<span | ||
class:icon-info={icon === 'info'} | ||
class:icon-exclamation={icon === 'exclamation'} | ||
class="u-cross-center u-line-height-1 u-color-text-gray" | ||
aria-hidden="true" /> | ||
<span class="text u-line-height-1-5"> | ||
Allowed characters: lowercase alphanumeric and non-leading hyphen | ||
</span> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/svelte'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { InputProjectId } from '../../../src/lib/elements/forms'; | ||
|
||
const validStrings = ['validstring', 'valid-string', 'validstring123', 'valid-']; | ||
|
||
const invalidStrings = ['-invalid', 'Valid', '_invalid', 'Valid123', 'valid.string']; | ||
|
||
test('shows id input', () => { | ||
const { getByPlaceholderText } = render(InputProjectId); | ||
const input = getByPlaceholderText('Enter ID'); | ||
|
||
expect(input).toBeInTheDocument(); | ||
expect(input).toHaveAttribute('type', 'text'); | ||
}); | ||
|
||
test('state', async () => { | ||
const { component, getByPlaceholderText } = render(InputProjectId, { value: '' }); | ||
const input = getByPlaceholderText('Enter ID'); | ||
|
||
expect(component.value).toEqual(''); | ||
await userEvent.type(input, 'lorem'); | ||
expect(component.value).toEqual('lorem'); | ||
}); | ||
|
||
validStrings.forEach((validString) => { | ||
test(`validates ${validString} as valid`, () => { | ||
const { getByPlaceholderText } = render(InputProjectId, { value: validString }); | ||
const input = getByPlaceholderText('Enter ID') as HTMLInputElement; | ||
expect(input.checkValidity()).toBe(true); | ||
}); | ||
}); | ||
invalidStrings.forEach((invalidString) => { | ||
test(`validates ${invalidString} as invalid`, () => { | ||
const { getByPlaceholderText } = render(InputProjectId, { value: invalidString }); | ||
const input = getByPlaceholderText('Enter ID') as HTMLInputElement; | ||
expect(input.checkValidity()).toBe(false); | ||
}); | ||
}); |
e965738
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
console-cloud – ./
console-cloud-git-main-appwrite.vercel.app
console-cloud-appwrite.vercel.app
console-cloud.vercel.app
e965738
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
console-preview-cloud – ./
console-preview-cloud-appwrite.vercel.app
console-preview-cloud.vercel.app
console-preview-cloud-git-main-appwrite.vercel.app
e965738
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
console – ./
brand-new-console.torsten.appwrite.org
demo.appwriters.com
console-git-main-appwrite.vercel.app
svelte-console.vercel.app
console-appwrite.vercel.app
e965738
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
console-preview – ./
console-preview-appwrite.vercel.app
console-preview-git-main-appwrite.vercel.app
console-next.vercel.app