mirror of
https://github.com/supabase/supabase.git
synced 2026-07-04 06:44:22 +08:00
* Add a generateDeterministicUuid function and tests for it. * Use the new function and generate an id automatically when creating a snippet. * Clean up extra code. * Don't pass in id when creating a snippet. * Add generateSnippetTitle function and use it instead of fixed string. * When SQL editor is open, generate an id form a generated snippet title. * Add id override for SQL editor to avoid flash when saving the snippet. * Merge the two generate functions to happen in the same useMemo block. * Save the snippet to the API when adding it. * Minor fixes from CodeRabbit review. * Hide new folder CTA in sql editor for self-hosted * Don't add the snippet for saving, just set the value. * UpsertContentPayload always has an id. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { generateDeterministicUuid } from './snippets.browser'
|
|
|
|
describe('snippets.utils', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.resetAllMocks()
|
|
})
|
|
|
|
describe('generateDeterministicUuid', () => {
|
|
it('should generate the same UUID for the same input', () => {
|
|
const input = 'test-string'
|
|
const uuid1 = generateDeterministicUuid([input])
|
|
const uuid2 = generateDeterministicUuid([input])
|
|
|
|
expect(uuid1).toBe(uuid2)
|
|
expect(uuid1).toMatch(
|
|
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
|
|
)
|
|
})
|
|
|
|
it('should generate different UUIDs for different inputs', () => {
|
|
const uuid1 = generateDeterministicUuid(['input1'])
|
|
const uuid2 = generateDeterministicUuid(['input2'])
|
|
|
|
expect(uuid1).not.toBe(uuid2)
|
|
})
|
|
|
|
it('should handle empty string input', () => {
|
|
const uuid = generateDeterministicUuid([''])
|
|
expect(uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
|
|
})
|
|
|
|
it('should handle special characters and Unicode', () => {
|
|
const uuid1 = generateDeterministicUuid(['test-with-émojis-🚀-and-símb0ls!'])
|
|
const uuid2 = generateDeterministicUuid(['test-with-émojis-🚀-and-símb0ls!'])
|
|
expect(uuid1).toBe(uuid2)
|
|
expect(uuid1).toMatch(
|
|
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
|
|
)
|
|
})
|
|
|
|
it('should handle very long strings', () => {
|
|
const longString = 'a'.repeat(10000)
|
|
const uuid = generateDeterministicUuid([longString])
|
|
expect(uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
|
|
})
|
|
})
|
|
})
|