Files
supabase/apps/studio/components/interfaces/Functions/EdgeFunctionOverview/EdgeFunctionOverview.periods.platform.test.tsx
T
Alaister YoungandAlaister Young 2695cf117a [FE-3106] (part 8) – refactor(studio): move storage, functions and branches pages (#53217)
Moves the `/storage`, `/realtime`, `/compute`, `/functions` and
`/branches` page bodies into their route files and deletes the pages
(FE-3106). Part 8 of the stack.

**Depends on:** #53216

**Changed:**
- `routes/project/$ref/{storage,realtime,compute,functions,branches}/**`
– 26 page bodies inlined. Wrappers the routes imported from pages
(`BranchesPageWrapper`, `MergeRequestsPageWrapper`, …) are now private
to their route files. Bucket redirects, function create/deploy
navigation and merge-request links use typed `navigate`/`Link`; function
logs/invocations use `useLocation().href`
- Edge function overview, logs-navigation, vectors, compute and branches
tests render the routes with `renderRoute`

- `routes/project/$ref/storage/files/buckets/$bucketId.tsx` – also
carries master's #52777 (Purge CDN cache action and single `action`
query param for the bucket modals), ported from the deleted page so it
isn't reverted

**Removed:**
- 26 page files

Addresses
[FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages).

## To test

- Storage: open a bucket, its policies link and S3 settings – same
layout; deleting a bucket returns to the list
- Edge Functions: create a function, open
Overview/Code/Logs/Invocations/Details – same layout
- Branches and merge requests – lists and "Review" links work

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-11-17 16:13:36 +09:00

90 lines
3.7 KiB
TypeScript

import { 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 { Route } from '@/routes/project/$ref/functions/$functionSlug/index'
import { createMockProject } from '@/tests/helpers'
import { CustomWrapper } from '@/tests/lib/custom-render'
import { addAPIMock } from '@/tests/lib/msw'
import { renderRoute } from '@/tests/lib/route-render'
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: [] }),
})
await renderRoute(Route, {
routeId: '/project/$ref/functions/$functionSlug/',
url: '/project/default/functions/send-email',
renderOptions: {
wrapper: ({ children }) => (
<CustomWrapper queryClient={queryClient}>
<FeatureFlagContext.Provider value={{ configcat: {}, posthog: {}, hasLoaded: false }}>
{children}
</FeatureFlagContext.Provider>
</CustomWrapper>
),
},
})
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()
})