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'
|
2022-11-27 15:29:29 +00:00
|
|
|
import { ModalContextKey } from '@/symbols'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-07-22 16:43:32 +00:00
|
|
|
import { userStore } from '@/stores'
|
2022-11-19 18:04:21 +00:00
|
|
|
import { MessageToasterStub } from '@/__tests__/stubs'
|
2022-08-10 14:56:01 +00:00
|
|
|
import EditUserForm from './EditUserForm.vue'
|
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-11-19 18:04:21 +00:00
|
|
|
const alertMock = this.mock(MessageToasterStub.value, 'success')
|
2022-07-22 16:43:32 +00:00
|
|
|
|
2024-06-01 18:02:27 +00:00
|
|
|
const user = ref(factory('user', { name: 'John Doe' }))
|
2022-07-22 16:43:32 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.render(EditUserForm, {
|
2022-07-22 16:43:32 +00:00
|
|
|
global: {
|
|
|
|
provide: {
|
2022-11-27 15:29:29 +00:00
|
|
|
[<symbol>ModalContextKey]: [ref({ user })]
|
2022-07-22 16:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.type(screen.getByRole('textbox', { name: 'Name' }), 'Jane Doe')
|
2024-04-22 21:04:03 +00:00
|
|
|
await this.type(screen.getByTitle('Password'), 'new-password-duck')
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Update' }))
|
2022-07-22 16:43:32 +00:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(updateMock).toHaveBeenCalledWith(user.value, {
|
|
|
|
name: 'Jane Doe',
|
|
|
|
email: user.value.email,
|
|
|
|
is_admin: user.value.is_admin,
|
|
|
|
password: 'new-password-duck'
|
|
|
|
})
|
2022-11-19 18:04:21 +00:00
|
|
|
|
|
|
|
expect(alertMock).toHaveBeenCalledWith('User profile updated.')
|
2022-07-22 16:43:32 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|