|
| 1 | +/** |
| 2 | + * @vitest-environment jsdom |
| 3 | + */ |
| 4 | +import { act } from 'react' |
| 5 | +import { createRoot, type Root } from 'react-dom/client' |
| 6 | +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
| 7 | +import { SortDropdown } from '@/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options' |
| 8 | + |
| 9 | +const LONG_COLUMN_LABEL = 'highest_current_champion_role_across_the_entire_company' |
| 10 | + |
| 11 | +function ColumnIcon() { |
| 12 | + return <svg data-testid='column-icon' aria-hidden='true' /> |
| 13 | +} |
| 14 | + |
| 15 | +class ResizeObserverMock { |
| 16 | + observe = vi.fn() |
| 17 | + unobserve = vi.fn() |
| 18 | + disconnect = vi.fn() |
| 19 | +} |
| 20 | + |
| 21 | +let container: HTMLDivElement |
| 22 | +let root: Root |
| 23 | + |
| 24 | +beforeEach(() => { |
| 25 | + vi.stubGlobal('ResizeObserver', ResizeObserverMock) |
| 26 | + container = document.createElement('div') |
| 27 | + document.body.appendChild(container) |
| 28 | + root = createRoot(container) |
| 29 | +}) |
| 30 | + |
| 31 | +afterEach(() => { |
| 32 | + act(() => root.unmount()) |
| 33 | + container.remove() |
| 34 | + vi.unstubAllGlobals() |
| 35 | +}) |
| 36 | + |
| 37 | +describe('SortDropdown', () => { |
| 38 | + it('renders long option labels in the truncatable span between both icons', () => { |
| 39 | + act(() => { |
| 40 | + root.render( |
| 41 | + <SortDropdown |
| 42 | + open |
| 43 | + onOpenChange={vi.fn()} |
| 44 | + config={{ |
| 45 | + options: [ |
| 46 | + { |
| 47 | + id: 'long-column', |
| 48 | + label: LONG_COLUMN_LABEL, |
| 49 | + icon: ColumnIcon, |
| 50 | + }, |
| 51 | + ], |
| 52 | + active: { column: 'long-column', direction: 'asc' }, |
| 53 | + onSort: vi.fn(), |
| 54 | + }} |
| 55 | + /> |
| 56 | + ) |
| 57 | + }) |
| 58 | + |
| 59 | + const item = document.body.querySelector<HTMLElement>('[role="menuitem"]') |
| 60 | + expect(item).not.toBeNull() |
| 61 | + expect(item).toHaveAccessibleName(LONG_COLUMN_LABEL) |
| 62 | + |
| 63 | + const label = item?.querySelector('span') |
| 64 | + expect(label).not.toBeNull() |
| 65 | + expect(label).toHaveTextContent(LONG_COLUMN_LABEL) |
| 66 | + expect(label).toHaveClass('min-w-0', 'block', 'truncate') |
| 67 | + expect(item?.querySelector('[data-testid="column-icon"]')).not.toBeNull() |
| 68 | + expect(item?.querySelectorAll('svg')).toHaveLength(2) |
| 69 | + }) |
| 70 | +}) |
0 commit comments