import {
  buildMetaMaskMobileDappUrl,
  getWatchAssetBatchSize,
  isMobileBrowser,
  isWalletInAppBrowser,
} from '@/utils/walletProviderEnv'

describe('walletProviderEnv', () => {
  it('detects mobile user agents', () => {
    expect(isMobileBrowser('Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)')).toBe(true)
    expect(isMobileBrowser('Mozilla/5.0 (Windows NT 10.0; Win64; x64)')).toBe(false)
  })

  it('detects wallet in-app browsers', () => {
    expect(isWalletInAppBrowser('Mozilla/5.0 MetaMaskMobile')).toBe(true)
    expect(isWalletInAppBrowser('Mozilla/5.0 Chrome/120')).toBe(false)
  })

  it('builds MetaMask mobile dapp links without protocol prefix', () => {
    expect(buildMetaMaskMobileDappUrl('https://explorer.d-bis.org/wallet')).toBe(
      'https://metamask.app.link/dapp/explorer.d-bis.org/wallet',
    )
  })

  it('uses smaller watch-asset batches on mobile contexts', () => {
    expect(getWatchAssetBatchSize(true)).toBe(2)
    expect(getWatchAssetBatchSize(false)).toBe(Number.POSITIVE_INFINITY)
  })
})
