@@ -39,7 +39,7 @@ const waitForDrawerToOpen = async () => {
3939const updateInputWithBlur = ( label : string , text : string ) => {
4040 const input = screen . getByLabelText ( label ) ;
4141 userEvent . clear ( input ) ;
42- userEvent . type ( input , text ) ;
42+ if ( text . length ) userEvent . type ( input , text ) ;
4343
4444 // Blur/unfocus the input.
4545 userEvent . click ( document . body ) ;
@@ -227,6 +227,40 @@ describe('DiagramEditorSidePanel', function () {
227227 expect ( screen . queryByText ( 'routes.airline.new_name' ) ) . to . exist ;
228228 } ) ;
229229 } ) ;
230+
231+ it ( 'should not rename a field to an empty string' , async function ( ) {
232+ const result = renderDrawer ( ) ;
233+ result . plugin . store . dispatch (
234+ selectField ( 'flights.routes' , [ 'airline' , 'name' ] )
235+ ) ;
236+
237+ await waitForDrawerToOpen ( ) ;
238+ expect ( screen . getByTitle ( 'routes.airline.name' ) ) . to . be . visible ;
239+
240+ updateInputWithBlur ( 'Field name' , '' ) ;
241+
242+ await waitFor ( ( ) => {
243+ expect ( screen . queryByText ( 'Field name cannot be empty.' ) ) . to . exist ;
244+ expect ( screen . queryByText ( 'routes.airline.name' ) ) . to . exist ;
245+ } ) ;
246+ } ) ;
247+
248+ it ( 'should not rename a field to a duplicate' , async function ( ) {
249+ const result = renderDrawer ( ) ;
250+ result . plugin . store . dispatch (
251+ selectField ( 'flights.routes' , [ 'airline' , 'name' ] )
252+ ) ;
253+
254+ await waitForDrawerToOpen ( ) ;
255+ expect ( screen . getByTitle ( 'routes.airline.name' ) ) . to . be . visible ;
256+
257+ updateInputWithBlur ( 'Field name' , 'id' ) ;
258+
259+ await waitFor ( ( ) => {
260+ expect ( screen . queryByText ( 'Field already exists.' ) ) . to . exist ;
261+ expect ( screen . queryByText ( 'routes.airline.name' ) ) . to . exist ;
262+ } ) ;
263+ } ) ;
230264 } ) ;
231265
232266 it ( 'should change the content of the drawer when selecting different items' , async function ( ) {
0 commit comments