mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-20 23:04:06 +00:00
## Summary Automated initial change, cleaned up manually. Please check the screenshot changes. Includes a11y updates to icon buttons. Doesn't hit the buttons in Desktop. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7649-WIP-Component-The-Rest-of-the-PrimeVue-buttons-2ce6d73d365081d68e06f200f1321267) by [Unito](https://www.unito.io) --------- Co-authored-by: GitHub Action <action@github.com> Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import { mount } from '@vue/test-utils'
|
|
import PrimeVue from 'primevue/config'
|
|
import OverlayBadge from 'primevue/overlaybadge'
|
|
import Tooltip from 'primevue/tooltip'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { createI18n } from 'vue-i18n'
|
|
|
|
import SidebarIcon from './SidebarIcon.vue'
|
|
|
|
type SidebarIconProps = {
|
|
icon: string
|
|
selected: boolean
|
|
tooltip?: string
|
|
class?: string
|
|
iconBadge?: string | (() => string | null)
|
|
}
|
|
|
|
const i18n = createI18n({
|
|
legacy: false,
|
|
locale: 'en',
|
|
messages: {
|
|
en: {}
|
|
}
|
|
})
|
|
|
|
describe('SidebarIcon', () => {
|
|
const exampleProps: SidebarIconProps = {
|
|
icon: 'pi pi-cog',
|
|
selected: false
|
|
}
|
|
|
|
const mountSidebarIcon = (props: Partial<SidebarIconProps>, options = {}) => {
|
|
return mount(SidebarIcon, {
|
|
global: {
|
|
plugins: [PrimeVue, i18n],
|
|
directives: { tooltip: Tooltip },
|
|
components: { OverlayBadge }
|
|
},
|
|
props: { ...exampleProps, ...props },
|
|
...options
|
|
})
|
|
}
|
|
|
|
it('renders button element', () => {
|
|
const wrapper = mountSidebarIcon({})
|
|
expect(wrapper.find('button.side-bar-button').exists()).toBe(true)
|
|
})
|
|
|
|
it('renders icon', () => {
|
|
const wrapper = mountSidebarIcon({})
|
|
expect(wrapper.find('.side-bar-button-icon').exists()).toBe(true)
|
|
})
|
|
|
|
it('creates badge when iconBadge prop is set', () => {
|
|
const badge = '2'
|
|
const wrapper = mountSidebarIcon({ iconBadge: badge })
|
|
const badgeEl = wrapper.findComponent(OverlayBadge)
|
|
expect(badgeEl.exists()).toBe(true)
|
|
expect(badgeEl.find('.p-badge').text()).toEqual(badge)
|
|
})
|
|
|
|
it('shows tooltip on hover', async () => {
|
|
const tooltipShowDelay = 300
|
|
const tooltipText = 'Settings'
|
|
const wrapper = mountSidebarIcon({ tooltip: tooltipText })
|
|
|
|
const tooltipElBeforeHover = document.querySelector('[role="tooltip"]')
|
|
expect(tooltipElBeforeHover).toBeNull()
|
|
|
|
// Hover over the icon
|
|
await wrapper.trigger('mouseenter')
|
|
await new Promise((resolve) => setTimeout(resolve, tooltipShowDelay + 16))
|
|
|
|
const tooltipElAfterHover = document.querySelector('[role="tooltip"]')
|
|
expect(tooltipElAfterHover).not.toBeNull()
|
|
})
|
|
|
|
it('sets aria-label attribute when tooltip is provided', () => {
|
|
const tooltipText = 'Settings'
|
|
const wrapper = mountSidebarIcon({ tooltip: tooltipText })
|
|
expect(wrapper.attributes('aria-label')).toEqual(tooltipText)
|
|
})
|
|
})
|