FunctionList.utils.test.ts30 lines · main
1import { describe, expect, it } from 'vitest'
2
3import { getDatabaseTriggersHref } from './FunctionList.utils'
4
5describe('FunctionList.utils: getDatabaseTriggersHref', () => {
6 it('builds the triggers href with a plain function name', () => {
7 expect(getDatabaseTriggersHref('abc', 'on_insert')).toBe(
8 '/project/abc/database/triggers?search=on_insert'
9 )
10 })
11
12 it('preserves special characters in the function name', () => {
13 const href = getDatabaseTriggersHref('abc', 'on_insert&schema=secret')
14 const parsed = new URL(href, 'http://example.com')
15 expect(parsed.searchParams.get('search')).toBe('on_insert&schema=secret')
16 expect(parsed.searchParams.get('schema')).toBeNull()
17 })
18
19 it('preserves spaces and plus signs in the function name', () => {
20 const href = getDatabaseTriggersHref('abc', 'a name+x')
21 const parsed = new URL(href, 'http://example.com')
22 expect(parsed.searchParams.get('search')).toBe('a name+x')
23 })
24
25 it('falls back to empty strings for undefined inputs', () => {
26 expect(getDatabaseTriggersHref(undefined, undefined)).toBe(
27 '/project//database/triggers?search='
28 )
29 })
30})