import {
  ADD_ALERT,
  REMOVE_ALERT,
  DEFAULT_ALERT_TIME
} from '@instructure/quiz-common/lib/constants'

import {
  addInfo,
  addError,
  addSuccess,
  removeAlert,
  screenreaderNotification
} from '../alerts'

describe('alert action creators', () => {
  const actionWellFormed = (actionCreator, variant, removeIn = DEFAULT_ALERT_TIME) => {
    const message = 'this is the message to show'
    const errorAction = actionCreator(message)

    expect(errorAction.type, 'bad type')
      .to.be.equal(ADD_ALERT)

    expect(errorAction.payload.message, 'bad payload message')
      .to.be.equal(message)

    expect(errorAction.payload.variant, 'bad payload variant')
      .to.be.equal(variant)

    expect(errorAction.payload.removeIn, 'bad payload removeIn')
      .to.be.equal(removeIn)

    expect(errorAction.payload.uuid, 'bad uuid')
      .to.not.be.undefined()
  }

  it('returns a well-formed add error action', () => {
    actionWellFormed(addError, 'error')
  })

  it('returns a well-formed add success action', () => {
    actionWellFormed(addSuccess, 'success')
  })

  it('returns a well-formed add info action', () => {
    actionWellFormed(addInfo, 'info')
  })

  it('returns a well-formed screenreader action', () => {
    actionWellFormed(screenreaderNotification, 'screenreader', 2000)
  })

  it('returns a well-formed remove alert action', () => {
    const errorID = '12345'
    const removeAlertAction = removeAlert(errorID)

    expect(removeAlertAction)
      .to.deep.equal({
        type: REMOVE_ALERT,
        payload: {uuid: errorID}
      })
  })
})
