Skip to content

Commit 94f38d7

Browse files
committed
fix ci and add test
1 parent 29432cf commit 94f38d7

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

configs/testing-library-compass/src/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ type TestConnectionsOptions = {
9393
connectFn?: (
9494
connectionOptions: ConnectionInfo['connectionOptions']
9595
) => Partial<DataService> | Promise<Partial<DataService>>;
96+
/**
97+
* Connection storage mock
98+
*/
99+
connectionStorage?: ConnectionStorage;
96100
} & Partial<
97101
Omit<
98102
React.ComponentProps<typeof CompassConnections>,
@@ -258,9 +262,9 @@ function createWrapper(
258262
preferences: new InMemoryPreferencesAccess(options.preferences),
259263
track: Sinon.stub(),
260264
logger: createNoopLogger(),
261-
connectionStorage: new InMemoryConnectionStorage(
262-
options.connections
263-
) as ConnectionStorage,
265+
connectionStorage:
266+
options.connectionStorage ??
267+
(new InMemoryConnectionStorage(options.connections) as ConnectionStorage),
264268
connectionsStore: {
265269
getState: undefined as unknown as () => State,
266270
actions: {} as ReturnType<typeof useConnectionActions>,

packages/compass-connections/src/stores/connections-store-redux.spec.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
render,
1010
} from '@mongodb-js/testing-library-compass';
1111
import React from 'react';
12+
import { InMemoryConnectionStorage } from '@mongodb-js/connection-storage/provider';
1213

1314
const mockConnections = [
1415
{
@@ -48,6 +49,30 @@ describe('CompassConnections store', function () {
4849
sinon.restore();
4950
});
5051

52+
describe('#loadAll', function () {
53+
it('calls onFailToLoadConnections when it fails to loadAll connections', async function () {
54+
const onFailToLoadConnectionsSpy = sinon.spy();
55+
const connectionStorage = new InMemoryConnectionStorage();
56+
connectionStorage.loadAll = sinon
57+
.stub()
58+
.rejects(new Error('loadAll failed'));
59+
60+
renderCompassConnections({
61+
connectionStorage,
62+
onFailToLoadConnections: onFailToLoadConnectionsSpy,
63+
});
64+
65+
await waitFor(() => {
66+
expect(onFailToLoadConnectionsSpy).to.have.been.calledOnce;
67+
});
68+
69+
expect(onFailToLoadConnectionsSpy.firstCall.firstArg).to.have.property(
70+
'message',
71+
'loadAll failed'
72+
);
73+
});
74+
});
75+
5176
describe('#connect', function () {
5277
it('should show notifications throughout connection flow and save connection to persistent store', async function () {
5378
const { connectionsStore, connectionStorage, track } =

packages/compass-web/src/entrypoint.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe('CompassWeb', function () {
7474
enableCreatingNewConnections: true,
7575
...props.initialPreferences,
7676
}}
77+
onFailToLoadConnections={() => {}}
7778
></CompassWeb>
7879
</ConnectFnProvider>
7980
);

0 commit comments

Comments
 (0)