Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

5.1 KB
Raw Blame
// FE-MOB-SETINT-001 onwards
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen } from '../../../helpers/render';
import { resetAllStores, seedStore } from '../../../helpers/store';
import { useAddonStore } from '../../../../src/store/addonStore';
import { useAuthStore } from '../../../../src/store/authStore';
import { useSettingsStore } from '../../../../src/store/settingsStore';
import { buildSettings } from '../../../helpers/factories';
import MSettingsIntegrations from '../../../../src/mobile/screens/settings/MSettingsIntegrations';

// The four sections are covered by their own suites — stub them so this file
// only exercises the addon gating and the initial loadAddons call.
vi.mock('../../../../src/mobile/screens/settings/MPhotoProvidersSection', () => ({
  default: () => <div data-testid="photo-providers" />,
}));
vi.mock('../../../../src/mobile/screens/settings/MAirTrailConnectionSection', () => ({
  default: () => <div data-testid="airtrail" />,
}));
vi.mock('../../../../src/mobile/screens/settings/MLlmConnectionSection', () => ({
  default: () => <div data-testid="llm" />,
}));
vi.mock('../../../../src/mobile/screens/settings/MAiConnectionSection', () => ({
  default: ({ assistant, parsing }: { assistant: boolean; parsing: boolean }) => (
    <div data-testid="ai" data-assistant={String(assistant)} data-parsing={String(parsing)} />
  ),
}));
vi.mock('../../../../src/mobile/screens/settings/MSettingsMcp', () => ({
  default: () => <div data-testid="mcp" />,
}));

function seedAddons(ids: string[], loadAddons = vi.fn().mockResolvedValue(undefined)) {
  seedStore(useAddonStore, {
    addons: ids.map((id) => ({ id, name: id, type: 'integration', icon: '', enabled: true })),
    loaded: true,
    loadAddons,
  });
  return loadAddons;
}

describe('MSettingsIntegrations', () => {
  beforeEach(() => {
    resetAllStores();
  });

  it('FE-MOB-SETINT-001: only the photo providers render when no integration addon is on', () => {
    seedAddons([]);
    render(<MSettingsIntegrations />);

    expect(screen.getByTestId('photo-providers')).toBeInTheDocument();
    expect(screen.queryByTestId('airtrail')).not.toBeInTheDocument();
    expect(screen.queryByTestId('llm')).not.toBeInTheDocument();
    expect(screen.queryByTestId('mcp')).not.toBeInTheDocument();
  });

  it('FE-MOB-SETINT-002: the airtrail addon reveals the AirTrail connection section', () => {
    seedAddons(['airtrail']);
    render(<MSettingsIntegrations />);

    expect(screen.getByTestId('airtrail')).toBeInTheDocument();
    expect(screen.queryByTestId('llm')).not.toBeInTheDocument();
  });

  it('FE-MOB-SETINT-003: the llm_parsing addon reveals the AI connection, which parsing reads with', () => {
    seedAddons(['llm_parsing']);
    render(<MSettingsIntegrations />);

    const ai = screen.getByTestId('ai');
    expect(ai).toHaveAttribute('data-parsing', 'true');
    expect(ai).toHaveAttribute('data-assistant', 'false');
    // No personal parsing model saved: its old form is not offered.
    expect(screen.queryByTestId('llm')).not.toBeInTheDocument();
    expect(screen.queryByTestId('airtrail')).not.toBeInTheDocument();
  });

  it('FE-MOB-SETINT-008: a personal parsing model saved earlier keeps its form', () => {
    seedAddons(['llm_parsing']);
    seedStore(useSettingsStore, { settings: buildSettings({ llm_provider: 'openai', llm_model: 'gpt-4o' }) });
    render(<MSettingsIntegrations />);

    expect(screen.getByTestId('llm')).toBeInTheDocument();
  });

  it('FE-MOB-SETINT-004: the mcp addon reveals the MCP configuration', () => {
    seedAddons(['mcp']);
    render(<MSettingsIntegrations />);

    expect(screen.getByTestId('mcp')).toBeInTheDocument();
  });

  it('FE-MOB-SETINT-005: all three sections render together when every addon is on', () => {
    seedAddons(['airtrail', 'llm_parsing', 'mcp']);
    render(<MSettingsIntegrations />);

    expect(screen.getByTestId('airtrail')).toBeInTheDocument();
    expect(screen.getByTestId('ai')).toBeInTheDocument();
    expect(screen.getByTestId('mcp')).toBeInTheDocument();
  });

  it('FE-MOB-SETINT-006: a disabled addon row does not unlock its section', () => {
    seedStore(useAddonStore, {
      addons: [{ id: 'mcp', name: 'MCP', type: 'integration', icon: '', enabled: false }],
      loaded: true,
      loadAddons: vi.fn().mockResolvedValue(undefined),
    });
    render(<MSettingsIntegrations />);

    expect(screen.queryByTestId('mcp')).not.toBeInTheDocument();
  });

  it('FE-MOB-SETINT-007: the addon list is refreshed once on mount', () => {
    const loadAddons = seedAddons([]);
    const { rerender } = render(<MSettingsIntegrations />);
    rerender(<MSettingsIntegrations />);

    expect(loadAddons).toHaveBeenCalledTimes(1);
  });

  it('FE-MOB-SETINT-008: a managed install hides the photo providers and AirTrail, as the desktop does', () => {
    seedAddons(['airtrail', 'mcp']);
    seedStore(useAuthStore, { managed: true });
    render(<MSettingsIntegrations />);

    expect(screen.queryByTestId('photo-providers')).not.toBeInTheDocument();
    expect(screen.queryByTestId('airtrail')).not.toBeInTheDocument();
    expect(screen.getByTestId('mcp')).toBeInTheDocument();
  });
});