import {
  featureOn,
  ifFeature,
  setFeatures,
  unsetFeatures,
  withTestFeatures
} from '../featureCheck'

import store from '../../../reduxStore'

describe('feature check', () => {
  withTestFeatures(['aFeatureThatIsSet'])

  describe('featureOn', () => {
    it('returns true if a feature is in the store', () => {
      const featureIsOn = featureOn('aFeatureThatIsSet')
      expect(featureIsOn).to.be.true()
    })
    it('returns false if a feature is not in the store', () => {
      const featureIsOn = featureOn('aFeatureThatIsNotSet')
      expect(featureIsOn).to.be.false()
    })
  })

  describe('ifFeature', () => {
    const returnIfOn = 'on'
    const returnIfOff = 'off'
    it('returns the second arg if a feature is in the store', () => {
      const returnedVal = ifFeature('aFeatureThatIsSet', returnIfOn, returnIfOff)
      expect(returnedVal).to.be.equal(returnIfOn)
    })
    it('returns the third arg if a feature is not the store', () => {
      const returnedVal = ifFeature('aFeatureThatIsNotSet', returnIfOn, returnIfOff)
      expect(returnedVal).to.be.equal(returnIfOff)
    })
  })

  describe('setting features', () => {
    const featureName ='foobarFeature'

    it('sets features', () => {
      setFeatures([featureName])
      expect(store.dispatch).to.be.calledWithMatch({ payload: [featureName] })
    })

    it('unsets features', () => {
      unsetFeatures([featureName])
      expect(store.dispatch).to.be.calledWithMatch({ payload: [featureName] })
    })
  })
})
