Skip to content

Commit 65ca87b

Browse files
committed
wait for fitView and update tests
1 parent 206870e commit 65ca87b

File tree

2 files changed

+52
-60
lines changed

2 files changed

+52
-60
lines changed

packages/compass-data-modeling/src/components/diagram-editor.tsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -163,31 +163,6 @@ const DiagramEditor: React.FunctionComponent<{
163163
});
164164
}, [model?.relationships]);
165165

166-
const applyInitialLayout = useCallback(async () => {
167-
try {
168-
const { nodes: positionedNodes } = await applyLayout(
169-
nodes,
170-
edges,
171-
'LEFT_RIGHT'
172-
);
173-
onApplyInitialLayout(
174-
Object.fromEntries(
175-
positionedNodes.map((node) => [
176-
node.id,
177-
[node.position.x, node.position.y],
178-
])
179-
)
180-
);
181-
} catch (err) {
182-
log.error(
183-
mongoLogId(1_001_000_361),
184-
'DiagramEditor',
185-
'Error applying layout:',
186-
err
187-
);
188-
}
189-
}, [edges, log, mongoLogId, onApplyInitialLayout]);
190-
191166
const nodes = useMemo<NodeProps[]>(() => {
192167
return (model?.collections ?? []).map(
193168
(coll): NodeProps => ({
@@ -212,6 +187,31 @@ const DiagramEditor: React.FunctionComponent<{
212187
);
213188
}, [model?.collections]);
214189

190+
const applyInitialLayout = useCallback(async () => {
191+
try {
192+
const { nodes: positionedNodes } = await applyLayout(
193+
nodes,
194+
edges,
195+
'LEFT_RIGHT'
196+
);
197+
onApplyInitialLayout(
198+
Object.fromEntries(
199+
positionedNodes.map((node) => [
200+
node.id,
201+
[node.position.x, node.position.y],
202+
])
203+
)
204+
);
205+
} catch (err) {
206+
log.error(
207+
mongoLogId(1_001_000_361),
208+
'DiagramEditor',
209+
'Error applying layout:',
210+
err
211+
);
212+
}
213+
}, [edges, log, nodes, mongoLogId, onApplyInitialLayout]);
214+
215215
useEffect(() => {
216216
if (nodes.length === 0) return;
217217
const isInitialState = nodes.some(
@@ -222,8 +222,10 @@ const DiagramEditor: React.FunctionComponent<{
222222
return;
223223
}
224224
if (!areNodesReady) {
225-
void diagram.fitView();
226225
setAreNodesReady(true);
226+
setTimeout(() => {
227+
void diagram.fitView();
228+
});
227229
}
228230
}, [areNodesReady, nodes, diagram, applyInitialLayout]);
229231

@@ -280,6 +282,10 @@ const DiagramEditor: React.FunctionComponent<{
280282
minZoom: 0.25,
281283
}}
282284
onNodeDragStop={(evt, node) => {
285+
console.log('Node drag stopped:', node.id, [
286+
node.position.x,
287+
node.position.y,
288+
]);
283289
onMoveCollection(node.id, [node.position.x, node.position.y]);
284290
}}
285291
/>

packages/compass-e2e-tests/tests/data-modeling-tab.test.ts

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -132,78 +132,64 @@ describe('Data Modeling tab', function () {
132132
const dataModelEditor = browser.$(Selectors.DataModelEditor);
133133
await dataModelEditor.waitForDisplayed();
134134

135-
let nodes = await getDiagramNodes(browser);
135+
const nodes = await getDiagramNodes(browser);
136136
expect(nodes).to.have.lengthOf(2);
137137
expect(nodes[0].id).to.equal('test.testCollection1');
138138
expect(nodes[1].id).to.equal('test.testCollection2');
139139

140140
// Apply change to the model
141-
const originalPosition = {
142-
x: Math.round(nodes[0].position.x),
143-
y: Math.round(nodes[0].position.y),
144-
};
145141

146142
// react flow uses its own coordinate system,
147143
// so we get the node element location for the pointer action
148-
const startPosition = await browser
149-
.$(Selectors.DataModelPreviewCollection('test.testCollection1'))
150-
.getLocation();
144+
const testCollection1 = browser.$(
145+
Selectors.DataModelPreviewCollection('test.testCollection1')
146+
);
147+
const startPosition = await testCollection1.getLocation();
148+
const nodeSize = await testCollection1.getSize();
151149

152150
// This should move the node 20px to the right but it just moves it "somewhere else"
153151
// That's the best I could do
154152
await browser
155153
.action('pointer')
156154
.move({
157-
x: Math.round(startPosition.x) + 10,
158-
y: Math.round(startPosition.y) + 10,
155+
x: Math.round(startPosition.x) + nodeSize.width / 2,
156+
y: Math.round(startPosition.y) + nodeSize.height / 2,
159157
})
160158
.down({ button: 0 }) // Left mouse button
161-
.move({ x: 10, y: 0, duration: 100 })
162159
.pause(1000)
163-
.move({ x: 10, y: 0, duration: 100 })
160+
.move({ x: 100, y: 0, duration: 1000, origin: 'pointer' })
161+
.pause(1000)
162+
.move({ x: 100, y: 0, duration: 1000, origin: 'pointer' })
164163
.up({ button: 0 }) // Release the left mouse button
165164
.perform();
166165
await browser.waitForAnimations(dataModelEditor);
167166

168167
// Check that the first node has moved and mark the new position
169-
nodes = await getDiagramNodes(browser);
170-
expect(nodes).to.have.lengthOf(2);
171-
expect(Math.round(nodes[0].position.x)).not.to.equal(originalPosition.x);
172-
expect(Math.round(nodes[0].position.y)).not.to.equal(originalPosition.y);
173-
const newPosition = {
174-
x: Math.round(nodes[0].position.x),
175-
y: Math.round(nodes[0].position.y),
176-
};
168+
const newPosition = await testCollection1.getLocation();
169+
expect(newPosition).not.to.deep.equal(startPosition);
177170

178171
// Undo the change
179172
await browser.clickVisible(Selectors.DataModelUndoButton);
180173
await browser.waitForAnimations(dataModelEditor);
181-
nodes = await getDiagramNodes(browser);
182-
expect(nodes).to.have.lengthOf(2);
183-
expect(Math.round(nodes[0].position.x)).to.equal(originalPosition.x);
184-
expect(Math.round(nodes[0].position.y)).to.equal(originalPosition.y);
174+
const positionAfterUndone = await testCollection1.getLocation();
175+
expect(positionAfterUndone).to.deep.equal(startPosition);
185176

186177
// Redo the change
187178
await browser.waitForAriaDisabled(Selectors.DataModelRedoButton, false);
188179
await browser.clickVisible(Selectors.DataModelRedoButton);
189180
await browser.waitForAnimations(dataModelEditor);
190-
nodes = await getDiagramNodes(browser);
191-
expect(nodes).to.have.lengthOf(2);
192-
expect(Math.round(nodes[0].position.x)).to.equal(newPosition.x);
193-
expect(Math.round(nodes[0].position.y)).to.equal(newPosition.y);
194-
181+
const positionAfterRedo = await testCollection1.getLocation();
182+
expect(positionAfterRedo).to.deep.equal(newPosition);
195183
// Open a new tab
196184
await browser.openNewTab();
197185

198186
// Open the saved diagram
199187
await browser.clickVisible(Selectors.DataModelsListItem(dataModelName));
200188
await browser.$(Selectors.DataModelEditor).waitForDisplayed();
201189

202-
// Verify that the diagram has the latest changes
203-
nodes = await getDiagramNodes(browser);
204-
expect(nodes).to.have.lengthOf(2);
205-
expect(Math.round(nodes[0].position.x)).to.equal(newPosition.x);
206-
expect(Math.round(nodes[0].position.y)).to.equal(newPosition.y);
190+
// TODO: Verify that the diagram has the latest changes COMPASS-9479
191+
const savedNodes = await getDiagramNodes(browser);
192+
expect(savedNodes).to.have.lengthOf(2);
207193

208194
// Open a new tab
209195
await browser.openNewTab();

0 commit comments

Comments
 (0)