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 pdfViewerModal from '@/app/_global/components/elements/pdfViewerModal'
import embed from 'bootstrap-vue/es/components/embed/embed'

const localVue = createAppLocalVue()

describe('Component - Element - PdfViewerModal', () => {
  it('Should display title and PDF', async () => {
    const wrapper = shallowMount(pdfViewerModal, {
      localVue,
      propsData: {
        title: 'Title',
        pdfLink: 'https://dummy.pdf',
        hash: '3213123',
      },
    })

    await flushPromises()

    expect(wrapper.element).toMatchSnapshot()
    expect(wrapper.vm.$refs.title.innerHTML.trim()).toBe('Title')
    expect(wrapper.find('embed').attributes('src')).toBe('https://dummy.pdf?hash=3213123')
  })

  it('Should generate a hash', async () => {
    const wrapper = shallowMount(pdfViewerModal, {
      localVue,
      propsData: {
        title: 'Title',
        pdfLink: 'https://dummy.pdf',
      },
    })

    await flushPromises()

    expect(wrapper.vm.$refs.title.innerHTML.trim()).toBe('Title')
    expect(wrapper.find('embed').attributes('src')).toContain('https://dummy.pdf?hash=')
  })
})
