1
+ const mockDiagramming = {
2
+ // Keep original exports by spreading them (if needed)
3
+ ...require ( '@mongodb-js/diagramming' ) ,
4
+
5
+ // Override Diagram import because it's causing esm/cjs interop issues
6
+ Diagram : ( props ) => (
7
+ < div data-testid = "mock-diagram" >
8
+ { Object . entries ( props ) . map ( ( [ key , value ] ) => (
9
+ < div key = { key } data-testid = { `diagram-prop-${ key } ` } >
10
+ { JSON . stringify ( value ) }
11
+ </ div >
12
+ ) ) }
13
+ </ div >
14
+ ) ,
15
+ applyLayout : async ( nodes ) => {
16
+ return {
17
+ nodes : nodes . map ( ( node , index ) => ( {
18
+ ...node ,
19
+ position : { x : ( index + 1 ) * 100 , y : ( index + 1 ) * 100 } ,
20
+ } ) ) ,
21
+ } ;
22
+ } ,
23
+ } ;
24
+ ( require . cache [ require . resolve ( '@mongodb-js/diagramming' ) ] as any ) . exports =
25
+ mockDiagramming ;
26
+
1
27
import React from 'react' ;
2
28
import { expect } from 'chai' ;
3
29
import {
@@ -9,7 +35,10 @@ import DiagramEditor from './diagram-editor';
9
35
import { renderWithOpenedDiagramStore } from '../../test/setup-store' ;
10
36
import type { DataModelingStore } from '../../test/setup-store' ;
11
37
import { DataModelStorageServiceProvider } from '../provider' ;
12
- import type { MongoDBDataModelDescription } from '../services/data-model-storage' ;
38
+ import type {
39
+ Edit ,
40
+ MongoDBDataModelDescription ,
41
+ } from '../services/data-model-storage' ;
13
42
import { DiagramProvider } from '@mongodb-js/diagramming' ;
14
43
15
44
const storageItems : MongoDBDataModelDescription [ ] = [
@@ -28,7 +57,14 @@ const storageItems: MongoDBDataModelDescription[] = [
28
57
{
29
58
ns : 'db1.collection1' ,
30
59
indexes : [ ] ,
31
- displayPosition : [ 1 , 1 ] ,
60
+ displayPosition : [ - 1 , - 1 ] ,
61
+ shardKey : { } ,
62
+ jsonSchema : { bsonType : 'object' } ,
63
+ } ,
64
+ {
65
+ ns : 'db1.collection2' ,
66
+ indexes : [ ] ,
67
+ displayPosition : [ - 1 , - 1 ] ,
32
68
shardKey : { } ,
33
69
jsonSchema : { bsonType : 'object' } ,
34
70
} ,
@@ -61,7 +97,6 @@ const renderDiagramEditor = async ({
61
97
return Promise . resolve ( items . find ( ( x ) => x . id === id ) ?? null ) ;
62
98
} ,
63
99
} ;
64
- console . log ( DiagramProvider ) ;
65
100
const result = await renderWithOpenedDiagramStore (
66
101
< DataModelStorageServiceProvider storage = { mockDataModelStorage } >
67
102
< DiagramProvider fitView >
@@ -86,12 +121,25 @@ describe.only('DiagramEditor', function () {
86
121
store = result . store ;
87
122
88
123
// wait till the editor is loaded
89
- // await waitFor(() => {
90
- // expect(screen.getByTestId('model-preview')).to.be.visible;
91
- // });
124
+ await waitFor ( ( ) => {
125
+ expect ( screen . getByTestId ( 'model-preview' ) ) . to . be . visible ;
126
+ } ) ;
92
127
} ) ;
93
128
94
- it ( 'shows the list of diagrams' , async function ( ) {
95
- // screen.debug()
129
+ it ( 'applies the initial layout to unpositioned nodes' , async function ( ) {
130
+ const state = store . getState ( ) ;
131
+
132
+ expect ( state . diagram ?. edits . current ) . to . have . lengthOf ( 1 ) ;
133
+ expect ( state . diagram ?. edits . current [ 0 ] . type ) . to . equal ( 'SetModel' ) ;
134
+ const initialEdit = state . diagram ?. edits . current [ 0 ] as Extract <
135
+ Edit ,
136
+ { type : 'SetModel' }
137
+ > ;
138
+ expect ( initialEdit . model ?. collections [ 0 ] . displayPosition ) . to . deep . equal ( [
139
+ 100 , 100 ,
140
+ ] ) ;
141
+ expect ( initialEdit . model ?. collections [ 1 ] . displayPosition ) . to . deep . equal ( [
142
+ 200 , 200 ,
143
+ ] ) ;
96
144
} ) ;
97
145
} ) ;
0 commit comments