@@ -18,6 +18,7 @@ import {
1818import dataModel from '../../../test/fixtures/data-model-with-relationships.json' ;
1919import type {
2020 MongoDBDataModelDescription ,
21+ DataModelCollection ,
2122 Relationship ,
2223} from '../../services/data-model-storage' ;
2324import { DrawerAnchor } from '@mongodb-js/compass-components' ;
@@ -73,12 +74,12 @@ describe('DiagramEditorSidePanel', function () {
7374 result . plugin . store . dispatch ( selectCollection ( 'flights.airlines' ) ) ;
7475
7576 await waitFor ( ( ) => {
76- expect ( screen . getByTitle ( 'flights.airlines' ) ) . to . exist ;
77+ expect ( screen . getByTitle ( 'flights.airlines' ) ) . to . be . visible ;
7778 } ) ;
7879
7980 const nameInput = screen . getByLabelText ( 'Name' ) ;
8081 expect ( nameInput ) . to . be . visible ;
81- expect ( nameInput ) . to . have . value ( 'flights. airlines' ) ;
82+ expect ( nameInput ) . to . have . value ( 'airlines' ) ;
8283
8384 userEvent . click ( screen . getByRole ( 'textbox' , { name : 'Notes' } ) ) ;
8485 userEvent . type (
@@ -149,14 +150,14 @@ describe('DiagramEditorSidePanel', function () {
149150 result . plugin . store . dispatch ( selectCollection ( 'flights.airlines' ) ) ;
150151
151152 await waitFor ( ( ) => {
152- expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'flights. airlines' ) ;
153+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'airlines' ) ;
153154 } ) ;
154155
155156 result . plugin . store . dispatch (
156157 selectCollection ( 'flights.airports_coordinates_for_schema' )
157158 ) ;
158159 expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value (
159- 'flights. airports_coordinates_for_schema'
160+ 'airports_coordinates_for_schema'
160161 ) ;
161162
162163 result . plugin . store . dispatch (
@@ -178,15 +179,15 @@ describe('DiagramEditorSidePanel', function () {
178179 ) . to . be . visible ;
179180
180181 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' ) ;
182183 } ) ;
183184
184185 it ( 'should open and edit relationship starting from collection' , async function ( ) {
185186 const result = renderDrawer ( ) ;
186187 result . plugin . store . dispatch ( selectCollection ( 'flights.countries' ) ) ;
187188
188189 await waitFor ( ( ) => {
189- expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'flights. countries' ) ;
190+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'countries' ) ;
190191 } ) ;
191192
192193 // Open relationshipt editing form
@@ -249,7 +250,7 @@ describe('DiagramEditorSidePanel', function () {
249250 result . plugin . store . dispatch ( selectCollection ( 'flights.countries' ) ) ;
250251
251252 await waitFor ( ( ) => {
252- expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'flights. countries' ) ;
253+ expect ( screen . getByLabelText ( 'Name' ) ) . to . have . value ( 'countries' ) ;
253254 } ) ;
254255
255256 // Find the relationhip item
@@ -270,4 +271,96 @@ describe('DiagramEditorSidePanel', function () {
270271 . exist ;
271272 } ) ;
272273 } ) ;
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+ } ) ;
273366} ) ;
0 commit comments