@@ -36,6 +36,15 @@ const waitForDrawerToOpen = async () => {
3636 } ) ;
3737} ;
3838
39+ const updateInputWithBlur = ( label : string , text : string ) => {
40+ const input = screen . getByLabelText ( label ) ;
41+ userEvent . clear ( input ) ;
42+ userEvent . type ( input , text ) ;
43+
44+ // Blur/unfocus the input.
45+ userEvent . click ( document . body ) ;
46+ } ;
47+
3948async function comboboxSelectItem (
4049 label : string ,
4150 value : string ,
@@ -136,8 +145,8 @@ describe('DiagramEditorSidePanel', function () {
136145 ) . to . be . visible ;
137146 } ) ;
138147
139- describe ( 'Field context drawer ' , function ( ) {
140- it ( 'should render a field context drawer when field is clicked ' , async function ( ) {
148+ describe ( 'When a field is selected ' , function ( ) {
149+ it ( 'should render a field context drawer' , async function ( ) {
141150 const result = renderDrawer ( ) ;
142151 result . plugin . store . dispatch ( selectField ( 'flights.airlines' , [ 'alias' ] ) ) ;
143152
@@ -154,7 +163,7 @@ describe('DiagramEditorSidePanel', function () {
154163 expect ( selectedTypes ) . to . include ( 'int' ) ;
155164 } ) ;
156165
157- it ( 'should render a nested field context drawer when field is clicked ' , async function ( ) {
166+ it ( 'should render a nested field context drawer' , async function ( ) {
158167 const result = renderDrawer ( ) ;
159168 result . plugin . store . dispatch (
160169 selectField ( 'flights.routes' , [ 'airline' , 'id' ] )
@@ -171,6 +180,53 @@ describe('DiagramEditorSidePanel', function () {
171180 expect ( selectedTypes ) . to . have . lengthOf ( 1 ) ;
172181 expect ( selectedTypes ) . to . include ( 'string' ) ;
173182 } ) ;
183+
184+ it ( 'should delete a field' , async function ( ) {
185+ const result = renderDrawer ( ) ;
186+ result . plugin . store . dispatch (
187+ selectField ( 'flights.routes' , [ 'airline' , 'id' ] )
188+ ) ;
189+
190+ await waitForDrawerToOpen ( ) ;
191+ expect ( screen . getByTitle ( 'routes.airline.id' ) ) . to . be . visible ;
192+
193+ userEvent . click ( screen . getByLabelText ( / d e l e t e f i e l d / i) ) ;
194+
195+ await waitFor ( ( ) => {
196+ expect ( screen . queryByText ( 'routes.airline.id' ) ) . not . to . exist ;
197+ } ) ;
198+ expect ( screen . queryByLabelText ( 'Name' ) ) . to . not . exist ;
199+
200+ const modifiedCollection = selectCurrentModelFromState (
201+ result . plugin . store . getState ( )
202+ ) . collections . find ( ( coll ) => {
203+ return coll . ns === 'flights.routes' ;
204+ } ) ;
205+
206+ expect (
207+ modifiedCollection . jsonSchema . properties . airline . properties
208+ ) . to . not . have . property ( 'id' ) ; // deleted field
209+ expect (
210+ modifiedCollection . jsonSchema . properties . airline . properties
211+ ) . to . have . property ( 'name' ) ; // sibling field remains
212+ } ) ;
213+
214+ it ( 'should rename a field and keep it selected' , async function ( ) {
215+ const result = renderDrawer ( ) ;
216+ result . plugin . store . dispatch (
217+ selectField ( 'flights.routes' , [ 'airline' , 'name' ] )
218+ ) ;
219+
220+ await waitForDrawerToOpen ( ) ;
221+ expect ( screen . getByTitle ( 'routes.airline.name' ) ) . to . be . visible ;
222+
223+ updateInputWithBlur ( 'Field name' , 'new_name' ) ;
224+
225+ await waitFor ( ( ) => {
226+ expect ( screen . queryByText ( 'routes.airline.name' ) ) . not . to . exist ;
227+ expect ( screen . queryByText ( 'routes.airline.new_name' ) ) . to . exist ;
228+ } ) ;
229+ } ) ;
174230 } ) ;
175231
176232 it ( 'should change the content of the drawer when selecting different items' , async function ( ) {
@@ -486,11 +542,7 @@ describe('DiagramEditorSidePanel', function () {
486542 expect ( activeElement ) . to . equal ( nameInput ) ;
487543
488544 // Update the name.
489- userEvent . clear ( nameInput ) ;
490- userEvent . type ( nameInput , 'pineapple' ) ;
491-
492- // Blur/unfocus the input - now the collection should be names
493- userEvent . click ( document . body ) ;
545+ updateInputWithBlur ( 'Name' , 'pineapple' ) ;
494546
495547 // Check the name in the model.
496548 const newCollection = selectCurrentModelFromState (
0 commit comments