import {
  describe,
  expect,
  it,
  vi
} from 'vitest';

import { resolveMobileAdapter } from './mobile-capacitor-adapter.rules';

describe('resolveMobileAdapter', () => {
  it('returns the web adapter on electron and browser shells', async () => {
    const loadCapacitorAdapter = vi.fn(() => Promise.resolve('capacitor'));

    await expect(resolveMobileAdapter('electron', 'web', loadCapacitorAdapter)).resolves.toBe('web');
    await expect(resolveMobileAdapter('browser', 'web', loadCapacitorAdapter)).resolves.toBe('web');
    expect(loadCapacitorAdapter).not.toHaveBeenCalled();
  });

  it('loads the Capacitor adapter only on native mobile shells', async () => {
    const loadCapacitorAdapter = vi.fn(() => Promise.resolve('capacitor'));

    await expect(resolveMobileAdapter('capacitor', 'web', loadCapacitorAdapter)).resolves.toBe('capacitor');
    expect(loadCapacitorAdapter).toHaveBeenCalledTimes(1);
  });
});
