refactor(settings): share the integration and plugin tab gating between desktop and phone

The addon flags, the managed install flag and the addon reload of the integrations tab now come from one useIntegrationGates hook, and useSettings hands both shells the plugins tab flag next to the integrations one.
This commit is contained in:
Maurice
2026-10-09 10:39:01 +02:00
parent deff306755
commit 3b4539f600
7 changed files with 105 additions and 47 deletions
@@ -0,0 +1,55 @@
// FE-COMP-INTEGRATION-GATES-001 to -004: which integrations the settings shells offer.
import { renderHook } from '@testing-library/react';
import { resetAllStores, seedStore } from '../../../tests/helpers/store';
import { useAddonStore } from '../../store/addonStore';
import { useAuthStore } from '../../store/authStore';
import { useIntegrationGates } from './useIntegrationGates';
function seedAddons(enabled: string[]) {
const loadAddons = vi.fn().mockResolvedValue(undefined);
seedStore(useAddonStore, { isEnabled: (id: string) => enabled.includes(id), loadAddons });
return loadAddons;
}
beforeEach(() => {
resetAllStores();
});
describe('useIntegrationGates', () => {
it('FE-COMP-INTEGRATION-GATES-001: maps each addon to its flag', () => {
seedAddons(['mcp', 'llm_parsing']);
const { result } = renderHook(() => useIntegrationGates({ reloadAddons: false }));
expect(result.current).toMatchObject({
memoriesEnabled: false,
mcpEnabled: true,
airtrailEnabled: false,
llmEnabled: true,
dawarichEnabled: false,
hasIntegrations: true,
});
});
it('FE-COMP-INTEGRATION-GATES-002: any one integration addon opens the tab, none keeps it closed', () => {
for (const id of ['memories', 'mcp', 'airtrail', 'llm_parsing', 'dawarich']) {
seedAddons([id]);
expect(renderHook(() => useIntegrationGates({ reloadAddons: false })).result.current.hasIntegrations).toBe(true);
}
seedAddons(['vacay', 'atlas']);
expect(renderHook(() => useIntegrationGates({ reloadAddons: false })).result.current.hasIntegrations).toBe(false);
});
it('FE-COMP-INTEGRATION-GATES-003: reports a managed install', () => {
seedAddons([]);
seedStore(useAuthStore, { managed: true });
expect(renderHook(() => useIntegrationGates({ reloadAddons: false })).result.current.managed).toBe(true);
});
it('FE-COMP-INTEGRATION-GATES-004: reloads the addon list on mount only when asked to', () => {
const quiet = seedAddons([]);
renderHook(() => useIntegrationGates({ reloadAddons: false }));
expect(quiet).not.toHaveBeenCalled();
const loud = seedAddons([]);
renderHook(() => useIntegrationGates({ reloadAddons: true }));
expect(loud).toHaveBeenCalledTimes(1);
});
});