88 redoEdit ,
99 undoEdit ,
1010 selectFieldsForCurrentModel ,
11- startCreatingCollection ,
1211 addCollection ,
12+ nameDraftCollection ,
1313} from './diagram' ;
1414import type {
1515 Edit ,
@@ -21,14 +21,14 @@ import { UUID } from 'bson';
2121const model : StaticModel = {
2222 collections : [
2323 {
24- ns : 'collection1' ,
24+ ns : 'db. collection1' ,
2525 indexes : [ ] ,
2626 displayPosition : [ 0 , 0 ] ,
2727 shardKey : { } ,
2828 jsonSchema : { bsonType : 'object' } ,
2929 } ,
3030 {
31- ns : 'collection2' ,
31+ ns : 'db. collection2' ,
3232 indexes : [ ] ,
3333 displayPosition : [ 1 , 1 ] ,
3434 shardKey : { } ,
@@ -79,12 +79,12 @@ describe('Data Modeling store', function () {
7979 connectionId : 'connection-id' ,
8080 collections : [
8181 {
82- ns : 'collection1' ,
82+ ns : 'db. collection1' ,
8383 schema : model . collections [ 0 ] . jsonSchema ,
8484 position : { x : 0 , y : 0 } ,
8585 } ,
8686 {
87- ns : 'collection2' ,
87+ ns : 'db. collection2' ,
8888 schema : model . collections [ 1 ] . jsonSchema ,
8989 position : { x : 0 , y : 0 } ,
9090 } ,
@@ -142,7 +142,7 @@ describe('Data Modeling store', function () {
142142 model : {
143143 collections : [
144144 {
145- ns : 'collection2' ,
145+ ns : 'db. collection2' ,
146146 indexes : [ ] ,
147147 displayPosition : [ 0 , 0 ] ,
148148 shardKey : { } ,
@@ -229,22 +229,38 @@ describe('Data Modeling store', function () {
229229 store . dispatch ( openDiagram ( loadedDiagram ) ) ;
230230
231231 // start creating a new collection
232- store . dispatch ( startCreatingCollection ( ) ) ;
232+ store . dispatch ( addCollection ( ) ) ;
233233
234- // the new collection is not yet in the edit history
234+ // the new collection is in the diagram
235235 const diagramAtCreation = getCurrentDiagramFromState ( store . getState ( ) ) ;
236- expect ( diagramAtCreation . edits ) . to . deep . equal ( loadedDiagram . edits ) ;
236+ expect ( diagramAtCreation . edits ) . to . have . length ( 2 ) ;
237+ const firstAddCollectionEdit = diagramAtCreation . edits [ 1 ] as Extract <
238+ Edit ,
239+ { type : 'AddCollection' }
240+ > ;
241+ const firstCollectionDraftName = 'db.new-collection' ;
242+ expect ( firstAddCollectionEdit . type ) . to . equal ( 'AddCollection' ) ;
243+ expect ( firstAddCollectionEdit . ns ) . to . equal ( firstCollectionDraftName ) ;
244+ expect ( firstAddCollectionEdit . initialSchema ) . to . deep . equal ( {
245+ bsonType : 'object' ,
246+ properties : {
247+ _id : {
248+ bsonType : 'objectId' ,
249+ } ,
250+ } ,
251+ required : [ '_id' ] ,
252+ } ) ;
237253
238- // but the selection changes accordingly
254+ // the selection changes to the new collection
239255 const selectedItems = store . getState ( ) . diagram ?. selectedItems ;
240256 expect ( selectedItems ) . to . deep . equal ( {
241257 type : 'collection' ,
242- id : undefined ,
258+ id : firstCollectionDraftName ,
243259 } ) ;
244260
245- // save the new collection
246- const newCollectionNs = 'db.newCollection ' ;
247- store . dispatch ( addCollection ( newCollectionNs ) ) ;
261+ // name the new collection
262+ const newCollectionNs = 'db.myCollection ' ;
263+ store . dispatch ( nameDraftCollection ( newCollectionNs ) ) ;
248264
249265 // now the collection is added to the edit history
250266 const diagramAfterCreation = getCurrentDiagramFromState ( store . getState ( ) ) ;
@@ -277,6 +293,48 @@ describe('Data Modeling store', function () {
277293 } ) ;
278294 } ) ;
279295
296+ it ( 'should iterate the names for new collections' , function ( ) {
297+ store . dispatch ( openDiagram ( loadedDiagram ) ) ;
298+
299+ // start creating a new collection
300+ store . dispatch ( addCollection ( ) ) ;
301+
302+ // creates the first collection and makes it selected
303+ const firstCollectionDraftName = 'db.new-collection' ;
304+ const diagram1 = getCurrentDiagramFromState ( store . getState ( ) ) ;
305+ expect ( diagram1 . edits ) . to . have . length ( 2 ) ;
306+ const firstAddCollectionEdit = diagram1 . edits [ 1 ] as Extract <
307+ Edit ,
308+ { type : 'AddCollection' }
309+ > ;
310+ expect ( firstAddCollectionEdit . type ) . to . equal ( 'AddCollection' ) ;
311+ expect ( firstAddCollectionEdit . ns ) . to . equal ( firstCollectionDraftName ) ;
312+ const selectedItems1 = store . getState ( ) . diagram ?. selectedItems ;
313+ expect ( selectedItems1 ) . to . deep . equal ( {
314+ type : 'collection' ,
315+ id : firstCollectionDraftName ,
316+ } ) ;
317+
318+ // start creating another new collection
319+ store . dispatch ( addCollection ( ) ) ;
320+
321+ // creates the second collection and makes it selected
322+ const secondCollectionDraftName = 'db.new-collection-1' ;
323+ const diagramAtCreation = getCurrentDiagramFromState ( store . getState ( ) ) ;
324+ expect ( diagramAtCreation . edits ) . to . have . length ( 3 ) ;
325+ const secondAddCollectionEdit = diagramAtCreation . edits [ 2 ] as Extract <
326+ Edit ,
327+ { type : 'AddCollection' }
328+ > ;
329+ expect ( secondAddCollectionEdit . type ) . to . equal ( 'AddCollection' ) ;
330+ expect ( secondAddCollectionEdit . ns ) . to . equal ( secondCollectionDraftName ) ;
331+ const selectedItems2 = store . getState ( ) . diagram ?. selectedItems ;
332+ expect ( selectedItems2 ) . to . deep . equal ( {
333+ type : 'collection' ,
334+ id : secondCollectionDraftName ,
335+ } ) ;
336+ } ) ;
337+
280338 it ( 'should apply a valid MoveCollection edit' , function ( ) {
281339 store . dispatch ( openDiagram ( loadedDiagram ) ) ;
282340
@@ -361,7 +419,7 @@ describe('Data Modeling store', function () {
361419 model : {
362420 collections : [
363421 {
364- ns : 'collection1' ,
422+ ns : 'db. collection1' ,
365423 indexes : [ ] ,
366424 displayPosition : [ 0 , 0 ] ,
367425 shardKey : { } ,
@@ -382,7 +440,7 @@ describe('Data Modeling store', function () {
382440 const selectedFields = selectFieldsForCurrentModel ( edits ) ;
383441
384442 expect ( selectedFields ) . to . deep . equal ( {
385- collection1 : [ [ 'field1' ] , [ 'field2' ] , [ 'field3' ] ] ,
443+ 'db. collection1' : [ [ 'field1' ] , [ 'field2' ] , [ 'field3' ] ] ,
386444 } ) ;
387445 } ) ;
388446
@@ -395,7 +453,7 @@ describe('Data Modeling store', function () {
395453 model : {
396454 collections : [
397455 {
398- ns : 'collection1' ,
456+ ns : 'db. collection1' ,
399457 indexes : [ ] ,
400458 displayPosition : [ 0 , 0 ] ,
401459 shardKey : { } ,
@@ -471,29 +529,46 @@ describe('Data Modeling store', function () {
471529 } ,
472530 ] ;
473531 const selectedFields = selectFieldsForCurrentModel ( edits ) ;
474-
475- expect ( selectedFields ) . to . have . property ( 'collection1' ) ;
476- expect ( selectedFields . collection1 ) . to . deep . include ( [ 'prop1' ] ) ;
477- expect ( selectedFields . collection1 ) . to . deep . include ( [ 'prop2' ] ) ;
478- expect ( selectedFields . collection1 ) . to . deep . include ( [ 'prop2' , 'prop2A' ] ) ;
479- expect ( selectedFields . collection1 ) . to . deep . include ( [
532+ expect ( selectedFields ) . to . have . property ( 'db.collection1' ) ;
533+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [ 'prop1' ] ) ;
534+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [ 'prop2' ] ) ;
535+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [
536+ 'prop2' ,
537+ 'prop2A' ,
538+ ] ) ;
539+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [
480540 'prop2' ,
481541 'prop2B' ,
482542 'prop2B1' ,
483543 ] ) ;
484- expect ( selectedFields . collection1 ) . to . deep . include ( [
544+ expect ( selectedFields [ 'db .collection1' ] ) . to . deep . include ( [
485545 'prop2' ,
486546 'prop2B' ,
487547 'prop2B2' ,
488548 ] ) ;
489- expect ( selectedFields . collection1 ) . to . deep . include ( [ 'prop3' ] ) ;
490- expect ( selectedFields . collection1 ) . to . deep . include ( [ 'prop3' , 'prop3A' ] ) ;
491- expect ( selectedFields . collection1 ) . to . deep . include ( [ 'prop4' ] ) ;
492- expect ( selectedFields . collection1 ) . to . deep . include ( [ 'prop4' , 'prop4A' ] ) ;
493- expect ( selectedFields . collection1 ) . to . deep . include ( [ 'prop4' , 'prop4B' ] ) ;
494- expect ( selectedFields . collection1 ) . to . deep . include ( [ 'prop5' ] ) ;
495- expect ( selectedFields . collection1 ) . to . deep . include ( [ 'prop5' , 'prop5A' ] ) ;
496- expect ( selectedFields . collection1 ) . to . deep . include ( [ 'prop5' , 'prop5B' ] ) ;
549+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [ 'prop3' ] ) ;
550+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [
551+ 'prop3' ,
552+ 'prop3A' ,
553+ ] ) ;
554+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [ 'prop4' ] ) ;
555+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [
556+ 'prop4' ,
557+ 'prop4A' ,
558+ ] ) ;
559+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [
560+ 'prop4' ,
561+ 'prop4B' ,
562+ ] ) ;
563+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [ 'prop5' ] ) ;
564+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [
565+ 'prop5' ,
566+ 'prop5A' ,
567+ ] ) ;
568+ expect ( selectedFields [ 'db.collection1' ] ) . to . deep . include ( [
569+ 'prop5' ,
570+ 'prop5B' ,
571+ ] ) ;
497572 } ) ;
498573 } ) ;
499574} ) ;
0 commit comments