Files
supabase/apps/studio/components/layouts/EdgeFunctionsLayout/EdgeFunctionDetailsLayout.test.tsx
080b888e6b feat(studio): slim edge function detail layout and move header to Overview (#50955)
The edge function detail layout is now breadcrumbs plus tabs
(`PageNav`), without the page header, so tabs like Logs and Code get the
full height below the tabs. The function name, invoke URL and last
deploy details move into a header on the Overview tab, which also holds
the chart period selector. Both the new and legacy Overview render it,
and both now default to a 1 hour period instead of 15 minutes.

The Overview sections (invocations, errors, performance and usage) now
sit in one default-width `PageContainer` instead of each nesting a
full-width one, and the invocations chart moves into a chart card.
Invocations has no section heading, since it's the headline metric right
below the page header.

Both overview versions use the same chart periods. Sparse chart data is
filled only between returned API buckets, avoiding synthetic zeros
outside the reported range. Chart navigation uses the full rolling
period, including a full day for the 1 day option.

The selector shows a checkmark for the selected period, and the header
announces loaded details. Self-hosted Studio retains a Copy URL action
in the detail toolbar because it has no Overview tab.

This layer doesn't depend on the logs changes below it.

**Heads-up:** the header now only appears on Overview. Code, Details,
Invocations and Logs show breadcrumbs and tabs only. This change isn't
behind a flag.

### How to test

1. Open an edge function's Overview. The header shows the name, URL
(with copy) and last deploy hover card, and the period selector sits in
the header with 1 hour selected.
2. Switch through the other tabs. Breadcrumbs and tabs stay sticky, and
there's no header.
3. With the `edgeFunctionsOverview` flag off, the legacy Overview
renders with the same header.

### Validation

- 104 focused tests pass with retries disabled and shuffled order (seed
50968). New tests cover both overview versions, period changes, empty
results, header loading and copying, and self-hosted URL copying. Test
names describe observable behavior.
- 12 targeted regression mutations were detected and restored; the
selected-indicator mutation was repeated after the visual alignment fix.
- Browser QA on the staging preview for `3d055c0dc4` covers the header
and deploy details, copied URL, period changes, all detail tabs, sticky
navigation, the legacy overview, and empty results. Temporary local flag
overrides were removed. The final test-only commit `5af6a2896b` has
identical production code; its matching preview also passed header,
URL-copy, period-switching, and Settings smoke checks.
- Independent code review and changed-file formatting checks pass. All
40 executed CI checks pass on `5af6a2896b`, including TypeScript/lint,
unit tests, Next.js and TanStack E2E tests, and builds. All six review
threads are resolved.

### 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-27 09:29:10 +01:00

81 lines
3.3 KiB
TypeScript

import { QueryClient } from '@tanstack/react-query'
import { screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { HttpResponse } from 'msw'
import { afterEach, expect, it, vi } from 'vitest'
import EdgeFunctionDetailsLayout from './EdgeFunctionDetailsLayout'
import { MainScrollContainerProvider } from '@/components/layouts/MainScrollContainerContext'
import { MobileSheetProvider } from '@/components/layouts/Navigation/NavigationBar/MobileSheetContext'
import { BannerStackProvider } from '@/components/ui/BannerStack/BannerStackProvider'
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 { miscKeys } from '@/data/misc/keys'
import { projectKeys } from '@/data/projects/keys'
import { subscriptionKeys } from '@/data/subscriptions/keys'
import { createMockProject } from '@/tests/helpers'
import { customRender } from '@/tests/lib/custom-render'
import { addAPIMock, type APIErrorBody } from '@/tests/lib/msw'
const originalScrollTo = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'scrollTo')
afterEach(() => {
if (originalScrollTo) Object.defineProperty(HTMLElement.prototype, 'scrollTo', originalScrollTo)
else Reflect.deleteProperty(HTMLElement.prototype, 'scrollTo')
})
it('lets self-hosted users copy the function URL from the detail toolbar', async () => {
HTMLElement.prototype.scrollTo = vi.fn()
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: 'localhost:54321', protocol: 'http' },
})
queryClient.setQueryData(subscriptionKeys.addons('default'), { selected_addons: [] })
queryClient.setQueryData(customDomainKeys.list('default'), {})
queryClient.setQueryData(miscKeys.enabledFeaturesOverride(), { disabled_features: [] })
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/integrations/github/authorization',
response: () =>
HttpResponse.json<APIErrorBody>({ message: 'No GitHub authorization' }, { status: 404 }),
})
addAPIMock({
method: 'get',
path: '/v1/projects/:ref/api-keys',
response: () => HttpResponse.json<never[]>([]),
})
customRender(
<BannerStackProvider>
<MobileSheetProvider>
<MainScrollContainerProvider>
<EdgeFunctionDetailsLayout title="Settings">Function settings</EdgeFunctionDetailsLayout>
</MainScrollContainerProvider>
</MobileSheetProvider>
</BannerStackProvider>,
{ queryClient }
)
await user.click(await screen.findByRole('button', { name: 'Copy URL' }))
expect(await navigator.clipboard.readText()).toBe(
'http://localhost:54321/functions/v1/send-email'
)
})