import { mount } from '@vue/test-utils' import { defineComponent, h } from 'vue' import { describe, expect, it, vi } from 'vitest' import ActionItemInternal from '../../components/internal/ActionItemInternal.vue' function createRouterLinkStub(navigate = vi.fn()) { return defineComponent({ name: 'RouterLinkStub', props: { to: [String, Object], custom: Boolean, }, setup(props, { slots }) { return () => props.custom ? slots.default?.({ href: props.to, navigate }) : h('a', { href: props.to, onClick: navigate }, slots.default?.()) }, }) } describe('ActionItemInternal', () => { it('renders a normal button action and emits clicks', async () => { const wrapper = mount(ActionItemInternal, { slots: { default: 'Run' }, }) const button = wrapper.get('button') expect(button.attributes('type')).toBe('button') await button.trigger('click') expect(wrapper.emitted('click')).toHaveLength(1) }) it('renders disabled href actions without navigating or emitting', async () => { const wrapper = mount(ActionItemInternal, { props: { href: '/disabled', disabled: true, }, slots: { default: 'Disabled' }, }) const link = wrapper.get('a') expect(link.attributes('href')).toBeUndefined() expect(link.attributes('aria-disabled')).toBe('true') await link.trigger('click') expect(wrapper.emitted('click')).toBeUndefined() }) it('renders router actions through router-link and navigates after emitting', async () => { const navigate = vi.fn() const wrapper = mount(ActionItemInternal, { props: { to: '/settings' }, slots: { default: 'Settings' }, global: { stubs: { 'router-link': createRouterLinkStub(navigate), }, }, }) const link = wrapper.get('a') expect(link.attributes('href')).toBe('/settings') await link.trigger('click') expect(wrapper.emitted('click')).toHaveLength(1) expect(navigate).toHaveBeenCalledTimes(1) }) it('renders disabled router actions without href, navigation, or emitted clicks', async () => { const navigate = vi.fn() const wrapper = mount(ActionItemInternal, { props: { to: '/settings', disabled: true, }, slots: { default: 'Settings' }, global: { stubs: { 'router-link': createRouterLinkStub(navigate), }, }, }) const link = wrapper.get('a') expect(link.attributes('href')).toBeUndefined() expect(link.attributes('aria-disabled')).toBe('true') expect(link.attributes('tabindex')).toBe('-1') await link.trigger('click') expect(wrapper.emitted('click')).toBeUndefined() expect(navigate).not.toHaveBeenCalled() }) })