2024-01-09 15:38:12 +00:00
|
|
|
import factory from 'factoria'
|
|
|
|
import { expect, it } from 'vitest'
|
2024-01-18 11:13:05 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2024-01-09 15:38:12 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2024-01-18 11:13:05 +00:00
|
|
|
import { authService } from '@/services'
|
2024-01-09 15:38:12 +00:00
|
|
|
import { MessageToasterStub } from '@/__tests__/stubs'
|
|
|
|
import ProfileForm from './ProfileForm.vue'
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected test () {
|
|
|
|
it('updates profile', async () => {
|
2024-01-18 11:13:05 +00:00
|
|
|
const updateMock = this.mock(authService, 'updateProfile')
|
2024-01-09 15:38:12 +00:00
|
|
|
const alertMock = this.mock(MessageToasterStub.value, 'success')
|
|
|
|
|
2024-06-01 18:02:27 +00:00
|
|
|
this.renderComponent(factory('user', {
|
2024-10-13 17:37:01 +00:00
|
|
|
avatar: 'https://gravatar.com/foo',
|
2024-03-19 22:48:12 +00:00
|
|
|
}))
|
2024-01-09 15:38:12 +00:00
|
|
|
|
|
|
|
await this.type(screen.getByTestId('currentPassword'), 'old-password')
|
|
|
|
await this.type(screen.getByTestId('email'), 'koel@example.com')
|
|
|
|
await this.type(screen.getByTestId('name'), 'Koel User')
|
|
|
|
await this.type(screen.getByTestId('newPassword'), 'new-password')
|
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Save' }))
|
|
|
|
|
|
|
|
expect(updateMock).toHaveBeenCalledWith({
|
|
|
|
name: 'Koel User',
|
|
|
|
email: 'koel@example.com',
|
|
|
|
current_password: 'old-password',
|
|
|
|
new_password: 'new-password',
|
2024-10-13 17:37:01 +00:00
|
|
|
avatar: 'https://gravatar.com/foo',
|
2024-01-09 15:38:12 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
expect(alertMock).toHaveBeenCalledWith('Profile updated.')
|
|
|
|
})
|
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
private renderComponent (user: User) {
|
|
|
|
return this.be(user).render(ProfileForm)
|
|
|
|
}
|
2024-01-09 15:38:12 +00:00
|
|
|
}
|