1
- const mockDiagramming = {
2
- // Keep original exports by spreading them (if needed)
3
- // eslint-disable-next-line @typescript-eslint/no-require-imports
4
- ...require ( '@mongodb-js/diagramming' ) ,
5
-
6
- // Override Diagram import because it's causing esm/cjs interop issues
7
- Diagram : ( props : any ) => (
8
- < div data-testid = "mock-diagram" >
9
- { Object . entries ( props ) . map ( ( [ key , value ] ) => (
10
- < div key = { key } data-testid = { `diagram-prop-${ key } ` } >
11
- { JSON . stringify ( value ) }
12
- </ div >
13
- ) ) }
14
- </ div >
15
- ) ,
16
- applyLayout : ( nodes : any ) => {
17
- return {
18
- nodes : nodes . map ( ( node : any , index : number ) => ( {
19
- ...node ,
20
- position : { x : ( index + 1 ) * 100 , y : ( index + 1 ) * 100 } ,
21
- } ) ) ,
22
- } ;
23
- } ,
24
- } ;
25
- ( require . cache [ require . resolve ( '@mongodb-js/diagramming' ) ] as any ) . exports =
26
- mockDiagramming ;
27
-
28
1
import React from 'react' ;
29
2
import { expect } from 'chai' ;
30
3
import {
@@ -38,6 +11,8 @@ import type {
38
11
Edit ,
39
12
MongoDBDataModelDescription ,
40
13
} from '../services/data-model-storage' ;
14
+ import diagramming from '@mongodb-js/diagramming' ;
15
+ import sinon from 'sinon' ;
41
16
import { DiagramProvider } from '@mongodb-js/diagramming' ;
42
17
import { DataModelingWorkspaceTab } from '..' ;
43
18
import { openDiagram } from '../store/diagram' ;
@@ -111,6 +86,27 @@ const storageItems: MongoDBDataModelDescription[] = [
111
86
} ,
112
87
] ;
113
88
89
+ const mockDiagramming = {
90
+ // Override Diagram import because it's causing esm/cjs interop issues
91
+ Diagram : ( props : any ) => (
92
+ < div data-testid = "mock-diagram" >
93
+ { Object . entries ( props ) . map ( ( [ key , value ] ) => (
94
+ < div key = { key } data-testid = { `diagram-prop-${ key } ` } >
95
+ { JSON . stringify ( value ) }
96
+ </ div >
97
+ ) ) }
98
+ </ div >
99
+ ) ,
100
+ applyLayout : ( nodes : any ) => {
101
+ return {
102
+ nodes : nodes . map ( ( node : any , index : number ) => ( {
103
+ ...node ,
104
+ position : { x : ( index + 1 ) * 100 , y : ( index + 1 ) * 100 } ,
105
+ } ) ) ,
106
+ } ;
107
+ } ,
108
+ } ;
109
+
114
110
const renderDiagramEditor = ( {
115
111
items = storageItems ,
116
112
renderedItem = items [ 0 ] ,
@@ -159,6 +155,14 @@ const renderDiagramEditor = ({
159
155
describe ( 'DiagramEditor' , function ( ) {
160
156
let store : DataModelingStore ;
161
157
158
+ before ( function ( ) {
159
+ // We need to tub the Diagram import because it has problems with ESM/CJS interop
160
+ sinon . stub ( diagramming , 'Diagram' ) . callsFake ( mockDiagramming . Diagram ) ;
161
+ sinon
162
+ . stub ( diagramming , 'applyLayout' )
163
+ . callsFake ( mockDiagramming . applyLayout as any ) ;
164
+ } ) ;
165
+
162
166
context ( 'with initial diagram' , function ( ) {
163
167
beforeEach ( async function ( ) {
164
168
const result = renderDiagramEditor ( {
0 commit comments