diff options
author | 2023-05-07 23:31:10 +0200 | |
---|---|---|
committer | 2023-05-14 22:30:23 +0200 | |
commit | aad8d84e13ce31c1b7c1cbb930fb8bd4c0abe13a (patch) | |
tree | c483e3a25c858c09c73496616d95f168d8b9298d /src/ui/c-input-text/c-input-text.test.ts | |
parent | 401f13f7e305d60097db2334642e423c41d8897d (diff) | |
download | it-tools-aad8d84e13ce31c1b7c1cbb930fb8bd4c0abe13a.tar.gz it-tools-aad8d84e13ce31c1b7c1cbb930fb8bd4c0abe13a.tar.zst it-tools-aad8d84e13ce31c1b7c1cbb930fb8bd4c0abe13a.zip |
ui-lib(new-component): added text input component in the c-lib
Diffstat (limited to 'src/ui/c-input-text/c-input-text.test.ts')
-rw-r--r-- | src/ui/c-input-text/c-input-text.test.ts | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/ui/c-input-text/c-input-text.test.ts b/src/ui/c-input-text/c-input-text.test.ts new file mode 100644 index 0000000..56b5855 --- /dev/null +++ b/src/ui/c-input-text/c-input-text.test.ts @@ -0,0 +1,87 @@ +import { describe, expect, it, beforeEach } from 'vitest'; +import { shallowMount } from '@vue/test-utils'; +import { setActivePinia, createPinia } from 'pinia'; +import _ from 'lodash'; +import CInputText from './c-input-text.vue'; + +describe('CInputText', () => { + beforeEach(() => { + setActivePinia(createPinia()); + }); + + it('Renders a label', () => { + const wrapper = shallowMount(CInputText, { + props: { + label: 'Label', + }, + }); + + expect(wrapper.get('.label').text()).to.equal('Label'); + }); + + it('Renders a placeholder', () => { + const wrapper = shallowMount(CInputText, { + props: { + placeholder: 'Placeholder', + }, + }); + + expect(wrapper.get('.input').attributes('placeholder')).to.equal('Placeholder'); + }); + + it('Renders a value', () => { + const wrapper = shallowMount(CInputText, { + props: { + value: 'Value', + }, + }); + + expect(wrapper.vm.value).to.equal('Value'); + }); + + it('Renders a provided id', () => { + const wrapper = shallowMount(CInputText, { + props: { + id: 'id', + }, + }); + + expect(wrapper.get('.input').attributes('id')).to.equal('id'); + }); + + it('updates value on input', async () => { + const wrapper = shallowMount(CInputText); + + await wrapper.get('input').setValue('Hello'); + + expect(_.get(wrapper.emitted(), 'update:value.0.0')).to.equal('Hello'); + }); + + it('cannot be edited when disabled', async () => { + const wrapper = shallowMount(CInputText, { + props: { + disabled: true, + }, + }); + + await wrapper.get('input').setValue('Hello'); + + expect(_.get(wrapper.emitted(), 'update:value')).toBeUndefined(); + }); + + it('renders a feedback message for invalid rules', async () => { + const wrapper = shallowMount(CInputText, { + props: { rules: [{ validator: () => false, message: 'Message' }] }, + }); + + expect(wrapper.get('.feedback').text()).to.equal('Message'); + }); + + it('feedback does not render for valid rules', async () => { + const wrapper = shallowMount(CInputText, { + props: { rules: [{ validator: () => true, message: 'Message' }] }, + }); + + expect(wrapper.find('.feedback').exists()).to.equal(false); + }); +}); |