@@ -21,6 +21,8 @@ import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
2121import { createNoopLogger } from '@mongodb-js/compass-logging/provider' ;
2222import { createNoopTrack } from '@mongodb-js/compass-telemetry/provider' ;
2323import type { ConnectionInfoRef } from '@mongodb-js/compass-connections/provider' ;
24+ import { type WorkspacesService } from '@mongodb-js/compass-workspaces/provider' ;
25+ import Sinon from 'sinon' ;
2426
2527const topologyDescription = {
2628 type : 'Unknown' ,
@@ -42,34 +44,49 @@ const fakeDataService = {
4244 } ) ,
4345} as any ;
4446
45- describe ( 'Schema Validation Store' , function ( ) {
46- let store : Store < RootState , RootAction > ;
47- let deactivate : null | ( ( ) => void ) = null ;
47+ const fakeWorkspaces = {
48+ onTabReplace : ( ) => { } ,
49+ onTabClose : ( ) => { } ,
50+ } as unknown as WorkspacesService ;
51+
52+ const getMockedStore = async ( ) => {
4853 const globalAppRegistry = new AppRegistry ( ) ;
4954 const connectionInfoRef = {
5055 current : { } ,
5156 } as ConnectionInfoRef ;
57+ const activateResult = onActivated (
58+ { namespace : 'test.test' } as any ,
59+ {
60+ globalAppRegistry : globalAppRegistry ,
61+ dataService : fakeDataService ,
62+ instance : fakeInstance ,
63+ workspaces : fakeWorkspaces ,
64+ preferences : await createSandboxFromDefaultPreferences ( ) ,
65+ logger : createNoopLogger ( ) ,
66+ track : createNoopTrack ( ) ,
67+ connectionInfoRef,
68+ } ,
69+ createActivateHelpers ( )
70+ ) ;
71+ return activateResult ;
72+ } ;
73+
74+ describe ( 'Schema Validation Store' , function ( ) {
75+ let store : Store < RootState , RootAction > ;
76+ let deactivate : null | ( ( ) => void ) = null ;
77+ let sandbox : Sinon . SinonSandbox ;
5278
5379 beforeEach ( async function ( ) {
54- const activateResult = onActivated (
55- { namespace : 'test.test' } as any ,
56- {
57- globalAppRegistry : globalAppRegistry ,
58- dataService : fakeDataService ,
59- instance : fakeInstance ,
60- preferences : await createSandboxFromDefaultPreferences ( ) ,
61- logger : createNoopLogger ( ) ,
62- track : createNoopTrack ( ) ,
63- connectionInfoRef,
64- } ,
65- createActivateHelpers ( )
66- ) ;
80+ sandbox = Sinon . createSandbox ( ) ;
81+ fakeWorkspaces . onTabClose = sandbox . stub ( ) ;
82+ fakeWorkspaces . onTabReplace = sandbox . stub ( ) ;
83+ const activateResult = await getMockedStore ( ) ;
6784 store = activateResult . store ;
68- // eslint-disable-next-line @typescript-eslint/unbound-method
6985 deactivate = activateResult . deactivate ;
7086 } ) ;
7187
7288 afterEach ( function ( ) {
89+ sandbox . reset ( ) ;
7390 deactivate ?.( ) ;
7491 deactivate = null ;
7592 } ) ;
@@ -128,6 +145,16 @@ describe('Schema Validation Store', function () {
128145 } ) ;
129146 store . dispatch ( validatorChanged ( validator ) ) ;
130147 } ) ;
148+
149+ it ( 'prevents closing the tab' , function ( ) {
150+ store . dispatch ( validatorChanged ( validator ) ) ;
151+ expect ( store . getState ( ) . validation . isChanged ) . to . be . true ;
152+ deactivate ?.( ) ;
153+ const fnProvidedToOnTabClose = (
154+ fakeWorkspaces . onTabClose as Sinon . SinonStub
155+ ) . args [ 0 ] [ 0 ] ;
156+ expect ( fnProvidedToOnTabClose ( ) ) . to . be . false ;
157+ } ) ;
131158 } ) ;
132159
133160 context ( 'when the action is fetch valid sample documents' , function ( ) {
0 commit comments