2022-05-13 12:56:13 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import factory from '@/__tests__/factory'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-13 12:56:13 +00:00
|
|
|
import { fireEvent } from '@testing-library/vue'
|
|
|
|
import router from '@/router'
|
2022-07-22 16:31:07 +00:00
|
|
|
import { eventBus } from '@/utils'
|
|
|
|
import UserCard from './UserCard.vue'
|
2022-05-13 12:56:13 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-13 12:56:13 +00:00
|
|
|
private renderComponent (user: User) {
|
|
|
|
return this.render(UserCard, {
|
|
|
|
props: {
|
|
|
|
user
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
protected test () {
|
|
|
|
it('has different behaviors for current user', () => {
|
|
|
|
const user = factory<User>('user')
|
|
|
|
const { getByTitle, getByText } = this.actingAs(user).renderComponent(user)
|
|
|
|
|
|
|
|
getByTitle('This is you!')
|
2022-07-22 16:31:07 +00:00
|
|
|
getByText('Your Profile')
|
2022-05-13 12:56:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('edits user', async () => {
|
|
|
|
const user = factory<User>('user')
|
2022-07-22 16:31:07 +00:00
|
|
|
const emitMock = this.mock(eventBus, 'emit')
|
|
|
|
const { getByText } = this.renderComponent(user)
|
2022-05-13 12:56:13 +00:00
|
|
|
|
|
|
|
await fireEvent.click(getByText('Edit'))
|
|
|
|
|
2022-07-22 16:31:07 +00:00
|
|
|
expect(emitMock).toHaveBeenCalledWith('MODAL_SHOW_EDIT_USER_FORM', user)
|
2022-05-13 12:56:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('redirects to Profile screen if edit current user', async () => {
|
|
|
|
const mock = this.mock(router, 'go')
|
|
|
|
const user = factory<User>('user')
|
|
|
|
const { getByText } = this.actingAs(user).renderComponent(user)
|
|
|
|
|
2022-07-22 16:31:07 +00:00
|
|
|
await fireEvent.click(getByText('Your Profile'))
|
2022-05-13 12:56:13 +00:00
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalledWith('profile')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|