Add tests for ShowPassword component. Lint LoginForm and ShowPassword.

This commit is contained in:
Brandon Tripp 2021-04-14 12:48:11 -06:00
parent 0e763c0ac3
commit cf58064e91
3 changed files with 54 additions and 23 deletions

View File

@ -31,7 +31,7 @@
ref="password"
:type="showPassword ? 'text' : 'password'"
/>
<show-password @show-password="toggleShowPassword" :iconName='iconName' />
<show-password @show-password="toggleShowPassword" :iconName="iconName" />
</div>
<nuxt-link to="/password-reset/request">
{{ $t('login.forgotPassword') }}
@ -60,7 +60,7 @@ import ShowPassword from '../ShowPassword/ShowPassword.vue'
export default {
components: {
LocaleSwitch,
ShowPassword
ShowPassword,
},
data() {
return {

View File

@ -0,0 +1,33 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import ShowPassword from './ShowPassword.vue'
describe('ShowPassword', () => {
describe('State of show password icon', () => {
const wrapper = mount(ShowPassword, {
propsData: {
iconName: 'eye',
},
})
it('Shows eye icon by default', () => {
expect(wrapper.find('.icon-wrapper').attributes('data-test')).toEqual('eye')
})
describe('After click', () => {
it('Password wrapper emits show-password event', async () => {
wrapper.find('.click-wrapper').trigger('click')
await Vue.nextTick()
expect(wrapper.emitted()).toBeTruthy()
})
it('Shows the slash-eye icon after click', async () => {
wrapper.find('.click-wrapper').trigger('click')
wrapper.setProps({ iconName: 'eye-slash' })
await Vue.nextTick()
expect(wrapper.find('.icon-wrapper').attributes('data-test')).toEqual('eye-slash')
})
})
})
})

View File

@ -8,32 +8,30 @@
<script>
export default {
props: [
'iconName'
],
props: ['iconName'],
emits: ['toggle-password'],
methods: {
togglePassword(event) {
event.preventDefault()
this.$emit('show-password')
}
}
},
},
}
</script>
<style lang="scss">
.icon-wrapper {
.icon-wrapper {
margin-right: 2px;
}
}
.click-wrapper {
.click-wrapper {
padding: 8px;
align-content: center;
color: $text-color-disabled;
cursor: pointer;
}
}
.click-wrapper:hover {
.click-wrapper:hover {
&:focus-within {
background-color: $background-color-base;
border: $input-border-size solid $border-color-active;
@ -42,5 +40,5 @@ export default {
color: $text-color-base;
}
}
}
}
</style>