import { createAppLocalVue } from '@/../tests/utils' // should be the first to implement default mocks
import App from '@/app/App.vue'
import { shallowMount } from '@vue/test-utils'
import { DASHBOARD_HOME } from '@/config/url-prefix'
import { loggedInStore, loggedOutStore } from '@/../tests/factories/auth-store'
import flushPromises from 'flush-promises'

describe('Dashboard - Routing', () => {
  let router
  let localVue
  let SecurityConfig

  beforeEach(async () => {
    jest.resetModules()
    jest.clearAllMocks()

    router = await require('@/router').default

    SecurityConfig = await require('@/config/security').default

    SecurityConfig.router = router

    localVue = createAppLocalVue()

    await flushPromises()
  })

  it('dose not route to dashboard when not logged in', async () => {
    let store = loggedOutStore()

    const wrapper = shallowMount(App, {
      localVue,
      router,
      store: store,
    })

    router.push(DASHBOARD_HOME).catch(() => {})

    await flushPromises()

    expect(wrapper.vm.$route.path).not.toBe(DASHBOARD_HOME)
  })

  it('dose route to dashboard when logged in', async () => {
    let store = loggedInStore()

    const wrapper = shallowMount(App, {
      localVue,
      router,
      store: store,
    })

    router.push(DASHBOARD_HOME)

    await flushPromises()

    expect(wrapper.vm.$route.path).toBe(DASHBOARD_HOME)
  })
})
