mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Implementation of the FormUserMail Tests. And review changes.
This commit is contained in:
parent
4c0d222a81
commit
421aba22ff
@ -59,7 +59,7 @@ export const loadAllRules = (i18nCallback) => {
|
||||
},
|
||||
})
|
||||
.then((result) => {
|
||||
return result.data.state === 'success'
|
||||
return result.data.checkUsername.state === 'success'
|
||||
})
|
||||
.catch(() => {
|
||||
return false
|
||||
|
||||
@ -10,7 +10,7 @@ const toastErrorMock = jest.fn()
|
||||
const toastSuccessMock = jest.fn()
|
||||
const storeCommitMock = jest.fn()
|
||||
|
||||
describe('UserCard_FormUsername', () => {
|
||||
describe('UserCard_FormUserData', () => {
|
||||
let wrapper
|
||||
|
||||
const mocks = {
|
||||
|
||||
@ -0,0 +1,127 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
import flushPromises from 'flush-promises'
|
||||
import UserCardFormUserMail from './UserCard_FormUserMail'
|
||||
|
||||
const localVue = global.localVue
|
||||
jest.spyOn(window, 'alert').mockImplementation(() => {})
|
||||
|
||||
const mockAPIcall = jest.fn()
|
||||
|
||||
describe('UserCard_FormUserMail', () => {
|
||||
let wrapper
|
||||
|
||||
const mocks = {
|
||||
$t: jest.fn((t) => t),
|
||||
$store: {
|
||||
state: {
|
||||
sessionId: 1,
|
||||
email: 'user@example.org',
|
||||
firstName: 'Peter',
|
||||
lastName: 'Lustig',
|
||||
description: '',
|
||||
},
|
||||
},
|
||||
$apollo: {
|
||||
query: mockAPIcall,
|
||||
},
|
||||
}
|
||||
|
||||
const Wrapper = () => {
|
||||
return mount(UserCardFormUserMail, { localVue, mocks })
|
||||
}
|
||||
|
||||
describe('mount', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = Wrapper()
|
||||
})
|
||||
|
||||
it('renders the component', () => {
|
||||
expect(wrapper.find('div#formusermail').exists()).toBeTruthy()
|
||||
})
|
||||
|
||||
it('renders the edit link', () => {
|
||||
expect(wrapper.find('a[href="#formusermail"]').exists()).toBeTruthy()
|
||||
})
|
||||
|
||||
it('renders the E-Mail form.change', () => {
|
||||
expect(wrapper.findAll('div.col').at(0).text()).toBe('E-Mail form.change')
|
||||
})
|
||||
|
||||
it('renders the E-Mail', () => {
|
||||
expect(wrapper.findAll('div.col').at(1).text()).toBe('E-Mail')
|
||||
})
|
||||
|
||||
it('renders the E-Mail Adress', () => {
|
||||
expect(wrapper.findAll('div.col').at(2).text()).toBe('user@example.org')
|
||||
})
|
||||
|
||||
describe('edit user data', () => {
|
||||
beforeEach(async () => {
|
||||
await wrapper.find('a[href="#formusermail"]').trigger('click')
|
||||
await flushPromises()
|
||||
await wrapper.findAll('input').at(0).setValue('test@example.org')
|
||||
await flushPromises()
|
||||
})
|
||||
|
||||
it('enter email in input field', () => {
|
||||
expect(wrapper.find('input').element.value).toBe('test@example.org')
|
||||
})
|
||||
|
||||
describe('error API send', () => {
|
||||
beforeEach(async () => {
|
||||
mockAPIcall.mockRejectedValue({
|
||||
message: 'Ouch!',
|
||||
})
|
||||
await wrapper.find('a[href="#formusermail"]').trigger('click')
|
||||
await flushPromises()
|
||||
})
|
||||
|
||||
it('send request with filled variables to the API', async () => {
|
||||
expect(mockAPIcall).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
variables: {
|
||||
sessionId: 1,
|
||||
email: 'user@example.org',
|
||||
newEmail: 'test@example.org',
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('error message is send to the window.alert', async () => {
|
||||
expect(window.alert).toBeCalledWith('Ouch!')
|
||||
})
|
||||
})
|
||||
|
||||
describe('successful API send', () => {
|
||||
beforeEach(async () => {
|
||||
mockAPIcall.mockResolvedValue({
|
||||
data: {
|
||||
updateUserInfos: {
|
||||
validValues: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
await wrapper.find('a[href="#formusermail"]').trigger('click')
|
||||
await flushPromises()
|
||||
})
|
||||
|
||||
it('send request with filled variables to the API', async () => {
|
||||
expect(mockAPIcall).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
variables: {
|
||||
sessionId: 1,
|
||||
email: 'user@example.org',
|
||||
newEmail: 'test@example.org',
|
||||
},
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('successful message is send to the window.alert', async () => {
|
||||
expect(window.alert).toBeCalledWith('changePassword success')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -32,7 +32,7 @@
|
||||
</b-card>
|
||||
</template>
|
||||
<script>
|
||||
import loginAPI from '../../../apis/loginAPI'
|
||||
import { updateUserInfos } from '../../../graphql/queries'
|
||||
|
||||
export default {
|
||||
name: 'FormUserMail',
|
||||
@ -44,17 +44,21 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
async onSubmit() {
|
||||
// console.log(this.data)
|
||||
const result = await loginAPI.changeEmailProfil(
|
||||
this.$store.state.sessionId,
|
||||
this.email,
|
||||
this.newEmail,
|
||||
)
|
||||
if (result.success) {
|
||||
this.$apollo
|
||||
.query({
|
||||
query: updateUserInfos,
|
||||
variables: {
|
||||
sessionId: this.$store.state.sessionId,
|
||||
email: this.$store.state.email,
|
||||
newEmail: this.newEmail,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
alert('changePassword success')
|
||||
} else {
|
||||
alert(result.result.message)
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
alert(error.message)
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ changePasswordProfileMock.mockReturnValue({ success: true })
|
||||
const toastSuccessMock = jest.fn()
|
||||
const toastErrorMock = jest.fn()
|
||||
|
||||
describe('UserCardFormUserPasswort', () => {
|
||||
describe('UserCard_FormUserPasswort', () => {
|
||||
let wrapper
|
||||
|
||||
const mocks = {
|
||||
|
||||
@ -95,14 +95,18 @@ describe('UserCard_FormUsername', () => {
|
||||
describe('successfull submit', () => {
|
||||
beforeEach(async () => {
|
||||
mockAPIcall.mockResolvedValue({
|
||||
message: 'error',
|
||||
data: {
|
||||
updateUserInfos: {
|
||||
validValues: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
await wrapper.find('input[placeholder="Username"]').setValue('username')
|
||||
await wrapper.find('form').trigger('submit')
|
||||
await flushPromises()
|
||||
})
|
||||
|
||||
it('calls the loginAPI', () => {
|
||||
it('calls the API', () => {
|
||||
expect(mockAPIcall).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
variables: {
|
||||
@ -135,14 +139,14 @@ describe('UserCard_FormUsername', () => {
|
||||
beforeEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
mockAPIcall.mockRejectedValue({
|
||||
message: 'Error',
|
||||
message: 'Ouch!',
|
||||
})
|
||||
await wrapper.find('input[placeholder="Username"]').setValue('username')
|
||||
await wrapper.find('form').trigger('submit')
|
||||
await flushPromises()
|
||||
})
|
||||
|
||||
it('calls the loginAPI', () => {
|
||||
it('calls the API', () => {
|
||||
expect(mockAPIcall).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
variables: {
|
||||
@ -155,7 +159,7 @@ describe('UserCard_FormUsername', () => {
|
||||
})
|
||||
|
||||
it('toasts an error message', () => {
|
||||
expect(toastErrorMock).toBeCalledWith('Error')
|
||||
expect(toastErrorMock).toBeCalledWith('Ouch!')
|
||||
})
|
||||
|
||||
it('renders an empty username', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user