Results.utils.test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { describe, expect, test } from 'vitest'
  2. import {
  3. formatCellValue,
  4. formatClipboardValue,
  5. } from '@/components/interfaces/SQLEditor/UtilityPanel/Results.utils'
  6. describe('formatClipboardValue', () => {
  7. test('returns empty string for null', () => {
  8. expect(formatClipboardValue(null)).toBe('')
  9. })
  10. test('stringifies objects', () => {
  11. expect(formatClipboardValue({ a: 1 })).toBe('{"a":1}')
  12. })
  13. test('stringifies arrays', () => {
  14. expect(formatClipboardValue([1, 2])).toBe('[1,2]')
  15. })
  16. test('converts primitives to string', () => {
  17. expect(formatClipboardValue('hello')).toBe('hello')
  18. expect(formatClipboardValue(42)).toBe('42')
  19. expect(formatClipboardValue(false)).toBe('false')
  20. })
  21. })
  22. describe('formatCellValue', () => {
  23. test('returns NULL for null', () => {
  24. expect(formatCellValue(null)).toBe('NULL')
  25. })
  26. test('returns strings as-is', () => {
  27. expect(formatCellValue('hello')).toBe('hello')
  28. })
  29. test('stringifies objects', () => {
  30. expect(formatCellValue({ a: 1 })).toBe('{"a":1}')
  31. })
  32. test('stringifies numbers', () => {
  33. expect(formatCellValue(42)).toBe('42')
  34. })
  35. test('stringifies booleans', () => {
  36. expect(formatCellValue(true)).toBe('true')
  37. })
  38. })