-
Notifications
You must be signed in to change notification settings - Fork 81
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 #4926 from nextcloud-libraries/enh/ncinputfield-su…
…pport-numeric-value enh(NcInputField): Support numeric values - if numeric also emit numeric
- Loading branch information
Showing
2 changed files
with
52 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import NcInputField from '../../../../src/components/NcInputField/index.js' | ||
|
||
describe('NcInputField', () => { | ||
it('should emit text when type is text', async () => { | ||
const wrapper = shallowMount(NcInputField, { | ||
propsData: { | ||
label: 'label', | ||
value: '', | ||
type: 'text', | ||
}, | ||
}) | ||
|
||
await wrapper.get('input').setValue('text') | ||
|
||
expect(wrapper.emitted('update:value')).toEqual([['text']]) | ||
}) | ||
|
||
it('should emit text when type is number but value is text', () => { | ||
const wrapper = shallowMount(NcInputField, { | ||
propsData: { | ||
value: '1', | ||
type: 'number', | ||
}, | ||
}) | ||
|
||
const input = wrapper.find('input').element as HTMLInputElement | ||
input.value = '2' | ||
input.dispatchEvent(new InputEvent('input')) | ||
|
||
expect(wrapper.emitted('update:value')).toEqual([['2']]) | ||
}) | ||
|
||
it('should emit a number when type is number and value is number', () => { | ||
const wrapper = shallowMount(NcInputField, { | ||
propsData: { | ||
value: 1, | ||
type: 'number', | ||
}, | ||
}) | ||
|
||
const input = wrapper.find('input').element as HTMLInputElement | ||
input.value = '2' | ||
input.dispatchEvent(new InputEvent('input')) | ||
|
||
expect(wrapper.emitted('update:value')).toEqual([[2]]) | ||
}) | ||
}) |