mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 19:05:06 +03:00
## Context PR here mainly breaks up the files under `ConnectSheet` to separate the functional logic so that we can write unit tests. No behavior changes intended beyond the bug fixes ## Changes involved - **Test organization:** moved all root-level `ConnectSheet` test files into `ConnectSheet/__tests__/` for consistency with other parts of the codebase that use this convention. - **Bug fix:** read replica label had a stray `}` / missing `)`, rendering as e.g. `Read Replica (us-east-1 - abc123})` instead of `Read Replica (us-east-1 - abc123)`. - **`ConnectSheet.tsx`:** extracted the "hydrate sheet state on open" `useEffect` logic (mode/field/URL param resolution from URL vs. localStorage) into a new `ConnectSheet.utils.ts`, with unit tests - **`useConnectServerEnv.ts`:** fixed two race conditions in the secret reveal/hide flow: - `toggle()` and `getValue()` could each fire a separate reveal request if triggered close together — now deduped to share one in-flight request. - `getValue()` could hide a secret that had just been explicitly revealed by a concurrent `toggle()`, due to reading a stale closure value — now reads the live state via `useLatest`. - Also stopped swallowing the original error on reveal failure (now attached via `cause`). - Added tests for the above, plus the 10s auto-hide timer (previously untested). - **`ConnectStepsSection.tsx`:** extracted `resolveContentPath` and the three inline "show notice" booleans (IPv4 addon, session pooler, self-hosted MCP) into `ConnectStepsSection.utils.ts`, matching the existing pattern for the Data API notice. Added unit tests for all of them. ## To test - [ ] Just a basic smoke test of the Connect sheet should do <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Improved connect setup hydration so saved preferences and URL values are applied more consistently when opening the sheet, including automatic URL backfilling where needed. * Refreshed connection guidance notices (IPv4 add-on, session pooler, and self-hosted MCP) with more consistent logic. * **Bug Fixes** * Fixed secret reveal behavior to keep concurrent reveal actions in sync, handle failures more safely, and ensure auto-hide works reliably. * Corrected the read-replica option label formatting. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
225 lines
6.1 KiB
TypeScript
225 lines
6.1 KiB
TypeScript
import { describe, expect, test } from 'vitest'
|
|
|
|
import { resolveFrameworkLibraryKey } from '../Connect.utils'
|
|
|
|
describe('Connect.utils:resolveFrameworkLibraryKey', () => {
|
|
test('should return null if no framework provided', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: undefined,
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBeNull()
|
|
})
|
|
|
|
test('should return null for empty framework string', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: '',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBeNull()
|
|
})
|
|
|
|
test('should return explicit library if provided', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'nextjs',
|
|
frameworkVariant: 'app',
|
|
library: 'custom-library',
|
|
})
|
|
expect(result).toBe('custom-library')
|
|
})
|
|
|
|
test('should resolve library for Next.js App Router', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'nextjs',
|
|
frameworkVariant: 'app',
|
|
library: undefined,
|
|
})
|
|
// Next.js App Router has supabasejs as its library
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should resolve library for Next.js Pages Router', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'nextjs',
|
|
frameworkVariant: 'pages',
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should resolve library for React with Vite variant', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'react',
|
|
frameworkVariant: 'vite',
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should resolve library for React with Create React App variant', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'react',
|
|
frameworkVariant: 'create-react-app',
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should resolve library for framework without variants (Remix)', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'remix',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
// Remix has single child which is supabasejs
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should resolve library for Flutter', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'flutter',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabaseflutter')
|
|
})
|
|
|
|
test('should resolve library for Swift', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'swift',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabaseswift')
|
|
})
|
|
|
|
test('should resolve library for Android Kotlin', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'androidkotlin',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasekt')
|
|
})
|
|
|
|
test('should resolve library for Flask (Python)', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'flask',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasepy')
|
|
})
|
|
|
|
test('should fallback to first variant library when variant not specified for multi-variant framework', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'nextjs',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
// Should get library from first variant (app router)
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should return null for unknown framework', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'unknown-framework',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBeNull()
|
|
})
|
|
|
|
test('should handle SvelteKit framework', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'sveltekit',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should handle Nuxt framework', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'nuxt',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should handle Vue.js framework', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'vuejs',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should handle Solid.js framework', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'solidjs',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should handle Astro framework', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'astro',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should handle Expo React Native', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'exporeactnative',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should handle Ionic React', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'ionicreact',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should handle Ionic Angular', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'ionicangular',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should handle Refine framework', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'refine',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
|
|
test('should handle TanStack Start framework', () => {
|
|
const result = resolveFrameworkLibraryKey({
|
|
framework: 'tanstack',
|
|
frameworkVariant: undefined,
|
|
library: undefined,
|
|
})
|
|
expect(result).toBe('supabasejs')
|
|
})
|
|
})
|