2022-05-15 15:32:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import factory from '@/__tests__/factory'
|
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import { eventBus } from '@/utils'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-05-15 15:32:38 +00:00
|
|
|
import UserBadge from './UserBadge.vue'
|
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
private renderComponent () {
|
2024-01-15 22:26:50 +00:00
|
|
|
return this.be(factory<User>('user', {
|
2022-05-15 15:32:38 +00:00
|
|
|
name: 'John Doe'
|
|
|
|
})).render(UserBadge)
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('renders', () => expect(this.renderComponent().html()).toMatchSnapshot())
|
|
|
|
|
|
|
|
it('logs out', async () => {
|
2022-07-22 16:27:29 +00:00
|
|
|
const emitMock = this.mock(eventBus, 'emit')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.renderComponent()
|
2022-05-15 15:32:38 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Log out' }))
|
2022-05-15 15:32:38 +00:00
|
|
|
|
2022-07-22 16:27:29 +00:00
|
|
|
expect(emitMock).toHaveBeenCalledWith('LOG_OUT')
|
2022-05-15 15:32:38 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|