2022-07-22 16:15:50 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-07-22 16:15:50 +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 AddUserForm from './AddUserForm.vue'
|
2022-07-22 16:15:50 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected test () {
|
|
|
|
it('creates a new user', async () => {
|
|
|
|
const storeMock = this.mock(userStore, 'store')
|
2022-11-19 18:04:21 +00:00
|
|
|
const alertMock = this.mock(MessageToasterStub.value, 'success')
|
2022-07-22 16:15:50 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
this.render(AddUserForm)
|
2022-07-22 16:15:50 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.type(screen.getByRole('textbox', { name: 'Name' }), 'John Doe')
|
|
|
|
await this.type(screen.getByRole('textbox', { name: 'Email' }), 'john@doe.com')
|
2024-04-22 21:04:03 +00:00
|
|
|
await this.type(screen.getByTitle('Password'), 'secret-password')
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('checkbox'))
|
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Save' }))
|
2022-07-22 16:15:50 +00:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(storeMock).toHaveBeenCalledWith({
|
|
|
|
name: 'John Doe',
|
|
|
|
email: 'john@doe.com',
|
|
|
|
password: 'secret-password',
|
|
|
|
is_admin: true
|
|
|
|
})
|
2022-11-19 18:04:21 +00:00
|
|
|
|
|
|
|
expect(alertMock).toHaveBeenCalledWith('New user "John Doe" created.')
|
2022-07-22 16:15:50 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|