mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
Implement component test
This commit is contained in:
parent
8827add1c7
commit
22367417de
@ -8,15 +8,25 @@ const localVue = createLocalVue()
|
|||||||
localVue.use(Styleguide)
|
localVue.use(Styleguide)
|
||||||
|
|
||||||
describe('ChangePassword.vue', () => {
|
describe('ChangePassword.vue', () => {
|
||||||
let store
|
|
||||||
let mocks
|
let mocks
|
||||||
let wrapper
|
let wrapper
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mocks = {
|
mocks = {
|
||||||
validate: jest.fn(),
|
validate: jest.fn(),
|
||||||
|
$toast: {
|
||||||
|
error: jest.fn(),
|
||||||
|
success: jest.fn()
|
||||||
|
},
|
||||||
|
$t: jest.fn(),
|
||||||
|
$store: {
|
||||||
|
commit: jest.fn()
|
||||||
|
},
|
||||||
$apollo: {
|
$apollo: {
|
||||||
mutate: jest.fn().mockResolvedValue()
|
mutate: jest
|
||||||
|
.fn()
|
||||||
|
.mockRejectedValue({ message: 'Ouch!' })
|
||||||
|
.mockResolvedValueOnce({ data: { changePassword: 'NEWTOKEN' } })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -80,15 +90,63 @@ describe('ChangePassword.vue', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('given valid input', () => {
|
describe('given valid input', () => {
|
||||||
describe('click on submit button', () => {
|
beforeEach(() => {
|
||||||
it.todo('calls changePassword mutation')
|
wrapper.find('input#oldPassword').setValue('supersecret')
|
||||||
|
wrapper.find('input#newPassword').setValue('superdupersecret')
|
||||||
|
wrapper.find('input#confirmPassword').setValue('superdupersecret')
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('submit form', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper.find('form').trigger('submit')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calls changePassword mutation', () => {
|
||||||
|
expect(mocks.$apollo.mutate).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('passes form data as variables', () => {
|
||||||
|
expect(mocks.$apollo.mutate.mock.calls[0][0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
variables: {
|
||||||
|
oldPassword: 'supersecret',
|
||||||
|
newPassword: 'superdupersecret',
|
||||||
|
confirmPassword: 'superdupersecret'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
describe('mutation resolves', () => {
|
describe('mutation resolves', () => {
|
||||||
it.todo('calls auth/SET_TOKEN with response')
|
beforeEach(() => {
|
||||||
|
mocks.$apollo.mutate = jest.fn().mockResolvedValue()
|
||||||
|
wrapper = Wrapper()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calls auth/SET_TOKEN with response', () => {
|
||||||
|
expect(mocks.$store.commit).toHaveBeenCalledWith(
|
||||||
|
'auth/SET_TOKEN',
|
||||||
|
'NEWTOKEN'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('displays success message', () => {
|
||||||
|
expect(mocks.$t).toHaveBeenCalledWith(
|
||||||
|
'settings.security.change-password.success'
|
||||||
|
)
|
||||||
|
expect(mocks.$toast.success).toHaveBeenCalled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mutation rejects', () => {
|
describe('mutation rejects', () => {
|
||||||
it.todo('displays error message')
|
beforeEach(() => {
|
||||||
|
// second call will reject
|
||||||
|
wrapper.find('form').trigger('submit')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('displays error message', () => {
|
||||||
|
expect(mocks.$toast.error).toHaveBeenCalledWith('Ouch!')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
v-model="formData"
|
v-model="formData"
|
||||||
:schema="formSchema"
|
:schema="formSchema"
|
||||||
@submit="handleSubmit"
|
@submit="handleSubmit"
|
||||||
@input="validate"
|
|
||||||
>
|
>
|
||||||
<template>
|
<template>
|
||||||
<ds-input
|
<ds-input
|
||||||
@ -25,8 +24,11 @@
|
|||||||
label="Confirm new password"
|
label="Confirm new password"
|
||||||
/>
|
/>
|
||||||
<ds-space margin-top="base">
|
<ds-space margin-top="base">
|
||||||
<ds-button primary>
|
<ds-button
|
||||||
Submit
|
:loading="loading"
|
||||||
|
primary
|
||||||
|
>
|
||||||
|
{{ $t('settings.security.change-password.button') }}
|
||||||
</ds-button>
|
</ds-button>
|
||||||
</ds-space>
|
</ds-space>
|
||||||
</template>
|
</template>
|
||||||
@ -34,6 +36,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import gql from 'graphql-tag'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ChangePassword',
|
name: 'ChangePassword',
|
||||||
data() {
|
data() {
|
||||||
@ -48,17 +52,31 @@ export default {
|
|||||||
newPassword: { required: true },
|
newPassword: { required: true },
|
||||||
confirmPassword: { required: true }
|
confirmPassword: { required: true }
|
||||||
},
|
},
|
||||||
|
loading: false,
|
||||||
disabled: true
|
disabled: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
validate(data) {
|
async handleSubmit(data) {
|
||||||
console.log('validate')
|
this.loading = true
|
||||||
console.log(data)
|
const mutation = gql`
|
||||||
},
|
mutation($oldPassword: String!, $newPassword: String!) {
|
||||||
handleSubmit(data) {
|
changePassword(oldPassword: $oldPassword, newPassword: $newPassword)
|
||||||
console.log('handleSubmit')
|
}
|
||||||
console.log(data)
|
`
|
||||||
|
const variables = this.formData
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { data } = await this.$apollo.mutate({ mutation, variables })
|
||||||
|
this.$store.commit('auth/SET_TOKEN', data.changePassword)
|
||||||
|
this.$toast.success(
|
||||||
|
this.$t('settings.security.change-password.success')
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
this.$toast.error(err.message)
|
||||||
|
} finally {
|
||||||
|
this.loading = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,11 @@
|
|||||||
"labelBio": "Über dich"
|
"labelBio": "Über dich"
|
||||||
},
|
},
|
||||||
"security": {
|
"security": {
|
||||||
"name": "Sicherheit"
|
"name": "Sicherheit",
|
||||||
|
"change-password": {
|
||||||
|
"button": "Passwort ändern",
|
||||||
|
"success": "Passwort erfolgreich geändert!"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"invites": {
|
"invites": {
|
||||||
"name": "Einladungen"
|
"name": "Einladungen"
|
||||||
|
|||||||
@ -31,7 +31,11 @@
|
|||||||
"labelBio": "About You"
|
"labelBio": "About You"
|
||||||
},
|
},
|
||||||
"security": {
|
"security": {
|
||||||
"name": "Security"
|
"name": "Security",
|
||||||
|
"change-password": {
|
||||||
|
"button": "Change password",
|
||||||
|
"success": "Password successfully changed!"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"invites": {
|
"invites": {
|
||||||
"name": "Invites"
|
"name": "Invites"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user