@@ -13,32 +13,32 @@ beforeEach(() => {
1313
1414describe ( 'ExpandTextDialog' , ( ) => {
1515 it ( 'should not render content when closed' , ( ) => {
16- render ( < ExpandTextDialog open = { false } value = '' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
16+ render ( < ExpandTextDialog open = { false } value = '' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
1717
1818 expect ( screen . queryByTestId ( 'expand-content-input' ) ) . not . toBeInTheDocument ( )
1919 } )
2020
2121 it ( 'should render with the provided value when open' , ( ) => {
22- render ( < ExpandTextDialog open = { true } value = 'Hello world' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
22+ render ( < ExpandTextDialog open = { true } value = 'Hello world' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
2323
2424 const textarea = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
2525 expect ( textarea ) . toHaveValue ( 'Hello world' )
2626 } )
2727
2828 it ( 'should render title when provided' , ( ) => {
29- render ( < ExpandTextDialog open = { true } value = '' title = 'Content' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
29+ render ( < ExpandTextDialog open = { true } value = '' title = 'Content' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
3030
3131 expect ( screen . getByText ( 'Content' ) ) . toBeInTheDocument ( )
3232 } )
3333
3434 it ( 'should not render title when not provided' , ( ) => {
35- render ( < ExpandTextDialog open = { true } value = '' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
35+ render ( < ExpandTextDialog open = { true } value = '' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
3636
3737 expect ( screen . queryByRole ( 'heading' ) ) . not . toBeInTheDocument ( )
3838 } )
3939
4040 it ( 'should call onConfirm with edited value when Save is clicked' , ( ) => {
41- render ( < ExpandTextDialog open = { true } value = 'Original' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
41+ render ( < ExpandTextDialog open = { true } value = 'Original' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
4242
4343 const textarea = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
4444 fireEvent . change ( textarea , { target : { value : 'Updated' } } )
@@ -48,7 +48,7 @@ describe('ExpandTextDialog', () => {
4848 } )
4949
5050 it ( 'should call onCancel when Cancel is clicked' , ( ) => {
51- render ( < ExpandTextDialog open = { true } value = 'Original' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
51+ render ( < ExpandTextDialog open = { true } value = 'Original' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
5252
5353 fireEvent . click ( screen . getByRole ( 'button' , { name : 'Cancel' } ) )
5454
@@ -57,25 +57,73 @@ describe('ExpandTextDialog', () => {
5757 } )
5858
5959 it ( 'should disable textarea and Save button when disabled' , ( ) => {
60- render ( < ExpandTextDialog open = { true } value = 'test' disabled = { true } onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
60+ render (
61+ < ExpandTextDialog open = { true } value = 'test' inputType = 'code' disabled = { true } onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
62+ )
6163
6264 const textarea = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
6365 expect ( textarea ) . toBeDisabled ( )
6466 expect ( screen . getByRole ( 'button' , { name : 'Save' } ) ) . toBeDisabled ( )
6567 } )
6668
6769 it ( 'should render placeholder when provided' , ( ) => {
68- render ( < ExpandTextDialog open = { true } value = '' placeholder = 'Type here...' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
70+ render (
71+ < ExpandTextDialog
72+ open = { true }
73+ value = ''
74+ inputType = 'code'
75+ placeholder = 'Type here...'
76+ onConfirm = { mockOnConfirm }
77+ onCancel = { mockOnCancel }
78+ />
79+ )
6980
7081 const textarea = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
7182 expect ( textarea ) . toHaveAttribute ( 'placeholder' , 'Type here...' )
7283 } )
7384
85+ it ( 'should show current value when opened after value changed while closed' , ( ) => {
86+ const { rerender } = render (
87+ < ExpandTextDialog open = { false } value = '' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
88+ )
89+
90+ // 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 } /> )
92+
93+ // 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 } /> )
95+
96+ const textarea = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
97+ expect ( textarea ) . toHaveValue ( 'Updated text' )
98+ } )
99+
100+ it ( 'should reset to current value when re-opened after cancel' , ( ) => {
101+ const { rerender } = render (
102+ < ExpandTextDialog open = { true } value = 'Original' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
103+ )
104+
105+ // User types in the dialog then cancels
106+ const textarea = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
107+ fireEvent . change ( textarea , { target : { value : 'Unsaved edits' } } )
108+ fireEvent . click ( screen . getByRole ( 'button' , { name : 'Cancel' } ) )
109+
110+ // Close the dialog
111+ rerender ( < ExpandTextDialog open = { false } value = 'Original' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
112+
113+ // Re-open — should show the original value, not the unsaved edits
114+ rerender ( < ExpandTextDialog open = { true } value = 'Original' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
115+
116+ const textarea2 = screen . getByTestId ( 'expand-content-input' ) . querySelector ( 'textarea' ) !
117+ expect ( textarea2 ) . toHaveValue ( 'Original' )
118+ } )
119+
74120 // --- Rich text mode ---
75121
76- describe ( 'mode="richtext" ' , ( ) => {
122+ describe ( 'inputType="string" (richtext) ' , ( ) => {
77123 it ( 'should render the TipTap editor instead of a TextField' , async ( ) => {
78- render ( < ExpandTextDialog open = { true } value = '<p>Hello</p>' mode = 'richtext' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
124+ render (
125+ < ExpandTextDialog open = { true } value = '<p>Hello</p>' inputType = 'string' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
126+ )
79127
80128 // RichTextEditor renders data-testid='rich-text-editor' which wraps tiptap
81129 expect ( await screen . findByTestId ( 'rich-text-editor' ) ) . toBeInTheDocument ( )
@@ -85,15 +133,17 @@ describe('ExpandTextDialog', () => {
85133 expect ( screen . queryByTestId ( 'expand-content-input' ) ) . not . toBeInTheDocument ( )
86134 } )
87135
88- it ( 'should render plain TextField in default text mode ' , ( ) => {
89- render ( < ExpandTextDialog open = { true } value = 'Hello' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
136+ it ( 'should render plain TextField for non-string input types ' , ( ) => {
137+ render ( < ExpandTextDialog open = { true } value = 'Hello' inputType = 'code' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
90138
91139 expect ( screen . getByTestId ( 'expand-content-input' ) ) . toBeInTheDocument ( )
92140 expect ( screen . queryByTestId ( 'rich-text-editor' ) ) . not . toBeInTheDocument ( )
93141 } )
94142
95143 it ( 'should still show Save and Cancel buttons in richtext mode' , ( ) => {
96- render ( < ExpandTextDialog open = { true } value = '<p>Hello</p>' mode = 'richtext' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
144+ render (
145+ < ExpandTextDialog open = { true } value = '<p>Hello</p>' inputType = 'string' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
146+ )
97147
98148 expect ( screen . getByRole ( 'button' , { name : 'Save' } ) ) . toBeInTheDocument ( )
99149 expect ( screen . getByRole ( 'button' , { name : 'Cancel' } ) ) . toBeInTheDocument ( )
@@ -104,7 +154,7 @@ describe('ExpandTextDialog', () => {
104154 < ExpandTextDialog
105155 open = { true }
106156 value = '<p>Hello</p>'
107- mode = 'richtext '
157+ inputType = 'string '
108158 disabled = { true }
109159 onConfirm = { mockOnConfirm }
110160 onCancel = { mockOnCancel }
@@ -116,14 +166,23 @@ describe('ExpandTextDialog', () => {
116166
117167 it ( 'should render title in richtext mode' , ( ) => {
118168 render (
119- < ExpandTextDialog open = { true } value = '' title = 'Content' mode = 'richtext' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
169+ < ExpandTextDialog
170+ open = { true }
171+ value = ''
172+ title = 'Content'
173+ inputType = 'string'
174+ onConfirm = { mockOnConfirm }
175+ onCancel = { mockOnCancel }
176+ />
120177 )
121178
122179 expect ( screen . getByText ( 'Content' ) ) . toBeInTheDocument ( )
123180 } )
124181
125182 it ( 'should call onCancel when Cancel is clicked in richtext mode' , ( ) => {
126- render ( < ExpandTextDialog open = { true } value = '<p>Hello</p>' mode = 'richtext' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } /> )
183+ render (
184+ < ExpandTextDialog open = { true } value = '<p>Hello</p>' inputType = 'string' onConfirm = { mockOnConfirm } onCancel = { mockOnCancel } />
185+ )
127186
128187 fireEvent . click ( screen . getByRole ( 'button' , { name : 'Cancel' } ) )
129188
0 commit comments