@@ -2,6 +2,7 @@ import { expect } from 'chai';
22import { type DataModelingStore , setupStore } from '../../test/setup-store' ;
33import {
44 applyEdit ,
5+ applyInitialLayout ,
56 getCurrentDiagramFromState ,
67 openDiagram ,
78 redoEdit ,
@@ -67,17 +68,83 @@ describe('Data Modeling store', function () {
6768 store = setupStore ( ) ;
6869 } ) ;
6970
70- it ( 'openDiagram' , function ( ) {
71- store . dispatch ( openDiagram ( loadedDiagram ) ) ;
71+ describe ( 'New Diagram' , function ( ) {
72+ it ( 'handles analysis finished + initial positions' , function ( ) {
73+ // ANALYSIS FINISHED
74+ const newDiagram = {
75+ name : 'New Diagram' ,
76+ connectionId : 'connection-id' ,
77+ collections : [
78+ { ns : 'collection1' , schema : model . collections [ 0 ] . jsonSchema } ,
79+ { ns : 'collection2' , schema : model . collections [ 1 ] . jsonSchema } ,
80+ ] ,
81+ relations : model . relationships ,
82+ } ;
83+ store . dispatch ( {
84+ type : 'data-modeling/analysis-stats/ANALYSIS_FINISHED' ,
85+ ...newDiagram ,
86+ } ) ;
7287
73- const diagram = getCurrentDiagramFromState ( store . getState ( ) ) ;
74- expect ( diagram . id ) . to . equal ( loadedDiagram . id ) ;
75- expect ( diagram . name ) . to . equal ( loadedDiagram . name ) ;
76- expect ( diagram . connectionId ) . to . equal ( loadedDiagram . connectionId ) ;
77- expect ( diagram . edits ) . to . deep . equal ( loadedDiagram . edits ) ;
88+ const initialDiagram = getCurrentDiagramFromState ( store . getState ( ) ) ;
89+ expect ( initialDiagram . name ) . to . equal ( newDiagram . name ) ;
90+ expect ( initialDiagram . connectionId ) . to . equal ( newDiagram . connectionId ) ;
91+ expect ( initialDiagram . edits ) . to . have . length ( 1 ) ;
92+ expect ( initialDiagram . edits [ 0 ] . type ) . to . equal ( 'SetModel' ) ;
93+ expect ( initialDiagram . edits [ 0 ] . model . collections [ 0 ] ) . to . deep . include ( {
94+ ns : newDiagram . collections [ 0 ] . ns ,
95+ jsonSchema : newDiagram . collections [ 0 ] . schema ,
96+ displayPosition : [ - 1 , - 1 ] ,
97+ } ) ;
98+ expect ( initialDiagram . edits [ 0 ] . model . collections [ 1 ] ) . to . deep . include ( {
99+ ns : newDiagram . collections [ 1 ] . ns ,
100+ jsonSchema : newDiagram . collections [ 1 ] . schema ,
101+ displayPosition : [ - 1 , - 1 ] ,
102+ } ) ;
103+ expect ( initialDiagram . edits [ 0 ] . model . relationships ) . to . deep . equal (
104+ newDiagram . relations
105+ ) ;
106+
107+ // INITIAL LAYOUT
108+ const positions : Record < string , [ number , number ] > = {
109+ [ newDiagram . collections [ 0 ] . ns ] : [ 10 , 10 ] ,
110+ [ newDiagram . collections [ 1 ] . ns ] : [ 50 , 50 ] ,
111+ } ;
112+ store . dispatch ( applyInitialLayout ( positions ) ) ;
113+
114+ const diagramWithLayout = getCurrentDiagramFromState ( store . getState ( ) ) ;
115+ expect ( diagramWithLayout . name ) . to . equal ( newDiagram . name ) ;
116+ expect ( diagramWithLayout . connectionId ) . to . equal ( newDiagram . connectionId ) ;
117+ expect ( diagramWithLayout . edits ) . to . have . length ( 1 ) ;
118+ expect ( diagramWithLayout . edits [ 0 ] . type ) . to . equal ( 'SetModel' ) ;
119+ expect ( diagramWithLayout . edits [ 0 ] . model . collections [ 0 ] ) . to . deep . include ( {
120+ ns : newDiagram . collections [ 0 ] . ns ,
121+ jsonSchema : newDiagram . collections [ 0 ] . schema ,
122+ displayPosition : positions [ newDiagram . collections [ 0 ] . ns ] ,
123+ } ) ;
124+ expect ( diagramWithLayout . edits [ 0 ] . model . collections [ 1 ] ) . to . deep . include ( {
125+ ns : newDiagram . collections [ 1 ] . ns ,
126+ jsonSchema : newDiagram . collections [ 1 ] . schema ,
127+ displayPosition : positions [ newDiagram . collections [ 1 ] . ns ] ,
128+ } ) ;
129+ expect ( diagramWithLayout . edits [ 0 ] . model . relationships ) . to . deep . equal (
130+ newDiagram . relations
131+ ) ;
132+ } ) ;
133+ } ) ;
134+
135+ describe ( 'Existing Diagram' , function ( ) {
136+ it ( 'openDiagram' , function ( ) {
137+ store . dispatch ( openDiagram ( loadedDiagram ) ) ;
138+
139+ const diagram = getCurrentDiagramFromState ( store . getState ( ) ) ;
140+ expect ( diagram . id ) . to . equal ( loadedDiagram . id ) ;
141+ expect ( diagram . name ) . to . equal ( loadedDiagram . name ) ;
142+ expect ( diagram . connectionId ) . to . equal ( loadedDiagram . connectionId ) ;
143+ expect ( diagram . edits ) . to . deep . equal ( loadedDiagram . edits ) ;
144+ } ) ;
78145 } ) ;
79146
80- describe ( 'applyEdit ' , function ( ) {
147+ describe ( 'Editing ' , function ( ) {
81148 it ( 'should apply a valid SetModel edit' , function ( ) {
82149 store . dispatch ( openDiagram ( loadedDiagram ) ) ;
83150
0 commit comments