import RceImageImportModal from '../presenter'
import { FILE_UPLOAD_SUCCESS } from '@instructure/quiz-common/lib/constants'

describe('RceImageImportModal', () => {
  const setUploadStatusStub = sinon.stub()
  const props = {
    setUploadStatus: setUploadStatusStub
  }
  const testbed = createTestbed(withContext(RceImageImportModal), props)

  afterEach(() => {
    setUploadStatusStub.resetHistory()
  })

  it('should render', () => {
    testbed.render()
    const component = testbed.findChildByType(RceImageImportModal)
    expect(component).to.not.be.undefined()
  })

  describe('#successWrapper', () => {
    it('calls the successAction with the correct args', () => {
      const subject = testbed.render()
      const successActionStub = sinon.stub()
      const fakeUrl = 'myfakeUrl.com'
      const fileType = 'image/png'
      subject.refs.composedComponent.successWrapper(successActionStub, fileType)(fakeUrl)
      expect(successActionStub).to.be.calledWith(fakeUrl, fileType)
    })

    it('sets the upload status to success', () => {
      testbed.render()
      testbed.subject.refs.composedComponent.successWrapper(() => {})()
      expect(setUploadStatusStub).to.be.calledWith(FILE_UPLOAD_SUCCESS)
    })
  })

  describe('a11y tests', () => {
    it('should meet a11y standards', (done) => {
      testbed.render()
      testbed.checkA11yStandards(done)
    })
  })
})
