Skip to content

An open-source, faster Devin alternative

TypeScript
2.9 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { BrainCircuit, Database, KeySquare, Plug } from 'lucide-react'
import { managedAgentsNav } from './app-shell-nav'

describe('managed agents navigation', () => {
  const defaults = {}

  it('links Automations to its own page', () => {
    const nav = managedAgentsNav({
      ...defaults,
      computerEnabled: true,
    })
    expect(nav.map((group) => group.items.map((item) => item.label))).toEqual([
      ['Computer', 'Sessions', 'Secrets', 'Automations'],
      ['Connections'],
    ])
    expect(nav[0]?.items[0]).toMatchObject({
      to: '/computer',
      label: 'Computer',
    })
    expect(nav[0]?.items[1]).toMatchObject({ to: '/computer/sessions' })
    expect(nav[0]?.items[2]).toMatchObject({ to: '/computer/secrets' })
    expect(nav[0]?.items[3]).toMatchObject({ to: '/automations' })
    expect(nav[1]?.items[0]).toMatchObject({
      to: '/managed-agents/connections',
      label: 'Connections',
      icon: Plug,
    })
  })

  it('shows Automations next to the computer before the first one exists', () => {
    expect(
      managedAgentsNav({ ...defaults, computerEnabled: true }).map((group) =>
        group.items.map((item) => item.label),
      ),
    ).toEqual([
      ['Computer', 'Sessions', 'Secrets', 'Automations'],
      ['Connections'],
    ])
  })

  it('hides the computer from organizations without it (rollout flag)', () => {
    expect(
      managedAgentsNav(defaults)[0]?.items.map((item) => item.label),
    ).toEqual(['Automations'])
  })

  it('shows project navigation only after a project is selected', () => {
    const nav = managedAgentsNav({ ...defaults, projectId: 'project one' })

    expect(nav[0]?.items.map((item) => item.label)).toEqual([
      'Back to all automations',
    ])
    expect(nav[1]?.items.map((item) => item.label)).toEqual([
      'Deployments',
      'Sessions',
      'Schedules',
      'Webhooks',
      'Memory',
      'Database',
      'Secrets',
      'Connections',
      'BYOK',
      'Debug playground',
      'Settings',
    ])
    expect(
      nav[1]?.items.find((item) => item.label === 'Debug playground')?.to,
    ).toBe('/projects/project%20one')
    expect(nav[1]?.items[nav[1].items.length - 1]?.to).toBe(
      '/projects/project%20one/settings',
    )
    expect(nav[1]?.items.find((item) => item.label === 'Secrets')?.icon).toBe(
      KeySquare,
    )
    expect(nav[1]?.items.find((item) => item.label === 'Database')?.icon).toBe(
      Database,
    )
    expect(nav[1]?.items.find((item) => item.label === 'Connections')?.to).toBe(
      '/projects/project%20one/connections',
    )
    expect(nav[1]?.items.find((item) => item.label === 'BYOK')?.icon).toBe(
      BrainCircuit,
    )
  })

  it('shows only project-scoped navigation inside a project', () => {
    expect(
      managedAgentsNav({
        projectId: 'project-one',
      }).map((group) => group.label),
    ).toEqual([undefined, undefined])
  })
})