import { USidebar } from './USidebar'
import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import { UApp } from '../UApp/UApp'
import { ref, shallowRef } from 'vue'
describe('USidebar', () => {
it('should render correctly', () => {
const wrapper = mount({
template: `
`,
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should render correctly with primary variant', () => {
const wrapper = mount({
template: `
`,
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should render correctly with gray variant', () => {
const wrapper = mount({
template: `
`,
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should render correctly with light theme', () => {
const wrapper = mount({
template: `
`,
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should render correctly with dark theme', () => {
const wrapper = mount({
template: `
`,
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should render correctly with left location', () => {
const wrapper = mount({
template: `
`,
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should render correctly with right location', () => {
const wrapper = mount({
template: `
`,
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should render correctly with top location', () => {
const wrapper = mount({
template: `
`,
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should render correctly with border', () => {
const wrapper = mount({
template: `
`,
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should render correctly with elevation', () => {
const wrapper = mount({
template: `
`,
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should render correctly permanent sidebar', async () => {
const wrapper = mount({
components: {
USidebar,
UApp,
},
template: `
`,
setup() {
const drawer = ref(false)
const isHovering = shallowRef(false)
return { drawer, isHovering }
},
})
expect(wrapper.html()).toMatchSnapshot()
})
})
describe('USidebar events', () => {
it('should change isHovering on hover with expand-on-hover', async () => {
const wrapper = mount({
components: {
USidebar,
UApp,
},
template: `
`,
setup() {
const drawer = ref(false)
const isHovering = shallowRef(false)
return { drawer, isHovering }
},
})
expect(wrapper.html()).toMatchSnapshot()
const sidebar = wrapper.findComponent(USidebar)
await wrapper.find('.sidebar-drawer').trigger('mouseenter')
expect(sidebar.vm.isHovering).toBe(true)
await wrapper.find('.sidebar-drawer').trigger('mouseleave')
expect(sidebar.vm.isHovering).toBe(false)
})
it('should open by click on toggle button', async () => {
const wrapper = mount(
{
components: {
USidebar,
UApp,
},
template: `
toggle
`,
setup() {
const drawer = ref(false)
const toggleDrawer = () => {
drawer.value = !drawer.value
}
return { drawer, toggleDrawer }
},
},
{ props: {} }
)
await wrapper.find('.toggle').trigger('click')
expect(wrapper.vm.drawer).toBe(true)
})
it('should emit update:rail event when isHovering is set to true', async () => {
const wrapper = mount(
{
components: {
USidebar,
UApp,
},
template: `
`,
},
{
props: {
'onUpdate:rail': (e) => {
wrapper.setProps({ rail: e })
},
},
}
)
const sidebarComponent = wrapper.findComponent(USidebar)
const sidebar = wrapper.find('.sidebar-drawer')
await sidebar.trigger('mouseenter')
expect(sidebarComponent.emitted('update:rail')).toBeTruthy()
expect(sidebarComponent.vm.rail).toBe(true)
})
})