Graph: highlight a selected node's links; nav: Connect only when signed out
Selecting a node highlights every edge into and out of it, with their labels and the boxes at the far ends, and dims the rest. The Connect menu item is shown only while signed out; when signed in, the name in the menu links to the connection page so Disconnect stays reachable. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
11c9483a88
commit
44e4eb75c9
6 files changed
+133
-16
No files matched your search
@@ -0,0 +1,50 @@
|
||||
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 (
|
||||
<button type="button" onClick={() => connect(new BaoClient('http://b', 't'), { accessor: 'a', display_name: 'alice', policies: [], ttl: 0, renewable: false })}>
|
||||
sign in
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
function setup() {
|
||||
const router = createMemoryRouter([{ path: '/', element: <Layout />, children: [{ index: true, element: <SignIn /> }, { path: 'connect', element: <p>connect page</p> }] }])
|
||||
render(
|
||||
<Providers>
|
||||
<SessionProvider>
|
||||
<RouterProvider router={router} />
|
||||
</SessionProvider>
|
||||
</Providers>,
|
||||
)
|
||||
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('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()
|
||||
})
|
||||
Reference in new issue
Block a user