Skip to content

Commit 856f210

Browse files
committed
sidebar tests
1 parent 79aef5d commit 856f210

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

packages/compass-sidebar/src/modules/databases.spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import { expect } from 'chai';
2+
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
23

34
import databasesReducer, { INITIAL_STATE, changeDatabases } from './databases';
45

56
import { createInstance } from '../../test/helpers';
67

78
const CONNECTION_ID = 'webscale';
89

9-
function createDatabases(dbs: any[] = []) {
10-
const data = createInstance(dbs).databases.map((db) => {
11-
return {
12-
...db.toJSON(),
13-
collections: db.collections.toJSON(),
14-
};
15-
});
10+
async function createDatabases(dbs: any[] = []) {
11+
const preferences = await createSandboxFromDefaultPreferences();
12+
const data = createInstance(dbs, undefined, preferences).databases.map(
13+
(db) => {
14+
return {
15+
...db.toJSON(),
16+
collections: db.collections.toJSON(),
17+
};
18+
}
19+
);
1620
return data.map(({ is_non_existent, collections, ...rest }) => ({
1721
...rest,
1822
isNonExistent: is_non_existent,
@@ -26,8 +30,8 @@ function createDatabases(dbs: any[] = []) {
2630
describe('sidebar databases', function () {
2731
describe('#reducer', function () {
2832
context('when changing databases', function () {
29-
it('sets databases as-is', function () {
30-
const dbs = createDatabases([{ _id: 'foo' }, { _id: 'bar' }]);
33+
it('sets databases as-is', async function () {
34+
const dbs = await createDatabases([{ _id: 'foo' }, { _id: 'bar' }]);
3135

3236
expect(
3337
databasesReducer(undefined, changeDatabases(CONNECTION_ID, dbs))

packages/compass-sidebar/src/modules/instance.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ import { setupInstance } from './instance';
66
import type { RootState } from '.';
77
import type AppRegistry from 'hadron-app-registry';
88
import type { Logger } from '@mongodb-js/compass-logging';
9-
import type { MongoDBInstancesManager } from '@mongodb-js/compass-app-stores/provider';
9+
import type {
10+
MongoDBInstance,
11+
MongoDBInstancesManager,
12+
} from '@mongodb-js/compass-app-stores/provider';
13+
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
1014

1115
describe('sidebar instance', function () {
12-
const instance = createInstance();
1316
let instanceOnSpy: SinonSpy;
17+
let instance: MongoDBInstance;
1418
const globalAppRegistry = {} as any as AppRegistry;
1519
const connectionsService = {
1620
getDataServiceForConnection() {
@@ -31,7 +35,9 @@ describe('sidebar instance', function () {
3135
let logger: Logger;
3236
let listMongoDBInstancesStub: SinonStub;
3337

34-
beforeEach(function () {
38+
beforeEach(async function () {
39+
const preferences = await createSandboxFromDefaultPreferences();
40+
instance = createInstance(undefined, undefined, preferences);
3541
instanceOnSpy = spy();
3642
instance.on = instanceOnSpy;
3743
instancesManager = {

packages/compass-sidebar/src/stores/store.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { createInstance } from '../../test/helpers';
66
import { createNoopLogger } from '@mongodb-js/compass-logging/provider';
77
import type { DataService } from '@mongodb-js/compass-connections/provider';
88
import {
9+
type MongoDBInstance,
910
MongoDBInstancesManagerEvents,
1011
type MongoDBInstancesManager,
1112
} from '@mongodb-js/compass-app-stores/provider';
13+
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
1214

1315
const CONNECTION_ID = 'webscale';
1416
const ALL_EVENTS = [
@@ -31,7 +33,7 @@ const ALL_EVENTS = [
3133
];
3234

3335
describe('SidebarStore [Store]', function () {
34-
const instance = createInstance();
36+
let instance: MongoDBInstance;
3537
const globalAppRegistry = {} as any;
3638
let instanceOnSpy: SinonSpy;
3739
let instanceOffSpy: SinonSpy;
@@ -40,7 +42,9 @@ describe('SidebarStore [Store]', function () {
4042
let listMongoDBInstancesStub: SinonStub;
4143
let instancesManager: MongoDBInstancesManager;
4244

43-
beforeEach(function () {
45+
beforeEach(async function () {
46+
const preferences = await createSandboxFromDefaultPreferences();
47+
instance = createInstance(undefined, undefined, preferences);
4448
instanceOnSpy = spy();
4549
instanceOffSpy = spy();
4650
instance.on = instanceOnSpy;
@@ -89,11 +93,12 @@ describe('SidebarStore [Store]', function () {
8993
}
9094

9195
describe('when a new instance is created', function () {
92-
beforeEach(function () {
96+
beforeEach(async function () {
97+
const preferences = await createSandboxFromDefaultPreferences();
9398
instancesManager.emit(
9499
MongoDBInstancesManagerEvents.InstanceCreated,
95100
'newConnection',
96-
createInstance()
101+
createInstance(undefined, undefined, preferences)
97102
);
98103
});
99104

packages/compass-sidebar/test/helpers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { type PreferencesAccess } from 'compass-preferences-model';
12
import { MongoDBInstance } from 'mongodb-instance-model';
23

34
export function createInstance(
@@ -9,7 +10,8 @@ export function createInstance(
910
type: 'Unknown',
1011
servers: [],
1112
setName: 'foo',
12-
}
13+
},
14+
preferences: PreferencesAccess
1315
) {
1416
return new MongoDBInstance({
1517
_id: '123',
@@ -26,5 +28,6 @@ export function createInstance(
2628
};
2729
}),
2830
topologyDescription,
31+
preferences,
2932
} as any);
3033
}

0 commit comments

Comments
 (0)