koel/resources/assets/js/components/user/AddUserForm.spec.ts
2022-11-18 20:37:10 +01:00

30 lines
1,016 B
TypeScript

import { expect, it } from 'vitest'
import UnitTestCase from '@/__tests__/UnitTestCase'
import { fireEvent, waitFor } from '@testing-library/vue'
import { userStore } from '@/stores'
import AddUserForm from './AddUserForm.vue'
new class extends UnitTestCase {
protected test () {
it('creates a new user', async () => {
const storeMock = this.mock(userStore, 'store')
const { getByLabelText, getByRole } = this.render(AddUserForm)
await fireEvent.update(getByLabelText('Name'), 'John Doe')
await fireEvent.update(getByLabelText('Email'), 'john@doe.com')
await fireEvent.update(getByLabelText('Password'), 'secret-password')
await fireEvent.click(getByRole('checkbox'))
await fireEvent.click(getByRole('button', { name: 'Save' }))
await waitFor(() => {
expect(storeMock).toHaveBeenCalledWith({
name: 'John Doe',
email: 'john@doe.com',
password: 'secret-password',
is_admin: true
})
})
})
}
}