import { it, describe, expect } from 'vitest'
import { shallowMount } from '@vue/test-utils'
import UploadLoader from '../../../../components/upload/UploadLoader.vue'
import i18n from '../../config'

describe('Template', () => {
  describe('Props', () => {
    it('should have default props', () => {
      const wrapper = shallowMount(UploadLoader, {
        global: {
          plugins: [i18n]
        }
      })
      expect(wrapper.vm.loadPercentage).toBe('0%')
      expect(wrapper.vm.loadTextSize).toBe('0 Mo')
      expect(wrapper.vm.isLoaded).toBe(false)
      expect(wrapper.vm.picturesCount).toBe(null)
      expect(wrapper.vm.uploadedSequences).toStrictEqual([])
    })
  })
  describe('When the component have a percentage equal to 100%', () => {
    it('should have a button to do a new upload', () => {
      const wrapper = shallowMount(UploadLoader, {
        global: {
          plugins: [i18n]
        },
        props: {
          loadPercentage: '100%'
        }
      })
      expect(wrapper.html()).contains('button-stub')
      expect(wrapper.html()).contains('text="Nouvel envoi"')
    })
  })
  describe('When the component have an uploaded sequence', () => {
    it('should render the uploaded sequences information', () => {
      const wrapper = shallowMount(UploadLoader, {
        global: {
          plugins: [i18n]
        },
        props: {
          uploadedSequences: [{ pictureSize: '2345 Mo' }],
          loadTextSize: '2345 Mo',
          loadPercentage: '97%'
        }
      })
      expect(wrapper.html()).contains('Transfert en cours...')
      expect(wrapper.html()).contains('2345 Mo/2345 Mo')
    })
    describe('When the loading is completed', () => {
      it('should render the loading ended information', () => {
        const wrapper = shallowMount(UploadLoader, {
          global: {
            plugins: [i18n]
          },
          props: {
            uploadedSequences: [{ pictureSize: '2345 Mo' }],
            loadTextSize: '2345 Mo',
            loadPercentage: '100%'
          }
        })
        expect(wrapper.html()).contains('text="Nouvel envoi"')
        expect(wrapper.html()).contains('Transfert terminé !')
        expect(wrapper.html()).contains('2345 Mo/2345 Mo')
      })
    })
  })
})
