@@ -14,6 +14,28 @@ import {
1414 createNumbersCollection ,
1515} from '../helpers/insert-data' ;
1616
17+ type DiagramInstance = {
18+ getNodes : ( ) => Array < { id : string ; data : { title : string } } > ;
19+ } ;
20+
21+ async function getDiagramNodes ( browser : CompassBrowser ) {
22+ return await browser . execute ( ( ) => {
23+ // eslint-disable-next-line no-restricted-globals
24+ if ( 'diagramInstance' in window ) {
25+ // eslint-disable-next-line no-restricted-globals
26+ const diagramInstance = window . diagramInstance as DiagramInstance ;
27+ const nodes = diagramInstance . getNodes ( ) ;
28+ return nodes . map ( ( node ) => ( {
29+ id : node . id ,
30+ title : node . data . title ,
31+ } ) ) ;
32+ }
33+ throw new Error (
34+ 'Diagram instance not found in the window object. Ensure the diagram is set for tests.'
35+ ) ;
36+ } ) ;
37+ }
38+
1739describe ( 'Data Modeling tab' , function ( ) {
1840 let compass : Compass ;
1941 let browser : CompassBrowser ;
@@ -80,13 +102,12 @@ describe('Data Modeling tab', function () {
80102 const dataModelEditor = browser . $ ( Selectors . DataModelEditor ) ;
81103 await dataModelEditor . waitForDisplayed ( ) ;
82104
83- // Verify that the diagram is displayed and contains both collections
84- const text = await browser . getCodemirrorEditorText (
85- Selectors . DataModelPreview
86- ) ;
87-
88- expect ( text ) . to . include ( '"ns": "test.testCollection1"' ) ;
89- expect ( text ) . to . include ( '"ns": "test.testCollection2"' ) ;
105+ let nodes = await getDiagramNodes ( browser ) ;
106+ expect ( nodes ) . to . have . lengthOf ( 2 ) ;
107+ expect ( nodes . map ( ( x ) => x . title ) ) . to . deep . equal ( [
108+ 'test.testCollection1' ,
109+ 'test.testCollection2' ,
110+ ] ) ;
90111
91112 // Apply change to the model
92113 const newModel = {
@@ -96,40 +117,30 @@ describe('Data Modeling tab', function () {
96117 relationships : [ ] ,
97118 } ,
98119 } ;
99- const newPreview = JSON . stringify ( newModel . model , null , 2 ) ;
100120 await browser . setCodemirrorEditorValue (
101121 Selectors . DataModelApplyEditor ,
102122 JSON . stringify ( newModel )
103123 ) ;
104124 await browser . clickVisible ( Selectors . DataModelEditorApplyButton ) ;
105125
106126 // Verify that the model is updated
107- const updatedText = await browser . getCodemirrorEditorText (
108- Selectors . DataModelPreview
109- ) ;
110- expect ( updatedText ) . to . equal ( newPreview ) ;
127+ nodes = await getDiagramNodes ( browser ) ;
128+ expect ( nodes ) . to . have . lengthOf ( 0 ) ;
111129
112130 // Undo the change
113131 await browser . clickVisible ( Selectors . DataModelUndoButton ) ;
114- await browser . waitUntil ( async ( ) => {
115- const textAfterUndo = await browser . getCodemirrorEditorText (
116- Selectors . DataModelPreview
117- ) ;
118- return (
119- textAfterUndo . includes ( '"ns": "test.testCollection1"' ) &&
120- textAfterUndo . includes ( '"ns": "test.testCollection2"' )
121- ) ;
122- } ) ;
132+ nodes = await getDiagramNodes ( browser ) ;
133+ expect ( nodes ) . to . have . lengthOf ( 2 ) ;
134+ expect ( nodes . map ( ( x ) => x . title ) ) . to . deep . equal ( [
135+ 'test.testCollection1' ,
136+ 'test.testCollection2' ,
137+ ] ) ;
123138
124139 // Redo the change
125140 await browser . waitForAriaDisabled ( Selectors . DataModelRedoButton , false ) ;
126141 await browser . clickVisible ( Selectors . DataModelRedoButton ) ;
127- await browser . waitUntil ( async ( ) => {
128- const redoneText = await browser . getCodemirrorEditorText (
129- Selectors . DataModelPreview
130- ) ;
131- return redoneText === newPreview ;
132- } ) ;
142+ nodes = await getDiagramNodes ( browser ) ;
143+ expect ( nodes ) . to . have . lengthOf ( 0 ) ;
133144
134145 // Open a new tab
135146 await browser . openNewTab ( ) ;
@@ -139,10 +150,8 @@ describe('Data Modeling tab', function () {
139150 await browser . $ ( Selectors . DataModelEditor ) . waitForDisplayed ( ) ;
140151
141152 // Verify that the diagram has the latest changes
142- const savedText = await browser . getCodemirrorEditorText (
143- Selectors . DataModelPreview
144- ) ;
145- expect ( savedText ) . to . equal ( newPreview ) ;
153+ nodes = await getDiagramNodes ( browser ) ;
154+ expect ( nodes ) . to . have . lengthOf ( 0 ) ;
146155
147156 // Open a new tab
148157 await browser . openNewTab ( ) ;
0 commit comments