import { screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import type { components } from 'api-types' import { HttpResponse } from 'msw' import { Button } from 'ui' import { useCurrentPage, useSetPage } from 'ui-patterns/CommandMenu' import { beforeEach, describe, expect, it, vi } from 'vitest' import { useApiKeysCommands } from './ApiKeys' import { customRender } from '@/tests/lib/custom-render' import { addAPIMock } from '@/tests/lib/msw' type ApiKeyResponse = components['schemas']['ApiKeyResponse'] const { mockUseAsyncCheckPermissions, mockUseHighAvailability, mockUseSelectedProjectQuery } = vi.hoisted(() => ({ mockUseAsyncCheckPermissions: vi.fn(), mockUseHighAvailability: vi.fn(), mockUseSelectedProjectQuery: vi.fn(), })) vi.mock('@/hooks/misc/useCheckPermissions', () => ({ useAsyncCheckPermissions: mockUseAsyncCheckPermissions, })) vi.mock('@/hooks/misc/useHighAvailability', () => ({ useHighAvailability: mockUseHighAvailability, })) vi.mock('@/hooks/misc/useSelectedProject', () => ({ useSelectedProjectQuery: mockUseSelectedProjectQuery, })) const API_KEYS: ApiKeyResponse[] = [ { api_key: 'anon-key', name: 'anon', type: 'legacy' }, { api_key: 'service-key', name: 'service_role', type: 'legacy' }, { api_key: 'publishable-key', hash: 'hash', id: 'publishable-id', inserted_at: '2025-02-16T22:24:42.115195Z', name: 'default', type: 'publishable', }, { api_key: 'secret-key', hash: 'hash', id: 'secret-id', inserted_at: '2025-02-16T22:24:42.115195Z', name: 'sb_secret', type: 'secret', }, ] /** Renders the API keys command page so its commands can be asserted on. */ const CommandPageHarness = () => { useApiKeysCommands() const setPage = useSetPage() const page = useCurrentPage() const commands = page && 'sections' in page ? page.sections.flatMap((section) => section.commands) : [] return ( <>