Skip to content

The open-source AI receptionist for businesses. Answers every call, books the appointment and hands over to a person when needed. You own the code and the data.

2.0 KB
Raw Blame
// Sessions are the last card of Sign-in & security: no page of their own in the account's nav, and the old
// `#account/sessions` link opens Sign-in & security with the sessions card.
import { renderToStaticMarkup } from 'react-dom/server'
import { afterEach, expect, test, vi } from 'vitest'

const account = {
  user: { name: 'Mike', email: '[email protected]', emailVerified: true, locale: null },
  accounts: [],
  methods: { password: false, emailCode: true, passkey: false, sso: [], links: {}, mainOrigin: null },
  avatarUrl: null,
  profileChangedBy: null,
}
const useQuery = vi.fn((key: unknown) =>
  key === 'account' || (Array.isArray(key) && key[0] === 'account')
    ? { data: account, error: null, reload: async () => {} }
    : { data: undefined, error: null, reload: async () => {} },
)
vi.mock('../../cachedQuery.ts', async original => ({ ...(await original<object>()), useQuery }))

const { AccountSettings } = await import('./index.tsx')
const { movedHash } = await import('../../shell/useRoute.ts')

const render = (hash: string) => {
  vi.stubGlobal('window', { location: { hash }, addEventListener: () => {}, removeEventListener: () => {} })
  return renderToStaticMarkup(<AccountSettings hasWorkspace />)
}
afterEach(() => vi.unstubAllGlobals())

test('Sign-in & security ends with the sessions card', () => {
  const html = render('#account/security')
  expect(html).toContain('id="ac-signin"')
  expect(html).toContain('id="ac-sessions"')
  expect(html.indexOf('id="ac-signin"')).toBeLessThan(html.indexOf('id="ac-sessions"'))
})

test('the nav has no Sessions page', () => {
  const html = render('#account/security')
  expect(html).not.toContain('href="#account/sessions"')
  expect(html).toContain('href="#account/security"')
})

test('the old #account/sessions lands on Sign-in & security, at the sessions card', () => {
  const to = movedHash('#account/sessions')
  expect(to).toBe('#account/security/sessions')
  const html = render(to!)
  expect(html).toContain('id="ac-signin"')
  expect(html).toContain('id="ac-sessions"')
})