|
4 | 4 | import { act } from 'react' |
5 | 5 | import { createRoot, type Root } from 'react-dom/client' |
6 | 6 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
7 | | -import { SortDropdown } from '@/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options' |
| 7 | +import { |
| 8 | + ResourceFilterPanel, |
| 9 | + ResourceFilterSection, |
| 10 | +} from '@/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-filter-panel' |
| 11 | +import { |
| 12 | + ResourceOptions, |
| 13 | + SortDropdown, |
| 14 | +} from '@/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options' |
8 | 15 |
|
9 | 16 | const LONG_COLUMN_LABEL = 'highest_current_champion_role_across_the_entire_company' |
10 | 17 |
|
@@ -125,3 +132,47 @@ describe('SortDropdown', () => { |
125 | 132 | expect(onOpenChange).toHaveBeenCalledWith(false) |
126 | 133 | }) |
127 | 134 | }) |
| 135 | + |
| 136 | +describe('ResourceOptions filter content', () => { |
| 137 | + it('keeps section controls focusable and clear actions working in the filter popover', () => { |
| 138 | + const onClear = vi.fn() |
| 139 | + act(() => { |
| 140 | + root.render( |
| 141 | + <ResourceOptions |
| 142 | + filter={{ |
| 143 | + content: ( |
| 144 | + <ResourceFilterPanel> |
| 145 | + <ResourceFilterSection label='Status'> |
| 146 | + <button type='button'>Choose status</button> |
| 147 | + </ResourceFilterSection> |
| 148 | + <button type='button' onClick={onClear}> |
| 149 | + Clear all filters |
| 150 | + </button> |
| 151 | + </ResourceFilterPanel> |
| 152 | + ), |
| 153 | + }} |
| 154 | + /> |
| 155 | + ) |
| 156 | + }) |
| 157 | + |
| 158 | + const trigger = [...document.querySelectorAll<HTMLButtonElement>('button')].find( |
| 159 | + (button) => button.textContent === 'Filter' |
| 160 | + ) |
| 161 | + expect(trigger).toBeDefined() |
| 162 | + act(() => trigger?.click()) |
| 163 | + |
| 164 | + const choice = [...document.querySelectorAll<HTMLButtonElement>('button')].find( |
| 165 | + (button) => button.textContent === 'Choose status' |
| 166 | + ) |
| 167 | + expect(choice).toBeDefined() |
| 168 | + expect(document.body).toHaveTextContent('Status') |
| 169 | + act(() => choice?.focus()) |
| 170 | + expect(document.activeElement).toBe(choice) |
| 171 | + |
| 172 | + const clear = [...document.querySelectorAll<HTMLButtonElement>('button')].find( |
| 173 | + (button) => button.textContent === 'Clear all filters' |
| 174 | + ) |
| 175 | + act(() => clear?.click()) |
| 176 | + expect(onClear).toHaveBeenCalledOnce() |
| 177 | + }) |
| 178 | +}) |
0 commit comments