Skip to content

A games launcher for GOG, Amazon and Epic Games for Linux, Windows and macOS.

1.7 KB
Raw Blame
import { normalizeTitle, pickBestTitleMatch } from '../title_match'

describe('normalizeTitle', () => {
  it('lowercases, strips accents and punctuation', () => {
    expect(normalizeTitle('Baldur’s Gate 3™')).toBe('baldur s gate 3')
    expect(normalizeTitle('Pokémon  Écarlate')).toBe('pokemon ecarlate')
  })

  it('spells & as "and"', () => {
    expect(normalizeTitle('Dead Cells & Co')).toBe('dead cells and co')
  })
})

describe('pickBestTitleMatch', () => {
  const candidates = [
    { id: 1, name: 'GRIME II' },
    { id: 2, name: 'GRIME' },
    { id: 3, name: 'Hades II' }
  ]

  it('prefers the exact title', () => {
    expect(pickBestTitleMatch(candidates, 'GRIME')?.id).toBe(2)
  })

  it('does not confuse a sequel with the original', () => {
    expect(pickBestTitleMatch(candidates, 'Hades')).toBeUndefined()
  })

  it('accepts an edition of the requested title', () => {
    const editions = [
      { id: 10, name: 'Disco Elysium - The Final Cut' },
      { id: 11, name: 'Disco Elysium: Game of the Year Edition' }
    ]

    expect(
      pickBestTitleMatch(
        [{ id: 9, name: 'Disco Elysium' }, ...editions],
        'Disco Elysium'
      )?.id
    ).toBe(9)
  })

  it('falls back to an edition when the base game is missing', () => {
    expect(
      pickBestTitleMatch(
        [{ id: 12, name: 'Hades - Game of the Year Edition' }],
        'Hades'
      )?.id
    ).toBe(12)
  })

  it('accepts a year suffix', () => {
    expect(
      pickBestTitleMatch([{ id: 13, name: 'Prey (2017)' }], 'Prey')?.id
    ).toBe(13)
  })

  it('returns nothing for an empty title', () => {
    expect(pickBestTitleMatch(candidates, '   ')).toBeUndefined()
  })
})