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

describe('Eshop Checkout - Routing', () => {
  let store
  let localVue
  let router
  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('Should not render checkout component when logged out', async () => {
    store = loggedOutStore()

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

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

    await flushPromises()

    expect(wrapper.vm.$route.path).not.toMatch(ESHOP_CHECKOUT_SELECT_SIZES)
  })

  it('Should render checkout component when logged in', async () => {
    store = loggedInStore(appStore)

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

    router.push(ESHOP_CHECKOUT_SELECT_SIZES)

    await flushPromises()

    expect(wrapper.vm.$route.path).toMatch(ESHOP_CHECKOUT_SELECT_SIZES)

    expect(wrapper.isVueInstance()).toBeTruthy()
  })
})
