47 行
2.3 KiB
TypeScript
47 行
2.3 KiB
TypeScript
import { fireEvent, screen } from '@testing-library/react'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import CountsSummaryResults from '@/components/counts/CountsSummaryResults'
|
|
import CountsTableLayout from '@/components/counts/CountsTableLayout'
|
|
import { CountsDefinitionContext } from '@/lib/countsDefinitions'
|
|
import { postDefinition } from '@/test/fixtures/counts'
|
|
import { renderWithProviders } from '@/test/render'
|
|
|
|
import type { CountsResult } from '@/lib/counts'
|
|
|
|
const result: CountsResult = {
|
|
count: 4, page: 1, limit: 100, groupCount: 1, outputCount: 1,
|
|
rows: [{ field: 'resource_id' }], cols: [], columnValuesEditable: false,
|
|
rowHeaders: [{ values: ['__counts_private__'], kind: 'data' },
|
|
{ values: [], kind: 'grand_total' }],
|
|
columnHeaders: [{ values: [], kind: 'grand_total' }],
|
|
cells: [{ values: ['__counts_private__'], count: 4 }],
|
|
pivotTotals: [{ row: [], column: [], count: 4 }], axisLabels: {} }
|
|
|
|
describe ('Counts summary privacy and row numbering', () => {
|
|
it ('copies masked labels and omits private links and legacy numbering', () => {
|
|
const { container } = renderWithProviders (
|
|
<CountsDefinitionContext.Provider value={postDefinition}>
|
|
<CountsTableLayout><CountsSummaryResults resource="posts" data={result}
|
|
params={new URLSearchParams ('mode=summary&row_numbers=1&rows=resource_id&cols=')}
|
|
pending={false} update={vi.fn ()}/></CountsTableLayout>
|
|
</CountsDefinitionContext.Provider>, { route: '/ja/counts/posts' })
|
|
const label = screen.getByText ('********')
|
|
expect (label).toHaveAttribute ('title', expect.stringContaining ('集計件数には含まれます'))
|
|
expect (label).toHaveClass ('text-red-600', 'dark:text-red-400')
|
|
const row = label.closest ('tr')!
|
|
expect (row.querySelector ('a')).toBeNull ()
|
|
expect (container.innerHTML).not.toContain ('__counts_private__')
|
|
expect (screen.queryByText ('No.')).not.toBeInTheDocument ()
|
|
expect (row.querySelectorAll ('td')).toHaveLength (2)
|
|
const table = screen.getByRole ('grid')
|
|
table.focus ()
|
|
fireEvent.keyDown (table, { key: 'Home' })
|
|
const setData = vi.fn ()
|
|
fireEvent.copy (table, { clipboardData: { setData } })
|
|
const plain = setData.mock.calls.find (entry => entry[0] === 'text/plain')?.[1]
|
|
expect (plain).toContain ('********')
|
|
expect (plain).not.toContain ('__counts_private__')
|
|
})
|
|
})
|