Skip to content

Commit 51223f7

Browse files
committed
e2e test
1 parent d8dc823 commit 51223f7

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,15 @@ const DiagramEditor: React.FunctionComponent<{
333333
maxZoom: 1,
334334
minZoom: 0.25,
335335
}}
336+
onSelectionChange={({ nodes }) => {
337+
console.log('SELECTION CHANGE', nodes);
338+
}}
339+
onNodeDrag={(evt, node) => {
340+
console.log('NODE DRAG', node);
341+
// onMoveCollection(node.id, [node.position.x, node.position.y]);
342+
}}
336343
onNodeDragStop={(evt, node) => {
344+
console.log('NODE DRAG STOP', node);
337345
onMoveCollection(node.id, [node.position.x, node.position.y]);
338346
}}
339347
onEdgeClick={(evt, edge) => {

packages/compass-e2e-tests/helpers/selectors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,8 @@ export const CreateDataModelCollectionCheckbox = (
14421442
`${CreateDataModelModal} [data-testid="new-diagram-collection-checkbox-${collectionName}"]`;
14431443
export const DataModelEditor = '[data-testid="diagram-editor-container"]';
14441444
export const DataModelPreview = `${DataModelEditor} [data-testid="model-preview"]`;
1445+
export const DataModelPreviewCollection = (collectionId: string) =>
1446+
`${DataModelPreview} [data-nodeid="${collectionId}"]`;
14451447
export const DataModelApplyEditor = `${DataModelEditor} [data-testid="apply-editor"]`;
14461448
export const DataModelEditorApplyButton = `${DataModelApplyEditor} [data-testid="apply-button"]`;
14471449
export const DataModelUndoButton = 'button[aria-label="Undo"]';

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

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
waitForFileDownload,
1818
} from '../helpers/downloads';
1919
import { readFileSync } from 'fs';
20-
import { first } from 'lodash';
2120

2221
interface Node {
2322
id: string;
@@ -122,7 +121,7 @@ describe('Data Modeling tab', function () {
122121
}
123122
});
124123

125-
it.only('creates a new data model using an existing connection', async function () {
124+
it('creates a new data model using an existing connection', async function () {
126125
const dataModelName = 'Test Data Model';
127126
await setupDiagram(browser, {
128127
diagramName: dataModelName,
@@ -143,43 +142,55 @@ describe('Data Modeling tab', function () {
143142
x: Math.round(nodes[0].position.x),
144143
y: Math.round(nodes[0].position.y),
145144
};
146-
console.log('Before applying change to the model');
147-
console.log({ originalPosition });
148-
await browser.actions([
149-
browser
150-
.action('pointer')
151-
.move({
152-
origin: dataModelEditor,
153-
...originalPosition,
154-
})
155-
.down()
156-
.move(100, 0) // Move right by 100 pixels
157-
.up(),
158-
]);
159-
await browser.waitForAnimations(dataModelEditor);
160145

161-
const newPosition = { x: originalPosition.x + 100, y: originalPosition.y };
162-
console.log('After applying change to the model');
146+
// react flow uses its own coordinate system,
147+
// so we get the node element location for the pointer action
148+
const startPosition = await browser
149+
.$(Selectors.DataModelPreviewCollection('test.testCollection1'))
150+
.getLocation();
151+
152+
// This should move the node 20px to the right but it just moves it "somewhere else"
153+
// That's the best I could do
154+
await browser
155+
.action('pointer')
156+
.move({
157+
x: Math.round(startPosition.x) + 10,
158+
y: Math.round(startPosition.y) + 10,
159+
})
160+
.down({ button: 0 }) // Left mouse button
161+
.move({ x: 10, y: 0, duration: 100 })
162+
.pause(1000)
163+
.move({ x: 10, y: 0, duration: 100 })
164+
.up({ button: 0 }) // Release the left mouse button
165+
.perform();
166+
await browser.waitForAnimations(dataModelEditor);
163167

164-
// Verify that the model is updated
168+
// Check that the first node has moved and mark the new position
165169
nodes = await getDiagramNodes(browser);
166170
expect(nodes).to.have.lengthOf(2);
167-
expect(nodes[0].position).to.equal(newPosition);
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+
};
168177

169178
// Undo the change
170179
await browser.clickVisible(Selectors.DataModelUndoButton);
171180
await browser.waitForAnimations(dataModelEditor);
172181
nodes = await getDiagramNodes(browser);
173182
expect(nodes).to.have.lengthOf(2);
174-
expect(nodes[0].position).to.equal(originalPosition);
183+
expect(Math.round(nodes[0].position.x)).to.equal(originalPosition.x);
184+
expect(Math.round(nodes[0].position.y)).to.equal(originalPosition.y);
175185

176186
// Redo the change
177187
await browser.waitForAriaDisabled(Selectors.DataModelRedoButton, false);
178188
await browser.clickVisible(Selectors.DataModelRedoButton);
179189
await browser.waitForAnimations(dataModelEditor);
180190
nodes = await getDiagramNodes(browser);
181191
expect(nodes).to.have.lengthOf(2);
182-
expect(nodes[0].position).to.equal(newPosition);
192+
expect(Math.round(nodes[0].position.x)).to.equal(newPosition.x);
193+
expect(Math.round(nodes[0].position.y)).to.equal(newPosition.y);
183194

184195
// Open a new tab
185196
await browser.openNewTab();
@@ -191,7 +202,8 @@ describe('Data Modeling tab', function () {
191202
// Verify that the diagram has the latest changes
192203
nodes = await getDiagramNodes(browser);
193204
expect(nodes).to.have.lengthOf(2);
194-
expect(nodes[0].position).to.equal(newPosition);
205+
expect(Math.round(nodes[0].position.x)).to.equal(newPosition.x);
206+
expect(Math.round(nodes[0].position.y)).to.equal(newPosition.y);
195207

196208
// Open a new tab
197209
await browser.openNewTab();

0 commit comments

Comments
 (0)