import * as actions from '../tagAssociations'
import {
  ADD_TAG_ASSOCIATION,
  REMOVE_PENDING_ADDITION_TAG_ASSOCIATION,
  REMOVE_PENDING_DELETION_TAG_ASSOCIATION,
  REMOVE_TAG_ASSOCIATION,
  SET_PENDING_ADDITION_TAG_ASSOCIATIONS,
  SET_PENDING_DELETION_TAG_ASSOCIATIONS,
  SET_TAG_INPUT,
  SET_TAG_SUGGESTIONS
} from '@instructure/quiz-common/lib/constants'

describe('tagAssociations actions creators', () => {
  describe('#addTagAssociation', () => {
    it('returns a well-formed and correct action', () => {
      expect(actions.addTagAssociation('Item', '1', {id: '1', tag_value: '1', 'tag_id': '1'})).to.deep.equal({
        type: ADD_TAG_ASSOCIATION,
        payload: {
          entityType: 'Item',
          entityId: '1',
          tagAssociation: {
            id: '1',
            tag_value: '1',
            tag_id: '1'
          }
        }
      })
    })
  })

  describe('#removePendingAdditionTagAssociation', () => {
    it('returns a well-formed and correct action', () => {
      expect(actions.removePendingAdditionTagAssociation('Item', '1', 'tag-1')).to.deep.equal({
        type: REMOVE_PENDING_ADDITION_TAG_ASSOCIATION,
        payload: {
          entityType: 'Item',
          entityId: '1',
          tagValue: 'tag-1'
        }
      })
    })
  })

  describe('#removePendingDeletionTagAssociation', () => {
    it('returns a well-formed and correct action', () => {
      expect(actions.removePendingDeletionTagAssociation('Item', '1', '1')).to.deep.equal({
        type: REMOVE_PENDING_DELETION_TAG_ASSOCIATION,
        payload: {
          entityType: 'Item',
          entityId: '1',
          tagAssociationId: '1'
        }
      })
    })
  })

  describe('#removeTagAssociation', () => {
    it('returns a well-formed and correct action', () => {
      expect(actions.removeTagAssociation('Item', '1', '2')).to.deep.equal({
        type: REMOVE_TAG_ASSOCIATION,
        payload: {
          entityType: 'Item',
          entityId: '1',
          tagAssociationId: '2'
        }
      })
    })
  })

  describe('#setPendingAdditionTagAssociations', () => {
    it('returns a well-formed and correct action', () => {
      expect(actions.setPendingAdditionTagAssociations('Item', '1', [])).to.deep.equal({
        type: SET_PENDING_ADDITION_TAG_ASSOCIATIONS,
        payload: {
          entityType: 'Item',
          entityId: '1',
          tags: []
        }
      })
    })
  })

  describe('#setPendingDeletionTagAssociations', () => {
    it('returns a well-formed and correct action', () => {
      expect(actions.setPendingDeletionTagAssociations('Item', '1', [])).to.deep.equal({
        type: SET_PENDING_DELETION_TAG_ASSOCIATIONS,
        payload: {
          entityType: 'Item',
          entityId: '1',
          tags: []
        }
      })
    })
  })

  describe('#setTagInput', () => {
    it('returns a well-formed and correct action', () => {
      expect(actions.setTagInput('Item', '1', 'hello')).to.deep.equal({
        type: SET_TAG_INPUT,
        payload: {
          entityType: 'Item',
          entityId: '1',
          tagInput: 'hello'
        }
      })
    })
  })

  describe('#setTagSuggestions', () => {
    it('returns a well-formed and correct action', () => {
      expect(actions.setTagSuggestions('Item', '1', [], 'stuff')).to.deep.equal({
        type: SET_TAG_SUGGESTIONS,
        payload: {
          entityType: 'Item',
          entityId: '1',
          tags: [],
          text: 'stuff'
        }
      })
    })
  })
})
