diff --git a/src/index.js b/src/index.js index d169ec4c..2a6f2a11 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,7 @@ import icon from './widgets/icon/widget.vue'; import view from './widgets/view/widget.vue'; import navigation from './widgets/navigation/widget.vue'; import status from './widgets/status/widget.vue'; +import textfield from './widgets/textfield/widget.vue'; import _store from './core/store'; import _bus from './core/eventBus'; @@ -21,6 +22,7 @@ export const Icon = icon; export const View = view; export const Navigation = navigation; export const Status = status; +export const Textfield = textfield; export const bus = _bus; export const store = _store; diff --git a/src/widgets/textfield/widget.spec.js b/src/widgets/textfield/widget.spec.js new file mode 100644 index 00000000..cc9e2a95 --- /dev/null +++ b/src/widgets/textfield/widget.spec.js @@ -0,0 +1,67 @@ +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: '', + }); + }); + }); + + 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('emits input event with localValue', () => { + expect(context.$emit).toHaveBeenCalledWith('input', context.localValue); + }); + }); + + describe('#removeFocus', () => { + it('sets focused to false if focused is true', () => { + context = { + focused: true, + } + + Textfield.methods.removeFocus.call(context); + + expect(context.focused).toEqual(false); + }) + }); + + describe('#setFocus', () => { + it('sets focused to false if focused is true', () => { + context = { + focused: false, + } + + Textfield.methods.setFocus.call(context); + + expect(context.focused).toEqual(true); + }) + }); + }); +}); diff --git a/src/widgets/textfield/widget.vue b/src/widgets/textfield/widget.vue new file mode 100644 index 00000000..0414c7cd --- /dev/null +++ b/src/widgets/textfield/widget.vue @@ -0,0 +1,139 @@ + + + + + + +