import { render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { createMemoryRouter, RouterProvider } from 'react-router' import { expect, test } from 'vitest' import { BaoClient } from './api/bao' import { SessionProvider } from './api/session' import { useSession } from './api/useSession' import { Layout } from './Layout' import { Providers } from './test/providers' function SignIn() { const { connect } = useSession() return ( ) } function setup() { const router = createMemoryRouter([{ path: '/', element: , children: [{ index: true, element: }, { path: 'connect', element:

connect page

}] }]) render( , ) return userEvent.setup() } test('offers Connect only while signed out', async () => { const user = setup() const nav = screen.getByRole('navigation', { name: 'Main' }) expect(nav).toHaveTextContent('Connect') expect(screen.getByRole('link', { name: 'Connect' })).toHaveAttribute('href', '/connect') await user.click(screen.getByRole('button', { name: 'sign in' })) expect(screen.queryByRole('link', { name: 'Connect' })).not.toBeInTheDocument() expect(screen.queryByRole('link', { name: 'Connection' })).not.toBeInTheDocument() }) test('shows the section links only while signed in', async () => { const user = setup() const names = ['Identities', 'Secrets', 'Graph'] for (const n of names) expect(screen.queryByRole('link', { name: n })).not.toBeInTheDocument() expect(screen.getByRole('link', { name: 'Connect' })).toBeInTheDocument() await user.click(screen.getByRole('button', { name: 'sign in' })) for (const n of names) expect(screen.getByRole('link', { name: n })).toBeInTheDocument() }) test('while signed in, the signed-in name links to the connection details', async () => { const user = setup() await user.click(screen.getByRole('button', { name: 'sign in' })) const me = screen.getByRole('link', { name: 'alice' }) expect(me).toHaveAttribute('href', '/connect') await user.click(me) expect(screen.getByText('connect page')).toBeInTheDocument() })