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

describe('Share Qr Link - 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 when not logged in', async () => {
    let store = loggedOutStore()

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

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

    await flushPromises()

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

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

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

    router.push(SHARE_QR_CODE)

    await flushPromises()

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