mirror of
https://github.com/koel/koel
synced 2024-11-24 13:13:05 +00:00
feat(test): add UserEditForm tests
This commit is contained in:
parent
439882e761
commit
8a201b178f
2 changed files with 61 additions and 12 deletions
43
resources/assets/js/components/user/UserEditForm.spec.ts
Normal file
43
resources/assets/js/components/user/UserEditForm.spec.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
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 { alerts } from '@/utils'
|
||||
import UserEditForm from './UserEditForm.vue'
|
||||
|
||||
new class extends UnitTestCase {
|
||||
protected test () {
|
||||
it('edits a user', async () => {
|
||||
const updateMock = this.mock(userStore, 'update')
|
||||
const alertMock = this.mock(alerts, 'success')
|
||||
|
||||
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.')
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
|
@ -8,22 +8,28 @@
|
|||
|
||||
<main>
|
||||
<div class="form-row">
|
||||
<label>Name</label>
|
||||
<input v-model="updateData.name" v-koel-focus name="name" required title="Name" type="text">
|
||||
<label>
|
||||
Name
|
||||
<input v-model="updateData.name" v-koel-focus name="name" required title="Name" type="text">
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>Email</label>
|
||||
<input v-model="updateData.email" name="email" required title="Email" type="email">
|
||||
<label>
|
||||
Email
|
||||
<input v-model="updateData.email" name="email" required title="Email" type="email">
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>Password</label>
|
||||
<input
|
||||
v-model="updateData.password"
|
||||
autocomplete="new-password"
|
||||
name="password"
|
||||
placeholder="Leave blank for no changes"
|
||||
type="password"
|
||||
>
|
||||
<label>
|
||||
Password
|
||||
<input
|
||||
v-model="updateData.password"
|
||||
autocomplete="new-password"
|
||||
name="password"
|
||||
placeholder="Leave blank for no changes"
|
||||
type="password"
|
||||
>
|
||||
</label>
|
||||
<p class="help">Min. 10 characters. Should be a mix of characters, numbers, and symbols.</p>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
|
|
Loading…
Reference in a new issue