koel/resources/assets/js/components/invitation/AcceptInvivation.spec.ts

39 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-02-25 19:32:53 +00:00
import { screen, waitFor } from '@testing-library/vue'
import { expect, it } from 'vitest'
import UnitTestCase from '@/__tests__/UnitTestCase'
import AcceptInvitation from './AcceptInvitation.vue'
import { invitationService } from '@/services'
import factory from '@/__tests__/factory'
new class extends UnitTestCase {
protected test () {
it('accepts invitation', async () => {
const getProspectMock = this.mock(invitationService, 'getUserProspect')
.mockResolvedValue(factory.states('prospect')<User>('user'))
const acceptMock = this.mock(invitationService, 'accept').mockResolvedValue({
token: 'my-api-token',
'audio-token': 'my-audio-token'
})
await this.router.activateRoute({
2024-04-23 21:01:27 +00:00
path: '_',
screen: 'Invitation.Accept'
}, {
2024-02-25 19:32:53 +00:00
token: 'my-token'
})
this.render(AcceptInvitation)
await waitFor(() => expect(getProspectMock).toHaveBeenCalledWith('my-token'))
await this.tick(2)
await this.user.type(screen.getByTestId('name'), 'Bruce Dickinson')
await this.user.type(screen.getByTestId('password'), 'top-secret')
await this.user.click(screen.getByTestId('submit'))
2024-02-25 19:32:53 +00:00
expect(acceptMock).toHaveBeenCalledWith('my-token', 'Bruce Dickinson', 'top-secret')
})
}
}