|
| 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 } from 'vitest' |
| 7 | +import { |
| 8 | + TableSidebarScrollBody, |
| 9 | + TableSidebarShell, |
| 10 | +} from '@/app/workspace/[workspaceId]/tables/[tableId]/components/table-sidebar-layout' |
| 11 | + |
| 12 | +let container: HTMLDivElement |
| 13 | +let root: Root |
| 14 | + |
| 15 | +beforeEach(() => { |
| 16 | + globalThis.IS_REACT_ACT_ENVIRONMENT = true |
| 17 | + container = document.createElement('div') |
| 18 | + document.body.appendChild(container) |
| 19 | + root = createRoot(container) |
| 20 | +}) |
| 21 | + |
| 22 | +afterEach(() => { |
| 23 | + act(() => root.unmount()) |
| 24 | + container.remove() |
| 25 | +}) |
| 26 | + |
| 27 | +describe('table sidebar layout', () => { |
| 28 | + it('keeps the labeled dialog and its form mounted while the sidebar slides closed', () => { |
| 29 | + function render(open: boolean) { |
| 30 | + act(() => { |
| 31 | + root.render( |
| 32 | + <TableSidebarShell open={open} aria-label='Configure workflow'> |
| 33 | + <TableSidebarScrollBody> |
| 34 | + <input aria-label='Workflow name' defaultValue='Existing workflow' /> |
| 35 | + </TableSidebarScrollBody> |
| 36 | + </TableSidebarShell> |
| 37 | + ) |
| 38 | + }) |
| 39 | + } |
| 40 | + |
| 41 | + render(true) |
| 42 | + const dialog = container.querySelector<HTMLElement>('[role="dialog"]')! |
| 43 | + const input = container.querySelector<HTMLInputElement>('input')! |
| 44 | + const scrollBody = input.parentElement! |
| 45 | + expect(dialog.getAttribute('aria-label')).toBe('Configure workflow') |
| 46 | + expect(dialog.classList.contains('translate-x-0')).toBe(true) |
| 47 | + expect(dialog.classList.contains('shadow-overlay')).toBe(true) |
| 48 | + |
| 49 | + input.value = 'Edited workflow' |
| 50 | + scrollBody.scrollTop = 64 |
| 51 | + render(false) |
| 52 | + expect(container.querySelector('[role="dialog"]')).toBe(dialog) |
| 53 | + expect(container.querySelector('input')).toBe(input) |
| 54 | + expect(input.value).toBe('Edited workflow') |
| 55 | + expect(input.parentElement).toBe(scrollBody) |
| 56 | + expect(scrollBody.scrollTop).toBe(64) |
| 57 | + expect(dialog.classList.contains('translate-x-full')).toBe(true) |
| 58 | + expect(dialog.classList.contains('shadow-overlay')).toBe(false) |
| 59 | + |
| 60 | + render(true) |
| 61 | + expect(dialog.classList.contains('translate-x-0')).toBe(true) |
| 62 | + expect(input.value).toBe('Edited workflow') |
| 63 | + expect(scrollBody.scrollTop).toBe(64) |
| 64 | + }) |
| 65 | +}) |
0 commit comments