import { afterEach, expect, test } from 'vitest';
import { getAMapConfig, isAMapConfigured } from './appConfig';

afterEach(() => {
  delete window.__LINGNIU_APP_CONFIG__;
});

test('reads AMap runtime config from app config script', () => {
  window.__LINGNIU_APP_CONFIG__ = {
    amapWebJsKey: 'runtime-key',
    amapSecurityJsCode: 'runtime-security',
    amapSecurityServiceHost: '/_AMapService'
  };

  expect(getAMapConfig()).toEqual({
    webJsKey: 'runtime-key',
    securityJsCode: 'runtime-security',
    securityServiceHost: '/_AMapService'
  });
  expect(isAMapConfigured()).toBe(true);
});

test('treats blank AMap key as not configured', () => {
  window.__LINGNIU_APP_CONFIG__ = { amapWebJsKey: ' ' };

  expect(isAMapConfigured()).toBe(false);
});
