import { afterEach, describe, expect, it } from 'vitest'; import { isApplePaySupported } from './isApplePaySupported'; describe('isApplePaySupported', () => { const originalUserAgent = navigator.userAgent; afterEach(() => { Object.defineProperty(navigator, 'userAgent', { value: originalUserAgent, configurable: true, }); }); it('should return true for iPhone', () => { Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1', configurable: true, }); expect(isApplePaySupported()).toBe(true); }); it('should return true for Safari on macOS', () => { Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15', configurable: true, }); expect(isApplePaySupported()).toBe(true); }); it('should return false for Chrome on macOS', () => { Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36', configurable: true, }); expect(isApplePaySupported()).toBe(false); }); it('should return false for Edge on macOS', () => { Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67', configurable: true, }); expect(isApplePaySupported()).toBe(false); }); it('should return false for non-Apple devices', () => { Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36', configurable: true, }); expect(isApplePaySupported()).toBe(false); }); });