snippets.browser.test.ts53 lines · main
| 1 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
| 2 | |
| 3 | import { generateDeterministicUuid } from './snippets.browser' |
| 4 | |
| 5 | describe('snippets.utils', () => { |
| 6 | beforeEach(() => { |
| 7 | vi.clearAllMocks() |
| 8 | }) |
| 9 | |
| 10 | afterEach(() => { |
| 11 | vi.resetAllMocks() |
| 12 | }) |
| 13 | |
| 14 | describe('generateDeterministicUuid', () => { |
| 15 | it('should generate the same UUID for the same input', () => { |
| 16 | const input = 'test-string' |
| 17 | const uuid1 = generateDeterministicUuid([input]) |
| 18 | const uuid2 = generateDeterministicUuid([input]) |
| 19 | |
| 20 | expect(uuid1).toBe(uuid2) |
| 21 | expect(uuid1).toMatch( |
| 22 | /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i |
| 23 | ) |
| 24 | }) |
| 25 | |
| 26 | it('should generate different UUIDs for different inputs', () => { |
| 27 | const uuid1 = generateDeterministicUuid(['input1']) |
| 28 | const uuid2 = generateDeterministicUuid(['input2']) |
| 29 | |
| 30 | expect(uuid1).not.toBe(uuid2) |
| 31 | }) |
| 32 | |
| 33 | it('should handle empty string input', () => { |
| 34 | const uuid = generateDeterministicUuid(['']) |
| 35 | 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) |
| 36 | }) |
| 37 | |
| 38 | it('should handle special characters and Unicode', () => { |
| 39 | const uuid1 = generateDeterministicUuid(['test-with-émojis-🚀-and-símb0ls!']) |
| 40 | const uuid2 = generateDeterministicUuid(['test-with-émojis-🚀-and-símb0ls!']) |
| 41 | expect(uuid1).toBe(uuid2) |
| 42 | expect(uuid1).toMatch( |
| 43 | /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i |
| 44 | ) |
| 45 | }) |
| 46 | |
| 47 | it('should handle very long strings', () => { |
| 48 | const longString = 'a'.repeat(10000) |
| 49 | const uuid = generateDeterministicUuid([longString]) |
| 50 | 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) |
| 51 | }) |
| 52 | }) |
| 53 | }) |