import BmsLink from '@/components/navigation/BmsLink.vue';
import { mount, RouterLinkStub } from '@vue/test-utils';
import { expect } from 'vitest';

describe('BmsLink', () => {
  it('renders an external link when "to" is an external URL', () => {
    const wrapper = mount(BmsLink, {
      global: {
        stubs: {
          UiButton: true,
          'router-link': RouterLinkStub,
          teleport: true,
        },
      },
      props: {
        to: { name: 'route' },
        classes: 'test',
      },
    } as any);
    wrapper.find('a.internal-link').exists();
  });

  it('renders a router-link for internal links', () => {
    const wrapper = mount(BmsLink, {
      props: {
        to: 'https://example.com',
        classes: 'test',
      },
    } as any);
    wrapper.find('a.external-link').exists();
    expect(wrapper.find('a.external-link').attributes('target')).toBe('_self');
  });

  it('renders a router-link with particular target for link', () => {
    const wrapper = mount(BmsLink, {
      props: {
        to: 'https://example.com',
        classes: 'test',
        target: '_blank',
      },
    } as any);
    wrapper.find('a.external-link').exists();
    expect(wrapper.find('a.external-link').attributes('target')).toBe('_blank');
  });
});
