2022-12-07 13:31:38 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { screen } from '@testing-library/vue'
|
|
|
|
import { faHome } from '@fortawesome/free-solid-svg-icons'
|
2024-06-16 15:40:33 +00:00
|
|
|
import Component from './SidebarItem.vue'
|
|
|
|
import { eventBus } from '@/utils'
|
2022-12-07 13:31:38 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
2023-08-20 22:35:58 +00:00
|
|
|
protected test () {
|
2022-12-07 13:31:38 +00:00
|
|
|
it('renders', () => expect(this.renderComponent().html()).toMatchSnapshot())
|
|
|
|
|
|
|
|
it('activates when the screen matches', async () => {
|
|
|
|
this.renderComponent()
|
|
|
|
|
|
|
|
await this.router.activateRoute({
|
|
|
|
screen: 'Home',
|
2023-08-20 22:35:58 +00:00
|
|
|
path: '_'
|
2022-12-07 13:31:38 +00:00
|
|
|
})
|
|
|
|
|
2024-04-22 21:04:03 +00:00
|
|
|
expect(screen.getByTestId('sidebar-item').classList.contains('current')).toBe(true)
|
2022-12-07 13:31:38 +00:00
|
|
|
})
|
2024-06-16 15:40:33 +00:00
|
|
|
|
2024-08-18 15:06:06 +00:00
|
|
|
it('emits the sidebar toggle event when clicked', async () => {
|
|
|
|
const mock = this.mock(eventBus, 'emit')
|
2024-06-16 15:40:33 +00:00
|
|
|
this.renderComponent()
|
|
|
|
await this.user.click(screen.getByTestId('sidebar-item'))
|
|
|
|
|
|
|
|
expect(mock).toHaveBeenCalledWith('TOGGLE_SIDEBAR')
|
|
|
|
})
|
2022-12-07 13:31:38 +00:00
|
|
|
}
|
2024-04-23 21:01:27 +00:00
|
|
|
|
|
|
|
private renderComponent () {
|
2024-06-16 15:40:33 +00:00
|
|
|
return this.render(Component, {
|
2024-04-23 21:01:27 +00:00
|
|
|
props: {
|
|
|
|
icon: faHome,
|
|
|
|
href: '#',
|
|
|
|
screen: 'Home'
|
|
|
|
},
|
|
|
|
slots: {
|
|
|
|
default: 'Home'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-12-07 13:31:38 +00:00
|
|
|
}
|