@@ -3,27 +3,45 @@ import { expect } from 'chai';
33import { render , screen , userEvent } from '@mongodb-js/testing-library-compass' ;
44import { DiagramEditorToolbar } from './diagram-editor-toolbar' ;
55import sinon from 'sinon' ;
6+ import {
7+ type WorkspacesService ,
8+ WorkspacesServiceProvider ,
9+ } from '@mongodb-js/compass-workspaces/provider' ;
10+
11+ const workspacesService = {
12+ openDataModelingWorkspace : ( ) => { } ,
13+ } as WorkspacesService ;
614
715function renderDiagramEditorToolbar (
816 props : Partial < React . ComponentProps < typeof DiagramEditorToolbar > > = { }
917) {
1018 render (
11- < DiagramEditorToolbar
12- step = "EDITING"
13- hasUndo = { true }
14- hasRedo = { true }
15- isInRelationshipDrawingMode = { false }
16- onUndoClick = { ( ) => { } }
17- onRedoClick = { ( ) => { } }
18- onExportClick = { ( ) => { } }
19- onRelationshipDrawingToggle = { ( ) => { } }
20- onAddCollectionClick = { ( ) => { } }
21- { ...props }
22- />
19+ < WorkspacesServiceProvider value = { workspacesService } >
20+ < DiagramEditorToolbar
21+ step = "EDITING"
22+ hasUndo = { true }
23+ hasRedo = { true }
24+ isInRelationshipDrawingMode = { false }
25+ onUndoClick = { ( ) => { } }
26+ onRedoClick = { ( ) => { } }
27+ onExportClick = { ( ) => { } }
28+ onRelationshipDrawingToggle = { ( ) => { } }
29+ onAddCollectionClick = { ( ) => { } }
30+ { ...props }
31+ />
32+ </ WorkspacesServiceProvider >
2333 ) ;
2434}
2535
2636describe ( 'DiagramEditorToolbar' , function ( ) {
37+ beforeEach ( function ( ) {
38+ workspacesService . openDataModelingWorkspace = sinon . spy ( ) ;
39+ } ) ;
40+
41+ afterEach ( function ( ) {
42+ sinon . reset ( ) ;
43+ } ) ;
44+
2745 it ( 'renders nothing if step is NO_DIAGRAM_SELECTED' , function ( ) {
2846 renderDiagramEditorToolbar ( { step : 'NO_DIAGRAM_SELECTED' } ) ;
2947 expect ( ( ) => screen . getByTestId ( 'diagram-editor-toolbar' ) ) . to . throw ( ) ;
@@ -34,6 +52,23 @@ describe('DiagramEditorToolbar', function () {
3452 expect ( ( ) => screen . getByTestId ( 'diagram-editor-toolbar' ) ) . to . throw ( ) ;
3553 } ) ;
3654
55+ context ( 'breadcrumbs' , function ( ) {
56+ it ( 'includes "diagrams" breadcrumb' , function ( ) {
57+ renderDiagramEditorToolbar ( ) ;
58+ const diagrams = screen . getByRole ( 'button' , { name : 'diagrams' } ) ;
59+ expect ( diagrams ) . to . be . visible ;
60+ userEvent . click ( diagrams ) ;
61+ expect (
62+ workspacesService . openDataModelingWorkspace
63+ ) . to . have . been . calledOnce ;
64+ } ) ;
65+
66+ it ( 'includes diagram name breadcrumb' , function ( ) {
67+ renderDiagramEditorToolbar ( { diagramName : 'My Diagram' } ) ;
68+ expect ( screen . getByText ( 'My Diagram' ) ) . to . be . visible ;
69+ } ) ;
70+ } ) ;
71+
3772 context ( 'undo button' , function ( ) {
3873 it ( 'renders it disabled if hasUndo is false' , function ( ) {
3974 renderDiagramEditorToolbar ( { hasUndo : false } ) ;
0 commit comments