From 0bde83eb75ac2bbe276af6b918b83072900adf90 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 29 Jun 2021 11:54:38 +0200 Subject: [PATCH] email input component --- .../src/components/Inputs/InputEmail.spec.js | 71 ++++++++++++++++++ frontend/src/components/Inputs/InputEmail.vue | 73 +++++++++++++++++++ frontend/src/views/Pages/Login.vue | 51 ++----------- 3 files changed, 150 insertions(+), 45 deletions(-) create mode 100644 frontend/src/components/Inputs/InputEmail.spec.js create mode 100644 frontend/src/components/Inputs/InputEmail.vue diff --git a/frontend/src/components/Inputs/InputEmail.spec.js b/frontend/src/components/Inputs/InputEmail.spec.js new file mode 100644 index 000000000..f8e374654 --- /dev/null +++ b/frontend/src/components/Inputs/InputEmail.spec.js @@ -0,0 +1,71 @@ +import { mount } from '@vue/test-utils' + +import InputEmail from './InputEmail' + +const localVue = global.localVue + +describe('InputEmail', () => { + let wrapper + + const propsData = { + name: 'input-field-name', + label: 'input-field-label', + placeholder: 'input-field-placeholder', + value: '', + } + + const Wrapper = () => { + return mount(InputEmail, { localVue, propsData }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('has an input field', () => { + expect(wrapper.find('input').exists()).toBeTruthy() + }) + + describe('properties', () => { + it('has the name "input-field-name"', () => { + expect(wrapper.find('input').attributes('name')).toEqual('input-field-name') + }) + + it('has the id "input-field-name-input-field"', () => { + expect(wrapper.find('input').attributes('id')).toEqual('input-field-name-input-field') + }) + + it('has the placeholder "input-field-placeholder"', () => { + expect(wrapper.find('input').attributes('placeholder')).toEqual('input-field-placeholder') + }) + + it('has the value ""', () => { + expect(wrapper.vm.currentValue).toEqual('') + }) + + it('has the label "input-field-label"', () => { + expect(wrapper.find('label').text()).toEqual('input-field-label') + }) + + it('has the label for "input-field-name-input-field"', () => { + expect(wrapper.find('label').attributes('for')).toEqual('input-field-name-input-field') + }) + }) + + describe('input value changes', () => { + it('emits input with new value', async () => { + await wrapper.find('input').setValue('12') + expect(wrapper.emitted('input')).toBeTruthy() + expect(wrapper.emitted('input')).toEqual([['12']]) + }) + }) + + describe('value property changes', () => { + it('updates data model', async () => { + await wrapper.setProps({ value: 'user@example.org' }) + expect(wrapper.vm.currentValue).toEqual('user@example.org') + }) + }) + }) +}) diff --git a/frontend/src/components/Inputs/InputEmail.vue b/frontend/src/components/Inputs/InputEmail.vue new file mode 100644 index 000000000..adcd66345 --- /dev/null +++ b/frontend/src/components/Inputs/InputEmail.vue @@ -0,0 +1,73 @@ + + + diff --git a/frontend/src/views/Pages/Login.vue b/frontend/src/views/Pages/Login.vue index 25c40df5a..2d4ce2345 100755 --- a/frontend/src/views/Pages/Login.vue +++ b/frontend/src/views/Pages/Login.vue @@ -13,7 +13,6 @@ - @@ -22,47 +21,14 @@
{{ $t('login') }}
- - - - - - - - - {{ validationContext.errors[0] }} - - - - + + + - - - - - - - {{ $t('error.no-account') }} - - - - -
{{ $t('login') }}
@@ -91,31 +57,26 @@ import loginAPI from '../../apis/loginAPI' import CONFIG from '../../config' import InputPassword from '../../components/Inputs/InputPassword' +import InputEmail from '../../components/Inputs/InputEmail' export default { name: 'login', components: { InputPassword, + InputEmail, }, data() { return { form: { email: '', password: '', - // rememberMe: false }, - loginfail: false, allowRegister: CONFIG.ALLOW_REGISTER, passwordVisible: false, } }, methods: { - getValidationState({ dirty, validated, valid = null }) { - return dirty || validated ? valid : null - }, async onSubmit() { - // error info ausschalten - this.loginfail = false const loader = this.$loading.show({ container: this.$refs.submitButton, }) @@ -129,7 +90,7 @@ export default { loader.hide() } else { loader.hide() - this.loginfail = true + this.$toast.error(this.$t('error.no-account')) } }, },