Files
supabase/apps/studio/components/interfaces/Functions/EdgeFunctionOverview/EdgeFunctionOverview.periods.platform.test.tsx
T
d4b9d1240c refactor(studio): remove the legacy edge function overview (#52281)
The `edgeFunctionsOverview` flag is fully rolled out, so the edge
function Overview page now always renders the new Overview. This removes
the legacy Overview and everything only it used.

- **Overview page**: renders `EdgeFunctionOverview` directly, like the
other function tabs. The flag check and the loader shown while flags
load are gone.
- **`EdgeFunctionRecentInvocations`** and its utils: only the legacy
Overview showed this list.
- **`components/ui/Charts/AreaChart`**: the legacy Overview was its last
importer. The other `AreaChart` uses are recharts' own.

**Self-hosted:** flags never load off-platform, so self-hosted Studio
always got the legacy Overview. Its Overview tab is already hidden, and
the new Overview sends a direct visit to the Details tab, so nothing
reachable from the UI changes.

After this ships, the `edgeFunctionsOverview` flag can be deleted in
ConfigCat.

### How to test

1. Open an edge function's Overview on platform. It shows the new
Overview, with no loader flash while flags load.
2. Self-hosted: open `/project/default/functions/<slug>` directly. It
redirects to the Details tab.

### Validation

- Studio typecheck, lint, Prettier and knip pass on this layer.
Functions and Charts unit tests pass.

### Stack

Merge in order:

1. #50953 — reusable logs table building blocks
2. #50954 — function-scoped unified logs queries
3. #50955 — slimmer function detail layout, header on Overview
4. #50957 — Invocations merged into a function-scoped Logs tab
5. #50958 — Overview errors in the shared logs table
6. #52281 — remove the legacy Overview

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Jordi Enric <jordi.err@gmail.com>
2026-10-28 09:19:25 +01:00

82 lines
3.5 KiB
TypeScript

import { dehydrate, QueryClient } from '@tanstack/react-query'
import { screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { FeatureFlagContext } from 'common'
import { HttpResponse } from 'msw'
import { afterEach, expect, it, vi } from 'vitest'
import { configKeys } from '@/data/config/keys'
import { customDomainKeys } from '@/data/custom-domains/keys'
import type { EdgeFunction } from '@/data/edge-functions/edge-function-query'
import { edgeFunctionsKeys } from '@/data/edge-functions/keys'
import { projectKeys } from '@/data/projects/keys'
import { subscriptionKeys } from '@/data/subscriptions/keys'
import OverviewPage from '@/pages/project/[ref]/functions/[functionSlug]/index'
import { createMockProject } from '@/tests/helpers'
import { customRender } from '@/tests/lib/custom-render'
import { addAPIMock } from '@/tests/lib/msw'
afterEach(() => vi.useRealTimers())
it('loads the overview before feature flags and updates metrics with the selected period', async () => {
vi.useFakeTimers({ toFake: ['Date'] })
vi.setSystemTime(new Date('2026-03-20T10:37:21Z'))
const user = userEvent.setup()
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
})
queryClient.setQueryData(projectKeys.detail('default'), createMockProject({ ref: 'default' }))
queryClient.setQueryData(configKeys.settingsV2('default'), {
app_config: { endpoint: 'default.supabase.co' },
})
queryClient.setQueryData(subscriptionKeys.addons('default'), { selected_addons: [] })
queryClient.setQueryData(customDomainKeys.list('default'), {})
queryClient.setQueryData<EdgeFunction>(edgeFunctionsKeys.detail('default', undefined), {
id: 'function-id',
name: 'Send email',
slug: 'send-email',
status: 'ACTIVE',
version: 2,
created_at: new Date('2026-03-20T08:00:00Z').valueOf(),
updated_at: new Date('2026-03-20T09:00:00Z').valueOf(),
})
addAPIMock({
method: 'get',
path: '/platform/projects/:ref/analytics/endpoints/functions.combined-stats',
response: ({ request }) => {
const interval = new URL(request.url).searchParams.get('interval')
if (interval === '15min') return HttpResponse.json<{ result: never[] }>({ result: [] })
const isDaily = interval === '1day'
return HttpResponse.json<{
result: Array<{ timestamp: string; avg_execution_time: number }>
}>({
result: [
{ timestamp: '2026-03-20T10:35:00Z', avg_execution_time: isDaily ? 90 : 40 },
{ timestamp: '2026-03-20T10:36:00Z', avg_execution_time: isDaily ? 90 : 80 },
],
})
},
})
addAPIMock({
method: 'post',
path: '/platform/projects/:ref/analytics/endpoints/logs.all.otel',
response: () => HttpResponse.json<{ result: never[] }>({ result: [] }),
})
customRender(
<FeatureFlagContext.Provider value={{ configcat: {}, posthog: {}, hasLoaded: false }}>
<OverviewPage dehydratedState={dehydrate(queryClient)} />
</FeatureFlagContext.Provider>,
{ queryClient }
)
expect(await screen.findByText('60ms')).toBeVisible()
await user.click(screen.getByRole('button', { name: '15 min' }))
expect((await screen.findAllByText('No data to show'))[0]).toBeVisible()
await user.click(screen.getByRole('button', { name: '1 day' }))
await waitFor(() =>
expect(screen.getByRole('button', { name: '1 day', pressed: true })).toBeVisible()
)
expect(await screen.findByText('90ms')).toBeVisible()
})