import { createAppLocalVue } from '@/../tests/utils' // should be the first to implement default mocks
import { shallowMount } from '@vue/test-utils'
import flushPromises from 'flush-promises'
import CustomDatePicker from '@/elements/common/components/CustomDatePicker'
import Datepicker from 'vuejs-datepicker'

const localVue = createAppLocalVue()

describe('Component - Element - CustomDatePicker', () => {
  it('Should show date picker', async () => {
    let value = '2019-8-26'
    const wrapper = shallowMount(CustomDatePicker, {
      localVue,
      propsData: {
        name: 'myDatePicker',
        initialView: 'year',
        value: value,
        disableDateRange: { to: 'Thu Jul 25 2019 12:09:22 GMT+0800 (Malaysia Time)' },
      },
      stubs: {
        datepicker: Datepicker,
      },
    })
    await flushPromises()

    expect(wrapper.vm.$refs.datePicker.name).toBe('myDatePicker')
    expect(wrapper.vm.$refs.datePicker.initialView).toBe('year')
    expect(wrapper.vm.$refs.datePicker.value).toBe('2019-8-26')
    expect(wrapper.vm.$refs.datePicker.disabledDates.to).toBe('Thu Jul 25 2019 12:09:22 GMT+0800 (Malaysia Time)')

    wrapper.vm.dateFormatter('2019-07-26T00:00:00Z')
    expect(wrapper.emitted('input')).toBeTruthy()
    expect(wrapper.emitted('input')[0][0]).toBe('2019-07-26')

    wrapper.vm.$children[0].$data.resetTypedDate = new Date('Fri Jul 26 2019 12:09:22 GMT+0800 (Malaysia Time)')
    expect(wrapper.element).toMatchSnapshot()
  })
})
