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 { REPORT } from '@/config/url-prefix'
import { loggedInStore, loggedOutStore } from '@/../tests/factories/auth-store'
import flushPromises from 'flush-promises'
import { store as appStore } from '@/store'

describe('Report - 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 bonus report when not logged in', async () => {
    let store = loggedOutStore()

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

    router.push(REPORT + '/bonus').catch(() => {})

    await flushPromises()

    expect(wrapper.vm.$route.path).not.toBe(REPORT + '/bonus')
  })

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

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

    router.push(REPORT + '/bonus')

    await flushPromises()

    expect(wrapper.vm.$route.path).toBe(REPORT + '/bonus')
  })

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

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

    router.push(REPORT + '/report').catch(() => {})

    await flushPromises()

    expect(wrapper.vm.$route.path).not.toBe(REPORT + '/report')
  })

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

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

    router.push(REPORT + '/report')

    await flushPromises()

    expect(wrapper.vm.$route.path).toBe(REPORT + '/report')
  })
})
