Skip to content

Commit 5203939

Browse files
committed
add test and dependency
1 parent af90728 commit 5203939

File tree

4 files changed

+48
-18
lines changed

4 files changed

+48
-18
lines changed

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-schema-validation/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"@mongodb-js/compass-field-store": "^9.25.2",
7979
"@mongodb-js/compass-logging": "^1.6.2",
8080
"@mongodb-js/compass-telemetry": "^1.4.2",
81+
"@mongodb-js/compass-workspaces": "^0.31.2",
8182
"bson": "^6.10.1",
8283
"compass-preferences-model": "^2.33.2",
8384
"hadron-app-registry": "^9.4.2",

packages/compass-schema-validation/src/stores/store.spec.ts

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
2121
import { createNoopLogger } from '@mongodb-js/compass-logging/provider';
2222
import { createNoopTrack } from '@mongodb-js/compass-telemetry/provider';
2323
import type { ConnectionInfoRef } from '@mongodb-js/compass-connections/provider';
24+
import { type WorkspacesService } from '@mongodb-js/compass-workspaces/provider';
25+
import Sinon from 'sinon';
2426

2527
const 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 () {

packages/compass-schema-validation/src/stores/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { type WorkspacesService } from '@mongodb-js/compass-workspaces/provider'
2323
*/
2424
const MIN_VERSION = '3.2.0';
2525

26-
type SchemaValidationServices = {
26+
export type SchemaValidationServices = {
2727
globalAppRegistry: AppRegistry;
2828
dataService: Pick<
2929
DataService,

0 commit comments

Comments
 (0)