mirror of
https://github.com/koel/koel
synced 2024-11-10 14:44:13 +00:00
feat(test): add UserBadge component tests
This commit is contained in:
parent
a1732a1915
commit
07ee6f59e8
2 changed files with 30 additions and 0 deletions
27
resources/assets/js/components/user/UserBadge.spec.ts
Normal file
27
resources/assets/js/components/user/UserBadge.spec.ts
Normal 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()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>`;
|
Loading…
Reference in a new issue