-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(textarea): add component and tests
closes #86
- Loading branch information
1 parent
782cc34
commit d520f1d
Showing
3 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<script> | ||
import {getContext} from 'svelte'; | ||
import {key} from './key'; | ||
export let name; | ||
const {form, handleChange} = getContext(key); | ||
</script> | ||
|
||
<textarea {name} on:change={handleChange} on:blur={handleChange} {...$$props}> | ||
{$form[name]} | ||
</textarea> |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export {createForm} from './create-form'; | ||
export {default as Form} from './components/Form.svelte'; | ||
export {default as Textarea} from './components/Textarea.svelte'; | ||
export {default as Field} from './components/Field.svelte'; | ||
export {default as Select} from './components/Select.svelte'; | ||
export {default as ErrorMessage} from './components/ErrorMessage.svelte'; |
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,38 @@ | ||
import {render as renderTl, fireEvent, waitFor} from '@testing-library/svelte'; | ||
|
||
import Form from '../lib/components/Form.svelte'; | ||
import Textarea from '../lib/components/Textarea.svelte'; | ||
|
||
const defaultProps = { | ||
initialValues: { | ||
description: '', | ||
}, | ||
['onSubmit']: () => {}, | ||
}; | ||
|
||
const render = (ui, props = defaultProps) => { | ||
return renderTl(<Form {...props}>{ui}</Form>, {props}); | ||
}; | ||
|
||
describe('Textarea', () => { | ||
test('-> updates value on change', async () => { | ||
const label = 'description'; | ||
const props = {...defaultProps}; | ||
const {getByLabelText} = render( | ||
<> | ||
<label for={label}>{label}</label> | ||
<Textarea id={label} name={label} /> | ||
</>, | ||
props, | ||
); | ||
|
||
const textarea = getByLabelText(label); | ||
expect(textarea.value.trim()).toBe(props.initialValues.description); | ||
|
||
const value = 'foo'; | ||
|
||
await fireEvent.change(textarea, {target: {value}}); | ||
|
||
expect(textarea.value).toContain(value); | ||
}); | ||
}); |