Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ export { DrawerDisplayMode };
export function useDrawerActions() {
const actions = useContext(DrawerActionsContext);
const stableActions = useRef({
openDrawer(id: string) {
openDrawer: (id: string) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by to make sure eslint is not warning on unbound methods (those are safe to call unbound, this just makes it clear)

actions.current.openDrawer(id);
},
closeDrawer() {
closeDrawer: () => {
actions.current.closeDrawer();
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
render,
userEvent,
} from '@mongodb-js/testing-library-compass';
import DiagramEditor, { getFieldsFromSchema } from './diagram-editor';
import DiagramEditor from './diagram-editor';
import type { DataModelingStore } from '../../test/setup-store';
import type {
Edit,
Expand All @@ -18,6 +18,7 @@ import sinon from 'sinon';
import { DiagramProvider } from '@mongodb-js/diagramming';
import { DataModelingWorkspaceTab } from '..';
import { openDiagram } from '../store/diagram';
import { getFieldsFromSchema } from '../utils/nodes-and-edges';

const storageItems: MongoDBDataModelDescription[] = [
{
Expand Down Expand Up @@ -68,14 +69,14 @@ const storageItems: MongoDBDataModelDescription[] = [
{
ns: 'db1.collection1',
indexes: [],
displayPosition: [NaN, NaN],
displayPosition: [0, 0],
shardKey: {},
jsonSchema: { bsonType: 'object' },
},
{
ns: 'db1.collection2',
indexes: [],
displayPosition: [NaN, NaN],
displayPosition: [0, 0],
shardKey: {},
jsonSchema: { bsonType: 'object' },
},
Expand Down Expand Up @@ -165,37 +166,6 @@ describe('DiagramEditor', function () {
.callsFake(mockDiagramming.applyLayout as any);
});

context('with initial diagram', function () {
beforeEach(async function () {
const result = renderDiagramEditor({
renderedItem: storageItems[1],
});
store = result.store;

// wait till the editor is loaded
await waitFor(() => {
expect(screen.getByTestId('model-preview')).to.be.visible;
});
});

it('applies the initial layout to unpositioned nodes', function () {
const state = store.getState();

expect(state.diagram?.edits.current).to.have.lengthOf(1);
expect(state.diagram?.edits.current[0].type).to.equal('SetModel');
const initialEdit = state.diagram?.edits.current[0] as Extract<
Edit,
{ type: 'SetModel' }
>;
expect(initialEdit.model?.collections[0].displayPosition).to.deep.equal([
100, 100,
]);
expect(initialEdit.model?.collections[1].displayPosition).to.deep.equal([
200, 200,
]);
});
});

context('with existing diagram', function () {
beforeEach(async function () {
const result = renderDiagramEditor({
Expand Down
Loading
Loading