edbf68909a
Faceted catalog rows are selectable for contributors; a sticky bulk bar (BulkActionBar) drives set/add/remove gestures from the collection fields schema, calls bulkEntryMeta (one commit), toasts applied/skipped counts, and re-fetches. Non-contributors and legacy (no-fields) collections see no selection (INV-5). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
46 lines
2.0 KiB
React
46 lines
2.0 KiB
React
import { render, screen, fireEvent } from '@testing-library/react'
|
|
import { describe, it, expect, vi } from 'vitest'
|
|
import BulkActionBar from './BulkActionBar.jsx'
|
|
|
|
const FIELDS = {
|
|
priority: { type: 'enum', values: ['P0', 'P1', 'P2'], label: 'Priority' },
|
|
tags: { type: 'tags', label: 'Tags' },
|
|
}
|
|
|
|
describe('BulkActionBar', () => {
|
|
it('shows the selected count', () => {
|
|
render(<BulkActionBar fields={FIELDS} count={3} onApply={() => {}} onClear={() => {}} />)
|
|
expect(screen.getByText(/3 selected/i)).toBeInTheDocument()
|
|
})
|
|
|
|
it('applies a set op when an enum value is chosen', () => {
|
|
const onApply = vi.fn()
|
|
render(<BulkActionBar fields={FIELDS} count={2} onApply={onApply} onClear={() => {}} />)
|
|
fireEvent.change(screen.getByLabelText(/set priority/i), { target: { value: 'P0' } })
|
|
expect(onApply).toHaveBeenCalledWith({ op: 'set', field: 'priority', value: 'P0' })
|
|
})
|
|
|
|
it('applies an add-tag op', () => {
|
|
const onApply = vi.fn()
|
|
render(<BulkActionBar fields={FIELDS} count={2} onApply={onApply} onClear={() => {}} />)
|
|
fireEvent.change(screen.getByPlaceholderText(/tag…/i), { target: { value: 'checkout' } })
|
|
fireEvent.click(screen.getByRole('button', { name: /add tag/i }))
|
|
expect(onApply).toHaveBeenCalledWith({ op: 'add', field: 'tags', value: 'checkout' })
|
|
})
|
|
|
|
it('applies a remove-tag op', () => {
|
|
const onApply = vi.fn()
|
|
render(<BulkActionBar fields={FIELDS} count={2} onApply={onApply} onClear={() => {}} />)
|
|
fireEvent.change(screen.getByPlaceholderText(/tag…/i), { target: { value: 'checkout' } })
|
|
fireEvent.click(screen.getByRole('button', { name: /remove tag/i }))
|
|
expect(onApply).toHaveBeenCalledWith({ op: 'remove', field: 'tags', value: 'checkout' })
|
|
})
|
|
|
|
it('calls onClear', () => {
|
|
const onClear = vi.fn()
|
|
render(<BulkActionBar fields={FIELDS} count={2} onApply={() => {}} onClear={onClear} />)
|
|
fireEvent.click(screen.getByRole('button', { name: /clear/i }))
|
|
expect(onClear).toHaveBeenCalled()
|
|
})
|
|
})
|