@@ -69,10 +69,19 @@ describe('UiFind', () => {
69
69
expect ( screen . getByPlaceholderText ( 'Find...' ) ) . toHaveValue ( uiFind ) ;
70
70
} ) ;
71
71
72
- it ( 'renders state.ownInputValue when it is not `undefined` regardless of props.uiFind' , async ( ) => {
72
+ it ( 'prioritizes state.ownInputValue over props.uiFind when ownInputValue is set' , async ( ) => {
73
+ // Test the initial state
73
74
const { rerender } = render ( < UnconnectedUiFindInput { ...props } uiFind = { uiFind } /> ) ;
75
+ expect ( screen . getByPlaceholderText ( 'Find...' ) ) . toHaveValue ( uiFind ) ;
76
+
77
+ // Test setting ownInputValue through user interaction
74
78
await userEvent . clear ( screen . getByPlaceholderText ( 'Find...' ) ) ;
75
79
await userEvent . type ( screen . getByPlaceholderText ( 'Find...' ) , ownInputValue ) ;
80
+
81
+ // Verify the state change affected the value
82
+ expect ( screen . getByPlaceholderText ( 'Find...' ) ) . toHaveValue ( ownInputValue ) ;
83
+
84
+ // Verify the precedence is maintained after re-render
76
85
rerender ( < UnconnectedUiFindInput { ...props } uiFind = { uiFind } /> ) ;
77
86
expect ( screen . getByPlaceholderText ( 'Find...' ) ) . toHaveValue ( ownInputValue ) ;
78
87
} ) ;
@@ -120,29 +129,30 @@ describe('UiFind', () => {
120
129
} ) ;
121
130
122
131
it ( 'no-ops if value is unchanged' , async ( ) => {
123
- // First render
124
- const { unmount } = render ( < UnconnectedUiFindInput { ...props } /> ) ;
125
- await userEvent . clear ( screen . getByPlaceholderText ( 'Find...' ) ) ;
126
- expect ( updateUiFindSpy ) . not . toHaveBeenCalled ( ) ;
127
- unmount ( ) ;
128
-
129
- // Second render
130
132
render ( < UnconnectedUiFindInput { ...props } uiFind = { uiFind } /> ) ;
131
- await userEvent . clear ( screen . getByPlaceholderText ( 'Find...' ) ) ;
132
- await userEvent . type ( screen . getByPlaceholderText ( 'Find...' ) , uiFind ) ;
133
+ const input = screen . getByPlaceholderText ( 'Find...' ) ;
134
+ await userEvent . clear ( input ) ;
135
+ await userEvent . type ( input , uiFind ) ;
133
136
const calls = updateUiFindSpy . mock . calls ;
134
137
const calledWithUnchanged = calls . some ( ( [ args ] ) => args && args . uiFind === uiFind ) ;
135
138
expect ( calledWithUnchanged ) . toBe ( false ) ;
136
139
} ) ;
137
140
} ) ;
138
141
139
142
describe ( 'blurring input' , ( ) => {
140
- it ( 'clears state.ownInputValue' , async ( ) => {
141
- render ( < UnconnectedUiFindInput { ...props } /> ) ;
142
- await userEvent . type ( screen . getByPlaceholderText ( 'Find...' ) , 'abc' ) ;
143
- expect ( screen . getByPlaceholderText ( 'Find...' ) ) . toHaveValue ( 'abc' ) ;
144
- screen . getByPlaceholderText ( 'Find...' ) . blur ( ) ;
145
- expect ( screen . getByPlaceholderText ( 'Find...' ) ) . toHaveValue ( props . uiFind || undefined ) ;
143
+ it ( 'clears state.ownInputValue and resets to props.uiFind' , async ( ) => {
144
+ render ( < UnconnectedUiFindInput { ...props } uiFind = { uiFind } /> ) ;
145
+ const input = screen . getByPlaceholderText ( 'Find...' ) ;
146
+ await userEvent . clear ( input ) ;
147
+ await userEvent . type ( input , 'abc' ) ;
148
+ expect ( input ) . toHaveValue ( 'abc' ) ;
149
+ await userEvent . tab ( ) ;
150
+ expect ( input ) . toHaveValue ( uiFind ) ;
151
+
152
+ // Verify that typing after blur starts from props.uiFind
153
+ await userEvent . clear ( input ) ;
154
+ await userEvent . type ( input , 'xyz' ) ;
155
+ expect ( input ) . toHaveValue ( 'xyz' ) ;
146
156
} ) ;
147
157
148
158
it ( 'triggers pending queryParameter updates' , async ( ) => {
@@ -172,10 +182,10 @@ describe('UiFind', () => {
172
182
expect ( screen . queryByTestId ( 'clear-icon' ) ) . not . toBeInTheDocument ( ) ;
173
183
} ) ;
174
184
175
- it ( 'clears value immediately when clicked' , ( ) => {
185
+ it ( 'clears value immediately when clicked' , async ( ) => {
176
186
render ( < UnconnectedUiFindInput { ...props } allowClear uiFind = { uiFind } /> ) ;
177
187
const clearIcon = screen . getByTestId ( 'clear-icon' ) ;
178
- clearIcon . dispatchEvent ( new MouseEvent ( ' click' , { bubbles : true } ) ) ;
188
+ await userEvent . click ( clearIcon ) ;
179
189
expect ( updateUiFindSpy ) . toHaveBeenLastCalledWith ( {
180
190
history : props . history ,
181
191
location : props . location ,
0 commit comments