diff --git a/src/renderer/components/secret-editor/value-editor/trim-button/trim-button.html b/src/renderer/components/secret-editor/value-editor/trim-button/trim-button.html new file mode 100644 index 0000000..a406b4b --- /dev/null +++ b/src/renderer/components/secret-editor/value-editor/trim-button/trim-button.html @@ -0,0 +1,8 @@ + +
+ +
+
diff --git a/src/renderer/components/secret-editor/value-editor/trim-button/trim-button.js b/src/renderer/components/secret-editor/value-editor/trim-button/trim-button.js new file mode 100644 index 0000000..6d17ed7 --- /dev/null +++ b/src/renderer/components/secret-editor/value-editor/trim-button/trim-button.js @@ -0,0 +1,12 @@ +export default { + name: 'trim-button', + template: require('./trim-button.html'), + props: { + text: { type: String, default: '' } + }, + methods: { + trim() { + this.$emit('trim', this.text.trim()); + } + } +}; diff --git a/src/renderer/components/secret-editor/value-editor/trim-button/trim-button.spec.js b/src/renderer/components/secret-editor/value-editor/trim-button/trim-button.spec.js new file mode 100644 index 0000000..1e071e3 --- /dev/null +++ b/src/renderer/components/secret-editor/value-editor/trim-button/trim-button.spec.js @@ -0,0 +1,19 @@ +import { mount } from '@vue/test-utils'; +import JsonFormatButton from './trim-button'; + +describe('TrimButton', () => { + describe('#trim', () => { + it('should trim the given text', () => { + const wrapper = mount(JsonFormatButton, { + propsData: { + text: ' Gummi Bears ' + } + }); + + wrapper.find('.e-btn').trigger('click'); + + const emitted = wrapper.emitted().trim[0][0]; + expect(emitted).to.eql('Gummi Bears'); + }); + }); +}); diff --git a/src/renderer/components/secret-editor/value-editor/value-editor.html b/src/renderer/components/secret-editor/value-editor/value-editor.html index 5d43b0b..8b25bcd 100644 --- a/src/renderer/components/secret-editor/value-editor/value-editor.html +++ b/src/renderer/components/secret-editor/value-editor/value-editor.html @@ -9,6 +9,10 @@ />
+ { expect(wrapper.emitted()).to.eql({ change: [['something else']] }); }); + + it('should emit change event when a field is trimmed', () => { + const wrapper = mountWithStore(ValueEditor, { propsData: { value: ' Dr Bubo ' } }); + wrapper.find('.editor-toolbar .trim .e-btn').trigger('click'); + expect(wrapper.emitted()).to.eql({ change: [['Dr Bubo']] }); + }); }); });