import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'

// Smoke-test helper. Vuetify components are left unresolved (Vue 3 renders
// unknown elements with their slot children, so text content is still
// present and nothing throws), which avoids standing up the whole Vuetify
// plugin in happy-dom. RouterLink is the one import that needs a router, so
// it's stubbed with a slot-rendering anchor.

export function freshPinia () {
  const pinia = createPinia()
  setActivePinia(pinia)
  return pinia
}

export function mountComponent (Component, { props = {}, pinia } = {}) {
  return mount(Component, {
    props,
    global: {
      plugins: pinia ? [pinia] : [],
      stubs: { RouterLink: { template: '<a><slot /></a>' } },
    },
  })
}
