Skip to content

Commit da5d4f0

Browse files
committed
test
1 parent 1dc2da4 commit da5d4f0

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ function renderDiagramEditorToolbar(
1212
step="EDITING"
1313
hasUndo={true}
1414
hasRedo={true}
15+
isInRelationshipDrawingMode={false}
1516
onUndoClick={() => {}}
1617
onRedoClick={() => {}}
1718
onExportClick={() => {}}
19+
onRelationshipDrawingToggle={() => {}}
1820
{...props}
1921
/>
2022
);
@@ -63,6 +65,36 @@ describe('DiagramEditorToolbar', function () {
6365
});
6466
});
6567

68+
context('add relationship button', function () {
69+
it('renders it active if isInRelationshipDrawingMode is true', function () {
70+
renderDiagramEditorToolbar({ isInRelationshipDrawingMode: true });
71+
const addButton = screen.getByRole('button', {
72+
name: 'Add Relationship',
73+
});
74+
expect(addButton).to.have.attribute('aria-pressed', 'true');
75+
});
76+
77+
it('does not render it active if isInRelationshipDrawingMode is false', function () {
78+
renderDiagramEditorToolbar({ isInRelationshipDrawingMode: false });
79+
const addButton = screen.getByRole('button', {
80+
name: 'Add Relationship',
81+
});
82+
expect(addButton).to.have.attribute('aria-pressed', 'false');
83+
});
84+
85+
it('clicking on it calls onRelationshipDrawingToggle', function () {
86+
const relationshipDrawingToggleSpy = sinon.spy();
87+
renderDiagramEditorToolbar({
88+
onRelationshipDrawingToggle: relationshipDrawingToggleSpy,
89+
});
90+
const addRelationshipButton = screen.getByRole('button', {
91+
name: 'Add Relationship',
92+
});
93+
userEvent.click(addRelationshipButton);
94+
expect(relationshipDrawingToggleSpy).to.have.been.calledOnce;
95+
});
96+
});
97+
6698
it('renders export button and calls onExportClick', function () {
6799
const exportSpy = sinon.spy();
68100
renderDiagramEditorToolbar({ onExportClick: exportSpy });

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@ export const DiagramEditorToolbar: React.FunctionComponent<{
4949
onRedoClick: () => void;
5050
onExportClick: () => void;
5151
onRelationshipDrawingToggle: () => void;
52-
}> = ({ step, hasUndo, onUndoClick, hasRedo, onRedoClick, onExportClick, onRelationshipDrawingToggle, isInRelationshipDrawingMode }) => {
52+
}> = ({
53+
step,
54+
hasUndo,
55+
onUndoClick,
56+
hasRedo,
57+
onRedoClick,
58+
onExportClick,
59+
onRelationshipDrawingToggle,
60+
isInRelationshipDrawingMode,
61+
}) => {
5362
const darkmode = useDarkMode();
5463
if (step !== 'EDITING') {
5564
return null;
@@ -64,6 +73,7 @@ export const DiagramEditorToolbar: React.FunctionComponent<{
6473
aria-label="Add Relationship"
6574
onClick={onRelationshipDrawingToggle}
6675
active={isInRelationshipDrawingMode}
76+
aria-pressed={isInRelationshipDrawingMode}
6777
>
6878
<Icon glyph="Relationship"></Icon>
6979
</IconButton>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ const DiagramEditor: React.FunctionComponent<{
232232
onRelationshipSelect: (rId: string) => void;
233233
onDiagramBackgroundClicked: () => void;
234234
selectedItems: SelectedItems;
235-
onNodesConnected: (source: string, target: string) => void;
236235
onRelationshipDrawn: (source: string, target: string) => void;
237236
}> = ({
238237
diagramLabel,
@@ -312,7 +311,12 @@ const DiagramEditor: React.FunctionComponent<{
312311
draggable: !isInRelationshipDrawingMode,
313312
})
314313
);
315-
}, [model?.collections, model?.relationships, selectedItems, isInRelationshipDrawingMode]);
314+
}, [
315+
model?.collections,
316+
model?.relationships,
317+
selectedItems,
318+
isInRelationshipDrawingMode,
319+
]);
316320

317321
const handleNodesConnect = useCallback(
318322
(source: string, target: string) => {

0 commit comments

Comments
 (0)