17bdd5fd9a
Replace DefaultCollectionRedirect with a CollectionDirectory that lists the project's visible collections, or redirects into the sole one when there is exactly one (preserving the S1 C3.7/C3.8 single-collection UX). The create-first-collection empty state is S4. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
49 lines
1.9 KiB
React
49 lines
1.9 KiB
React
import React from 'react'
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { render, screen, waitFor } from '@testing-library/react'
|
|
import { MemoryRouter, Routes, Route } from 'react-router-dom'
|
|
|
|
let mockItems = []
|
|
vi.mock('../api', () => ({
|
|
listCollections: vi.fn(async () => ({ items: mockItems })),
|
|
}))
|
|
import CollectionDirectory from './CollectionDirectory.jsx'
|
|
|
|
beforeEach(() => { mockItems = [] })
|
|
|
|
function renderDir(items) {
|
|
mockItems = items
|
|
return render(
|
|
<MemoryRouter initialEntries={["/p/ohm/"]}>
|
|
<Routes>
|
|
<Route path="/p/:projectId/*" element={<CollectionDirectory projectId="ohm" />} />
|
|
<Route path="/p/:projectId/c/:collectionId/*" element={<div>collection home</div>} />
|
|
</Routes>
|
|
</MemoryRouter>,
|
|
)
|
|
}
|
|
|
|
describe('CollectionDirectory', () => {
|
|
it('lists a card per collection with the type-driven noun + link when 2+', async () => {
|
|
renderDir([
|
|
{ id: 'default', name: 'Model', type: 'document' },
|
|
{ id: 'features', name: 'Scenarios', type: 'bdd' },
|
|
])
|
|
await waitFor(() => expect(screen.getByText('Scenarios')).toBeInTheDocument())
|
|
expect(screen.getByText('Model').closest('a')).toHaveAttribute('href', '/p/ohm/c/default/')
|
|
expect(screen.getByText('Scenarios').closest('a')).toHaveAttribute('href', '/p/ohm/c/features/')
|
|
expect(screen.getByText('RFCs')).toBeInTheDocument() // document → RFCs
|
|
expect(screen.getByText('Features')).toBeInTheDocument() // bdd → Features (type noun)
|
|
})
|
|
|
|
it('redirects into the sole collection when exactly one is visible', async () => {
|
|
renderDir([{ id: 'default', name: 'Model', type: 'document' }])
|
|
await waitFor(() => expect(screen.getByText('collection home')).toBeInTheDocument())
|
|
})
|
|
|
|
it('shows a minimal empty note when there are no collections', async () => {
|
|
renderDir([])
|
|
await waitFor(() => expect(screen.getByText('No collections yet.')).toBeInTheDocument())
|
|
})
|
|
})
|