|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * objectstack#27356 (hotcrm#2320 Studio S5) — a Create Record node's field |
| 5 | + * names were cut to four or five characters ("subj", "dueD"): each map row put |
| 6 | + * the field box, the value box and two buttons on one line, so the narrow |
| 7 | + * inspector split its width between them. A row now stacks: the field on its |
| 8 | + * own line beside the remove button, the value on the line under it beside the |
| 9 | + * text / expression toggle. |
| 10 | + * |
| 11 | + * jsdom draws no layout, so the pin is the row's structure, read through |
| 12 | + * `FlowNodeConfigField` (the editor's only caller) on a `create_record` node: |
| 13 | + * the field box never shares a line with the value box. The same editor draws |
| 14 | + * every key / value map in the flow inspector; the HTTP `headers` map is the |
| 15 | + * second case, a map with no value toggle. |
| 16 | + */ |
| 17 | + |
| 18 | +import { describe, it, expect, afterEach, vi } from 'vitest'; |
| 19 | +import { render, screen, cleanup } from '@testing-library/react'; |
| 20 | + |
| 21 | +vi.mock('../previews/useObjectFields', () => ({ |
| 22 | + useObjectFields: () => ({ fields: [], loading: false, error: null }), |
| 23 | +})); |
| 24 | + |
| 25 | +import { FlowNodeConfigField } from './FlowNodeConfigField'; |
| 26 | +import type { FlowConfigField } from './flow-node-config'; |
| 27 | + |
| 28 | +afterEach(cleanup); |
| 29 | + |
| 30 | +const TOGGLE = 'Write as a CEL expression'; |
| 31 | +const REMOVE = /remove/i; |
| 32 | +const LONG_FIELD = 'customer_satisfaction_score'; |
| 33 | + |
| 34 | +function renderMap(field: FlowConfigField, nodeType: string, value: Record<string, unknown>) { |
| 35 | + render( |
| 36 | + <FlowNodeConfigField |
| 37 | + field={field} |
| 38 | + value={value} |
| 39 | + onCommit={vi.fn()} |
| 40 | + context={{ draft: {}, node: { id: 'n1', type: nodeType, config: { objectName: 'case' } } }} |
| 41 | + />, |
| 42 | + ); |
| 43 | +} |
| 44 | + |
| 45 | +/** The line a box sits on: the row's key line or value line. */ |
| 46 | +const lineOf = (el: HTMLElement) => el.closest('[data-testid^="flow-kv-"]') as HTMLElement; |
| 47 | + |
| 48 | +describe('a key / value map row stacks the field over its value (objectstack#27356)', () => { |
| 49 | + it('Create Record: the long field name has its own line, beside the remove button only', () => { |
| 50 | + renderMap( |
| 51 | + { id: 'fields', path: ['config', 'fields'], label: 'Field values', kind: 'keyValue' }, |
| 52 | + 'create_record', |
| 53 | + { [LONG_FIELD]: '5' }, |
| 54 | + ); |
| 55 | + const key = screen.getByDisplayValue(LONG_FIELD); |
| 56 | + const value = screen.getByDisplayValue('5'); |
| 57 | + const keyLine = lineOf(key); |
| 58 | + |
| 59 | + expect(keyLine.contains(value)).toBe(false); |
| 60 | + expect(keyLine.querySelectorAll('input')).toHaveLength(1); |
| 61 | + const buttons = [...keyLine.querySelectorAll('button')]; |
| 62 | + expect(buttons).toHaveLength(1); |
| 63 | + expect(buttons[0]!.getAttribute('aria-label')).toMatch(REMOVE); |
| 64 | + |
| 65 | + // The value's line carries the text / expression toggle, under the field. |
| 66 | + const valueLine = lineOf(value); |
| 67 | + expect(valueLine).not.toBe(keyLine); |
| 68 | + expect(valueLine.contains(screen.getByRole('button', { name: TOGGLE }))).toBe(true); |
| 69 | + expect(keyLine.compareDocumentPosition(valueLine) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); |
| 70 | + }); |
| 71 | + |
| 72 | + it('a map with no value toggle (HTTP headers) stacks the same way', () => { |
| 73 | + renderMap( |
| 74 | + { id: 'headers', path: ['config', 'headers'], label: 'Headers', kind: 'keyValue' }, |
| 75 | + 'http', |
| 76 | + { 'X-Request-Correlation-Id': 'abc' }, |
| 77 | + ); |
| 78 | + const key = screen.getByDisplayValue('X-Request-Correlation-Id'); |
| 79 | + expect(lineOf(key).contains(screen.getByDisplayValue('abc'))).toBe(false); |
| 80 | + expect(screen.queryByRole('button', { name: TOGGLE })).toBeNull(); |
| 81 | + }); |
| 82 | +}); |
0 commit comments