import { media, onPhone, onTablet } from '../windowChecks'

describe('windowChecks', () => {
  const phoneQueryString = media['phone-break-point']
  const tabletQueryString = media['tablet-break-point']
  const matchingReturn = {matches: true}
  const notMatchingReturn = {matches: false}
  const windowMatching = (matches) => {
    const matchMediaStub = sinon.stub()
    matchMediaStub.withArgs(phoneQueryString).returns(
      matches.phone ? matchingReturn : notMatchingReturn
    )
    matchMediaStub.withArgs(tabletQueryString).returns(
      matches.tablet ? matchingReturn : notMatchingReturn
    )
    return {matchMedia: matchMediaStub}
  }

  describe('onPhone', () => {
    it('returns true if window matches with phone break point query string', () => {
      const fakeWindow = windowMatching({phone: true})
      const isOnPhone = onPhone(fakeWindow)
      expect(isOnPhone).to.be.true()
    })
    it('returns false if window does not match phone break point query string', () => {
      const fakeWindow = windowMatching({phone: false})
      const isOnPhone = onPhone(fakeWindow)
      expect(isOnPhone).to.be.false()
    })
  })

  describe('onTablet', () => {
    it('returns true if window matches tablet query string and not phone query string', () => {
      const fakeWindow = windowMatching({phone: false, tablet: true})
      const isOnTablet = onTablet(fakeWindow)
      expect(isOnTablet).to.be.true()
    })
    it('returns false if window matches phone query string and tablet query string', () => {
      const fakeWindow = windowMatching({phone: true, tablet: true})
      const isOnTablet = onTablet(fakeWindow)
      expect(isOnTablet).to.be.false()
    })
    it('returns false if window matches neither phone or tablet query string', () => {
      const fakeWindow = windowMatching({phone: false, tablet: false})
      const isOnTablet = onTablet(fakeWindow)
      expect(isOnTablet).to.be.false()
    })
  })
})
