Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

1.0 KB
Raw Blame
import { describe, expect, test } from 'vitest'

import { getOptionMatchScore } from '@/components/interfaces/ConnectSheet/ConnectConfigSection.utils'

describe('ConnectConfigSection utils: getOptionMatchScore', () => {
  test.each(['', '   '])('matches a blank search (%j)', (search) => {
    expect(getOptionMatchScore('Next.js', search, ['nextjs'])).toBe(1)
  })

  test('matches a substring of the option label', () => {
    expect(getOptionMatchScore('Next.js', 'xt.j')).toBe(1)
  })

  test('matches a substring of an option keyword', () => {
    expect(getOptionMatchScore('Next.js', 'nextjs', ['nextjs'])).toBe(1)
  })

  test('matches case-insensitively and ignores surrounding search whitespace', () => {
    expect(getOptionMatchScore('React Native', '  NATIVE  ')).toBe(1)
  })

  test('does not match when the search is absent from the label and keywords', () => {
    expect(getOptionMatchScore('Next.js', 'flutter', ['nextjs'])).toBe(0)
  })

  test('does not require keywords', () => {
    expect(getOptionMatchScore('Next.js', 'nextjs')).toBe(0)
  })
})