feat(test): add UserBadge component tests

This commit is contained in:
Phan An 2022-05-15 17:32:38 +02:00
parent a1732a1915
commit 07ee6f59e8
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
2 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,27 @@
import UnitTestCase from '@/__tests__/UnitTestCase'
import factory from '@/__tests__/factory'
import { expect, it } from 'vitest'
import { eventBus } from '@/utils'
import { fireEvent } from '@testing-library/vue'
import UserBadge from './UserBadge.vue'
new class extends UnitTestCase {
private renderComponent () {
return this.actingAs(factory<User>('user', {
name: 'John Doe'
})).render(UserBadge)
}
protected test () {
it('renders', () => expect(this.renderComponent().html()).toMatchSnapshot())
it('logs out', async () => {
const mock = this.mock(eventBus, 'emit')
const { getByTestId } = this.renderComponent()
await fireEvent.click(getByTestId('btn-logout'))
expect(mock).toHaveBeenCalledOnce()
})
}
}

View file

@ -0,0 +1,3 @@
// Vitest Snapshot v1
exports[`renders 1`] = `<span class="profile" id="userBadge"><a class="view-profile" data-testid="view-profile-link" href="/#!/profile" title="View/edit user profile"><img alt="Avatar of John Doe" src="https://gravatar.com/foo" class="avatar"><span class="name">John Doe</span></a><a title="Log out" class="logout control" data-testid="btn-logout" href="" role="button"><i class="fa fa-sign-out"></i></a></span>`;