@@ -4,6 +4,12 @@ import { ExpandTextDialog } from './ExpandTextDialog'
44
55// TipTap modules are auto-mocked via moduleNameMapper in jest.config.js
66
7+ jest . mock ( './CodeInput' , ( ) => ( {
8+ CodeInput : ( { value, language } : { value : string ; language ?: string } ) => (
9+ < textarea data-testid = 'code-input' data-language = { language } value = { value } onChange = { ( ) => { } } />
10+ )
11+ } ) )
12+
713const mockOnConfirm = jest . fn ( )
814const mockOnCancel = jest . fn ( )
915
@@ -13,32 +19,34 @@ beforeEach(() => {
1319
1420describe ( 'ExpandTextDialog' , ( ) => {
1521 it ( 'should not render content when closed' , ( ) => {
16- render ( < ExpandTextDialog open = { false } value = '' inputType = 'code ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
22+ render ( < ExpandTextDialog open = { false } value = '' inputType = 'number ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
1723
1824 expect ( screen . queryByTestId ( 'expand-content-input' ) ) . not . toBeInTheDocument ( )
1925 } )
2026
2127 it ( 'should render with the provided value when open' , ( ) => {
22- render ( < ExpandTextDialog open = { true } value = 'Hello world' inputType = 'code ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
28+ render ( < ExpandTextDialog open = { true } value = 'Hello world' inputType = 'number ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
2329
2430 const textarea = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
2531 expect ( textarea ) . toHaveValue ( 'Hello world' )
2632 } )
2733
2834 it ( 'should render title when provided' , ( ) => {
29- render ( < ExpandTextDialog open = { true } value = '' title = 'Content' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
35+ render (
36+ < ExpandTextDialog open = { true } value = '' title = 'Content' inputType = 'number' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
37+ )
3038
3139 expect ( screen . getByText ( 'Content' ) ) . toBeInTheDocument ( )
3240 } )
3341
3442 it ( 'should not render title when not provided' , ( ) => {
35- render ( < ExpandTextDialog open = { true } value = '' inputType = 'code ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
43+ render ( < ExpandTextDialog open = { true } value = '' inputType = 'number ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
3644
3745 expect ( screen . queryByRole ( 'heading' ) ) . not . toBeInTheDocument ( )
3846 } )
3947
4048 it ( 'should call onConfirm with edited value when Save is clicked' , ( ) => {
41- render ( < ExpandTextDialog open = { true } value = 'Original' inputType = 'code ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
49+ render ( < ExpandTextDialog open = { true } value = 'Original' inputType = 'number ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
4250
4351 const textarea = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
4452 fireEvent . change ( textarea , { target : { value : 'Updated' } } )
@@ -48,7 +56,7 @@ describe('ExpandTextDialog', () => {
4856 } )
4957
5058 it ( 'should call onCancel when Cancel is clicked' , ( ) => {
51- render ( < ExpandTextDialog open = { true } value = 'Original' inputType = 'code ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
59+ render ( < ExpandTextDialog open = { true } value = 'Original' inputType = 'number ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
5260
5361 fireEvent . click ( screen . getByRole ( 'button' , { name : 'Cancel' } ) )
5462
@@ -58,7 +66,14 @@ describe('ExpandTextDialog', () => {
5866
5967 it ( 'should disable textarea and Save button when disabled' , ( ) => {
6068 render (
61- < ExpandTextDialog open = { true } value = 'test' inputType = 'code' disabled = { true } onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
69+ < ExpandTextDialog
70+ open = { true }
71+ value = 'test'
72+ inputType = 'number'
73+ disabled = { true }
74+ onConfirm = { mockOnConfirm }
75+ onCancel = { mockOnCancel }
76+ />
6277 )
6378
6479 const textarea = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
@@ -71,7 +86,7 @@ describe('ExpandTextDialog', () => {
7186 < ExpandTextDialog
7287 open = { true }
7388 value = ''
74- inputType = 'code '
89+ inputType = 'number '
7590 placeholder = 'Type here...'
7691 onConfirm = { mockOnConfirm }
7792 onCancel = { mockOnCancel }
@@ -84,22 +99,24 @@ describe('ExpandTextDialog', () => {
8499
85100 it ( 'should show current value when opened after value changed while closed' , ( ) => {
86101 const { rerender } = render (
87- < ExpandTextDialog open = { false } value = '' inputType = 'code ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
102+ < ExpandTextDialog open = { false } value = '' inputType = 'number ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
88103 )
89104
90105 // Simulate value changing while dialog is closed (user typing in inline editor)
91- rerender ( < ExpandTextDialog open = { false } value = 'Updated text' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
106+ rerender (
107+ < ExpandTextDialog open = { false } value = 'Updated text' inputType = 'number' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
108+ )
92109
93110 // Open the dialog — it should show the updated value, not the initial empty value
94- rerender ( < ExpandTextDialog open = { true } value = 'Updated text' inputType = 'code ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
111+ rerender ( < ExpandTextDialog open = { true } value = 'Updated text' inputType = 'number ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
95112
96113 const textarea = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
97114 expect ( textarea ) . toHaveValue ( 'Updated text' )
98115 } )
99116
100117 it ( 'should reset to current value when re-opened after cancel' , ( ) => {
101118 const { rerender } = render (
102- < ExpandTextDialog open = { true } value = 'Original' inputType = 'code ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
119+ < ExpandTextDialog open = { true } value = 'Original' inputType = 'number ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
103120 )
104121
105122 // User types in the dialog then cancels
@@ -108,15 +125,58 @@ describe('ExpandTextDialog', () => {
108125 fireEvent . click ( screen . getByRole ( 'button' , { name : 'Cancel' } ) )
109126
110127 // Close the dialog
111- rerender ( < ExpandTextDialog open = { false } value = 'Original' inputType = 'code ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
128+ rerender ( < ExpandTextDialog open = { false } value = 'Original' inputType = 'number ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
112129
113130 // Re-open — should show the original value, not the unsaved edits
114- rerender ( < ExpandTextDialog open = { true } value = 'Original' inputType = 'code ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
131+ rerender ( < ExpandTextDialog open = { true } value = 'Original' inputType = 'number ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
115132
116133 const textarea2 = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
117134 expect ( textarea2 ) . toHaveValue ( 'Original' )
118135 } )
119136
137+ // --- Code mode ---
138+
139+ describe ( 'inputType="code"' , ( ) => {
140+ it ( 'should render CodeInput instead of TextField' , ( ) => {
141+ render (
142+ < ExpandTextDialog
143+ open = { true }
144+ value = 'const x = 1'
145+ inputType = 'code'
146+ language = 'javascript'
147+ onConfirm = { mockOnConfirm }
148+ onCancel = { mockOnCancel }
149+ />
150+ )
151+
152+ expect ( screen . getByTestId ( 'code-input' ) ) . toBeInTheDocument ( )
153+ expect ( screen . queryByTestId ( 'expand-content-input' ) ) . not . toBeInTheDocument ( )
154+ expect ( screen . queryByTestId ( 'rich-text-editor' ) ) . not . toBeInTheDocument ( )
155+ } )
156+
157+ it ( 'should pass language prop to CodeInput' , ( ) => {
158+ render (
159+ < ExpandTextDialog
160+ open = { true }
161+ value = '{}'
162+ inputType = 'code'
163+ language = 'json'
164+ onConfirm = { mockOnConfirm }
165+ onCancel = { mockOnCancel }
166+ />
167+ )
168+
169+ expect ( screen . getByTestId ( 'code-input' ) ) . toHaveAttribute ( 'data-language' , 'json' )
170+ } )
171+
172+ it ( 'should show Save and Cancel buttons in code mode' , ( ) => {
173+ render ( < ExpandTextDialog open = { true } value = '' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
174+
175+ expect ( screen . getByRole ( 'button' , { name : 'Save' } ) ) . toBeInTheDocument ( )
176+ expect ( screen . getByRole ( 'button' , { name : 'Cancel' } ) ) . toBeInTheDocument ( )
177+ } )
178+ } )
179+
120180 // --- Rich text mode ---
121181
122182 describe ( 'inputType="string" (richtext)' , ( ) => {
@@ -133,11 +193,12 @@ describe('ExpandTextDialog', () => {
133193 expect ( screen . queryByTestId ( 'expand-content-input' ) ) . not . toBeInTheDocument ( )
134194 } )
135195
136- it ( 'should render plain TextField for non-string input types' , ( ) => {
137- render ( < ExpandTextDialog open = { true } value = 'Hello' inputType = 'code ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
196+ it ( 'should render plain TextField for non-string, non-code input types' , ( ) => {
197+ render ( < ExpandTextDialog open = { true } value = 'Hello' inputType = 'number ' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
138198
139199 expect ( screen . getByTestId ( 'expand-content-input' ) ) . toBeInTheDocument ( )
140200 expect ( screen . queryByTestId ( 'rich-text-editor' ) ) . not . toBeInTheDocument ( )
201+ expect ( screen . queryByTestId ( 'code-input' ) ) . not . toBeInTheDocument ( )
141202 } )
142203
143204 it ( 'should still show Save and Cancel buttons in richtext mode' , ( ) => {
0 commit comments