2022-07-22 16:43:32 +00:00
|
|
|
import { ref } from 'vue'
|
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { UserKey } from '@/symbols'
|
|
|
|
import { fireEvent, waitFor } from '@testing-library/vue'
|
|
|
|
import { userStore } from '@/stores'
|
|
|
|
import UserEditForm from './UserEditForm.vue'
|
2022-07-26 14:46:02 +00:00
|
|
|
import { MessageToasterStub } from '@/__tests__/stubs'
|
2022-07-22 16:43:32 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected test () {
|
|
|
|
it('edits a user', async () => {
|
|
|
|
const updateMock = this.mock(userStore, 'update')
|
2022-07-26 14:46:02 +00:00
|
|
|
const alertMock = this.mock(MessageToasterStub.value, 'success')
|
2022-07-22 16:43:32 +00:00
|
|
|
|
|
|
|
const user = ref(factory<User>('user', { name: 'John Doe' }))
|
|
|
|
|
|
|
|
const { getByLabelText, getByRole } = this.render(UserEditForm, {
|
|
|
|
global: {
|
|
|
|
provide: {
|
|
|
|
[UserKey]: [user]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
await fireEvent.update(getByLabelText('Name'), 'Jane Doe')
|
|
|
|
await fireEvent.update(getByLabelText('Password'), 'new-password-duck')
|
|
|
|
await fireEvent.click(getByRole('button', { name: 'Update' }))
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(updateMock).toHaveBeenCalledWith(user.value, {
|
|
|
|
name: 'Jane Doe',
|
|
|
|
email: user.value.email,
|
|
|
|
is_admin: user.value.is_admin,
|
|
|
|
password: 'new-password-duck'
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(alertMock).toHaveBeenCalledWith('User profile updated.')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|