diff --git a/components/src/stories/TextField.stories.js b/components/src/stories/TextField.stories.js
index 19c2acc1..d655e6f7 100644
--- a/components/src/stories/TextField.stories.js
+++ b/components/src/stories/TextField.stories.js
@@ -11,9 +11,12 @@ export const Component = {
},
template: '',
}),
-
+
args: {
label: 'Label text',
+ value: '',
+ placeholder: 'Placeholder text',
+ suffix: '',
},
};
@@ -25,5 +28,8 @@ export default {
},
argTypes: {
label: 'text',
+ value: 'text',
+ placeholder: 'text',
+ suffix: 'text',
},
};
diff --git a/components/src/widgets/textfield/widget.spec.js b/components/src/widgets/textfield/widget.spec.js
index cc9e2a95..1a7056fe 100644
--- a/components/src/widgets/textfield/widget.spec.js
+++ b/components/src/widgets/textfield/widget.spec.js
@@ -1,67 +1,60 @@
+import { mount } from '@vue/test-utils';
import Textfield from './widget';
describe('Textfield widget', () => {
- let context;
- let result;
-
- describe('#data', () => {
- it('returns the initial data', () => {
- result = Textfield.data();
-
- expect(result).toEqual({
- focused: false,
- localValue: '',
- });
+ let wrapper;
+
+ describe('render', () => {
+ it('renders the base component without any prop', () => {
+ wrapper = mount(Textfield);
+
+ expect(wrapper.get('.text-field').exists()).toBeTruthy();
+ expect(wrapper.get('.text-field label').text()).toEqual('');
+ expect(wrapper.get('.text-field__input').exists()).toBeTruthy();
+ expect(wrapper.get('.text-field__input').element.value).toEqual('');
+ expect(wrapper.get('.text-field__input').attributes('placeholder')).toEqual('');
+ expect(wrapper.find('.text-field__suffix').exists()).toBeFalsy();
+ expect(wrapper.find('.text-field_focused').exists()).toBeFalsy();
+ expect(wrapper.find('.text-field__input_right').exists()).toBeFalsy();
});
- });
-
- describe('methods', () => {
- describe('#onInput', () => {
- beforeEach(() => {
- context = {
- localValue: 'my value',
- $emit: jest.fn(),
- e: {
- stopPropagation: jest.fn(),
- },
- };
-
- Textfield.methods.onInput.call(context, context.e);
- });
-
- it('calls stop propagation from event', () => {
- expect(context.e.stopPropagation).toHaveBeenCalled();
+ it('renders the base component with the props set', () => {
+ wrapper = mount(Textfield, {
+ props: {
+ value: 'Foo',
+ label: 'My text input',
+ placeholder: 'Insert text here',
+ suffix: 'hh:mm:ssss.csv',
+ },
});
- it('emits input event with localValue', () => {
- expect(context.$emit).toHaveBeenCalledWith('input', context.localValue);
- });
+ expect(wrapper.get('.text-field').exists()).toBeTruthy();
+ expect(wrapper.get('.text-field label').text()).toEqual('My text input');
+ expect(wrapper.get('.text-field__input').exists()).toBeTruthy();
+ expect(wrapper.get('.text-field__input').element.value).toEqual('Foo');
+ expect(wrapper.get('.text-field__input').attributes('placeholder')).toEqual('Insert text here');
+ expect(wrapper.get('.text-field__suffix').text()).toEqual('hh:mm:ssss.csv');
+ expect(wrapper.get('.text-field__input_right').exists()).toBeTruthy();
+ expect(wrapper.find('.text-field_focused').exists()).toBeFalsy();
});
- describe('#removeFocus', () => {
- it('sets focused to false if focused is true', () => {
- context = {
- focused: true,
- }
+ it('sets the "text-field_focused" class when focused', async () => {
+ wrapper = mount(Textfield);
- Textfield.methods.removeFocus.call(context);
+ await wrapper.find('.text-field').trigger('focusin');
- expect(context.focused).toEqual(false);
- })
+ expect(wrapper.get('.text-field_focused').exists()).toBeTruthy();
});
+ });
- describe('#setFocus', () => {
- it('sets focused to false if focused is true', () => {
- context = {
- focused: false,
- }
+ describe('events', () => {
+ it('emits the "input" event when the input element value changes', async () => {
+ wrapper = mount(Textfield);
- Textfield.methods.setFocus.call(context);
+ await wrapper.find('.text-field__input').setValue('lorem ipsum');
- expect(context.focused).toEqual(true);
- })
+ expect(wrapper.emitted().input[0]).toEqual(['lorem ipsum']);
});
});
});
diff --git a/components/src/widgets/textfield/widget.vue b/components/src/widgets/textfield/widget.vue
index 15245af4..ad8e4382 100644
--- a/components/src/widgets/textfield/widget.vue
+++ b/components/src/widgets/textfield/widget.vue
@@ -1,10 +1,7 @@
-
-
-