Skip to content

Commit 4f8ec68

Browse files
add unit test
1 parent a5d5cce commit 4f8ec68

File tree

1 file changed

+59
-21
lines changed

1 file changed

+59
-21
lines changed

packages/compass-sidebar/src/components/multiple-connections/sidebar.spec.tsx

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { WorkspacesService } from '@mongodb-js/compass-workspaces/provider'
1717
import { WorkspacesServiceProvider } from '@mongodb-js/compass-workspaces/provider';
1818
import { TestMongoDBInstanceManager } from '@mongodb-js/compass-app-stores/provider';
1919
import { ConnectionImportExportProvider } from '@mongodb-js/compass-connection-import-export';
20-
import { CompassSidebarPlugin } from '../../index';
20+
import { AtlasClusterConnectionsOnly, CompassSidebarPlugin } from '../../index';
2121
import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider';
2222
import type AppRegistry from '../../../../hadron-app-registry/dist';
2323

@@ -91,14 +91,16 @@ describe('Multiple Connections Sidebar Component', function () {
9191

9292
function doRender(
9393
activeWorkspace: WorkspaceTab | null = null,
94-
connections: ConnectionInfo[] = [savedFavoriteConnection]
94+
connections: ConnectionInfo[] = [savedFavoriteConnection],
95+
atlasClusterConnectionsOnly: boolean | undefined = undefined
9596
) {
9697
workspace = sinon.spy({
9798
openMyQueriesWorkspace: () => undefined,
9899
openShellWorkspace: () => undefined,
99100
openPerformanceWorkspace: () => undefined,
100101
}) as any;
101-
const result = renderWithConnections(
102+
103+
let component = (
102104
<ConnectionImportExportProvider>
103105
<WorkspacesProvider
104106
value={[
@@ -112,25 +114,36 @@ describe('Multiple Connections Sidebar Component', function () {
112114
></MultipleConnectionSidebar>
113115
</WorkspacesServiceProvider>
114116
</WorkspacesProvider>
115-
</ConnectionImportExportProvider>,
116-
{
117-
preferences: { enableMultipleConnectionSystem: true },
118-
connections,
119-
connectFn() {
120-
return {
121-
currentOp() {
122-
return {};
123-
},
124-
top() {
125-
return {};
126-
},
127-
getConnectionOptions() {
128-
return {};
129-
},
130-
} as any;
131-
},
132-
}
117+
</ConnectionImportExportProvider>
133118
);
119+
120+
if (atlasClusterConnectionsOnly !== undefined) {
121+
component = (
122+
<AtlasClusterConnectionsOnly.Provider
123+
value={atlasClusterConnectionsOnly}
124+
>
125+
{component}
126+
</AtlasClusterConnectionsOnly.Provider>
127+
);
128+
}
129+
130+
const result = renderWithConnections(component, {
131+
preferences: { enableMultipleConnectionSystem: true },
132+
connections,
133+
connectFn() {
134+
return {
135+
currentOp() {
136+
return {};
137+
},
138+
top() {
139+
return {};
140+
},
141+
getConnectionOptions() {
142+
return {};
143+
},
144+
} as any;
145+
},
146+
});
134147
track = result.track;
135148
appRegistry = sinon.spy(result.globalAppRegistry);
136149
connectionsStoreActions = sinon.spy(result.connectionsStore.actions);
@@ -188,6 +201,31 @@ describe('Multiple Connections Sidebar Component', function () {
188201
});
189202
});
190203

204+
describe("'Connections ' header", function () {
205+
context('by default', () => {
206+
it("shows 'Connections' in header and search bar", () => {
207+
doRender(undefined, []);
208+
expect(screen.getByTestId('connections-header').textContent).to.be(
209+
'Connections'
210+
);
211+
expect(
212+
screen.getByTestId('sidebar-filter-input').textContent
213+
).to.be.equal('Search connections');
214+
});
215+
});
216+
context('when is atlas clusters only', () => {
217+
it("shows 'Clusters' in header and search bar", () => {
218+
doRender(undefined, [], true);
219+
expect(screen.getByTestId('connections-header').textContent).to.be(
220+
'Clusters'
221+
);
222+
expect(
223+
screen.getByTestId('sidebar-filter-input').textContent
224+
).to.be.equal('Search clusters');
225+
});
226+
});
227+
});
228+
191229
describe('connections list', function () {
192230
context('when there are no connections', function () {
193231
it('should display an empty state with a CTA to add new connection', function () {

0 commit comments

Comments
 (0)