import { describe, expect, it } from 'vitest';
import { isIosDevice, resolveStandaloneDisplayMode } from './installPrompt';

describe('isIosDevice', () => {
  it('detects iOS user agents', () => {
    expect(isIosDevice('Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1')).toBe(true);
    expect(isIosDevice('Mozilla/5.0 (iPad; CPU OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1')).toBe(true);
  });

  it('returns false for non-iOS user agents', () => {
    expect(isIosDevice('Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36')).toBe(false);
  });
});

describe('resolveStandaloneDisplayMode', () => {
  it('returns true when matchMedia says standalone', () => {
    expect(resolveStandaloneDisplayMode(true, false)).toBe(true);
  });

  it('returns true when navigator.standalone is true', () => {
    expect(resolveStandaloneDisplayMode(false, true)).toBe(true);
  });

  it('returns false when both are false', () => {
    expect(resolveStandaloneDisplayMode(false, false)).toBe(false);
  });
});
