Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.3 KB
Raw Blame
import { beforeEach, describe, expect, it, vi } from 'vitest'
import emojiShortcodes from 'emojibase-data/en/shortcodes/emojibase.json'

async function importConfiguredCatalog() {
  const catalog = await import('./emoji-shortcode-catalog.js')
  const loadDataset = vi.fn(() => emojiShortcodes)
  catalog.setEmojiShortcodeDatasetLoader(loadDataset)
  return { catalog, loadDataset }
}

describe('emoji shortcode catalog laziness', () => {
  beforeEach(() => {
    vi.resetModules()
  })

  it('does not build the catalog when the shared module is imported', async () => {
    const { catalog, loadDataset } = await importConfiguredCatalog()

    expect(loadDataset).not.toHaveBeenCalled()

    const entries = catalog.getStandardEmojiShortcodeEntries()
    expect(entries).toContainEqual({ emoji: '🎉', shortcode: 'party' })
    expect(catalog.getStandardEmojiShortcodeEntries()).toBe(entries)
    expect(loadDataset).toHaveBeenCalledTimes(1)
  })

  it('loads once when replacing emoji and reuses the catalog', async () => {
    const { catalog, loadDataset } = await importConfiguredCatalog()

    expect(catalog.replaceKnownEmojiWithShortcodes('ship \u{1F389}')).toBe('ship  party ')
    expect(catalog.replaceKnownEmojiWithShortcodes('again 🎉')).toBe('again  party ')
    expect(loadDataset).toHaveBeenCalledTimes(1)
  })
})