@@ -18,6 +18,7 @@ import {
18
18
import dataModel from '../../../test/fixtures/data-model-with-relationships.json' ;
19
19
import type {
20
20
MongoDBDataModelDescription ,
21
+ DataModelCollection ,
21
22
Relationship ,
22
23
} from '../../services/data-model-storage' ;
23
24
import { DrawerAnchor } from '@mongodb-js/compass-components' ;
@@ -73,12 +74,12 @@ describe('DiagramEditorSidePanel', function () {
73
74
result . plugin . store . dispatch ( selectCollection ( 'flights.airlines' ) ) ;
74
75
75
76
await waitFor ( ( ) => {
76
- expect ( screen . getByTitle ( 'flights.airlines' ) ) . to . exist ;
77
+ expect ( screen . getByTitle ( 'flights.airlines' ) ) . to . be . visible ;
77
78
} ) ;
78
79
79
80
const nameInput = screen . getByLabelText ( 'Name' ) ;
80
81
expect ( nameInput ) . to . be . visible ;
81
- expect ( nameInput ) . to . have . value ( 'flights. airlines' ) ;
82
+ expect ( nameInput ) . to . have . value ( 'airlines' ) ;
82
83
83
84
userEvent . click ( screen . getByRole ( 'textbox' , { name : 'Notes' } ) ) ;
84
85
userEvent . type (
@@ -149,14 +150,14 @@ describe('DiagramEditorSidePanel', function () {
149
150
result . plugin . store . dispatch ( selectCollection ( 'flights.airlines' ) ) ;
150
151
151
152
await waitFor ( ( ) => {
152
- expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'flights. airlines' ) ;
153
+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'airlines' ) ;
153
154
} ) ;
154
155
155
156
result . plugin . store . dispatch (
156
157
selectCollection ( 'flights.airports_coordinates_for_schema' )
157
158
) ;
158
159
expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value (
159
- 'flights. airports_coordinates_for_schema'
160
+ 'airports_coordinates_for_schema'
160
161
) ;
161
162
162
163
result . plugin . store . dispatch (
@@ -178,15 +179,15 @@ describe('DiagramEditorSidePanel', function () {
178
179
) . to . be . visible ;
179
180
180
181
result . plugin . store . dispatch ( selectCollection ( 'flights.planes' ) ) ;
181
- expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'flights. planes' ) ;
182
+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'planes' ) ;
182
183
} ) ;
183
184
184
185
it ( 'should open and edit relationship starting from collection' , async function ( ) {
185
186
const result = renderDrawer ( ) ;
186
187
result . plugin . store . dispatch ( selectCollection ( 'flights.countries' ) ) ;
187
188
188
189
await waitFor ( ( ) => {
189
- expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'flights. countries' ) ;
190
+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'countries' ) ;
190
191
} ) ;
191
192
192
193
// Open relationshipt editing form
@@ -249,7 +250,7 @@ describe('DiagramEditorSidePanel', function () {
249
250
result . plugin . store . dispatch ( selectCollection ( 'flights.countries' ) ) ;
250
251
251
252
await waitFor ( ( ) => {
252
- expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'flights. countries' ) ;
253
+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'countries' ) ;
253
254
} ) ;
254
255
255
256
// Find the relationhip item
@@ -270,4 +271,96 @@ describe('DiagramEditorSidePanel', function () {
270
271
. exist ;
271
272
} ) ;
272
273
} ) ;
274
+
275
+ it ( 'should open and edit a collection name' , async function ( ) {
276
+ const result = renderDrawer ( ) ;
277
+ result . plugin . store . dispatch ( selectCollection ( 'flights.countries' ) ) ;
278
+
279
+ await waitFor ( ( ) => {
280
+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'countries' ) ;
281
+ } ) ;
282
+
283
+ // Update the name.
284
+ userEvent . clear ( screen . getByLabelText ( 'Name' ) ) ;
285
+ userEvent . type ( screen . getByLabelText ( 'Name' ) , 'pineapple' ) ;
286
+
287
+ // Blur/unfocus the input.
288
+ userEvent . click ( document . body ) ;
289
+
290
+ // Check the name in the model.
291
+ const modifiedCollection = selectCurrentModelFromState (
292
+ result . plugin . store . getState ( )
293
+ ) . collections . find ( ( c : DataModelCollection ) => {
294
+ return c . ns === 'flights.pineapple' ;
295
+ } ) ;
296
+
297
+ expect ( modifiedCollection ) . to . exist ;
298
+ } ) ;
299
+
300
+ it ( 'should prevent editing to an empty collection name' , async function ( ) {
301
+ const result = renderDrawer ( ) ;
302
+ result . plugin . store . dispatch ( selectCollection ( 'flights.countries' ) ) ;
303
+
304
+ await waitFor ( ( ) => {
305
+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'countries' ) ;
306
+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . attribute (
307
+ 'aria-invalid' ,
308
+ 'false'
309
+ ) ;
310
+ } ) ;
311
+
312
+ userEvent . clear ( screen . getByLabelText ( 'Name' ) ) ;
313
+
314
+ await waitFor ( ( ) => {
315
+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . attribute (
316
+ 'aria-invalid' ,
317
+ 'true'
318
+ ) ;
319
+ } ) ;
320
+
321
+ // Blur/unfocus the input.
322
+ userEvent . click ( document . body ) ;
323
+
324
+ const notModifiedCollection = selectCurrentModelFromState (
325
+ result . plugin . store . getState ( )
326
+ ) . collections . find ( ( c : DataModelCollection ) => {
327
+ return c . ns === 'flights.countries' ;
328
+ } ) ;
329
+
330
+ expect ( notModifiedCollection ) . to . exist ;
331
+ } ) ;
332
+
333
+ it ( 'should prevent editing to a duplicate collection name' , async function ( ) {
334
+ const result = renderDrawer ( ) ;
335
+ result . plugin . store . dispatch ( selectCollection ( 'flights.countries' ) ) ;
336
+
337
+ await waitFor ( ( ) => {
338
+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'countries' ) ;
339
+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . attribute (
340
+ 'aria-invalid' ,
341
+ 'false'
342
+ ) ;
343
+ } ) ;
344
+
345
+ userEvent . clear ( screen . getByLabelText ( 'Name' ) ) ;
346
+ userEvent . type ( screen . getByLabelText ( 'Name' ) , 'airlines' ) ;
347
+
348
+ await waitFor ( ( ) => {
349
+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . attribute (
350
+ 'aria-invalid' ,
351
+ 'true'
352
+ ) ;
353
+ } ) ;
354
+
355
+ // Blur/unfocus the input.
356
+ userEvent . click ( document . body ) ;
357
+
358
+ const notModifiedCollection = selectCurrentModelFromState (
359
+ result . plugin . store . getState ( )
360
+ ) . collections . find ( ( c : DataModelCollection ) => {
361
+ return c . ns === 'flights.countries' ;
362
+ } ) ;
363
+
364
+ expect ( notModifiedCollection ) . to . exist ;
365
+ } ) ;
273
366
} ) ;
0 commit comments