Skip to content

Commit b9be029

Browse files
add tests to indexes.spec.tsx
1 parent 481bbd4 commit b9be029

File tree

3 files changed

+84
-50
lines changed

3 files changed

+84
-50
lines changed

packages/compass-indexes/src/components/indexes/indexes.spec.tsx

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,8 @@ const renderIndexes = async (
4545

4646
if (props) {
4747
const state = store.getState();
48-
49-
const allProps: Partial<RootState> = {
50-
indexView: props.indexView ?? 'regular-indexes',
51-
regularIndexes: {
52-
...state.regularIndexes,
53-
...props.regularIndexes,
54-
},
55-
searchIndexes: {
56-
...state.searchIndexes,
57-
...props.searchIndexes,
58-
},
59-
};
60-
61-
Object.assign(store.getState(), allProps);
48+
const newState = { ...state, ...props };
49+
Object.assign(store.getState(), newState);
6250
}
6351

6452
render(
@@ -332,5 +320,69 @@ describe('Indexes Component', function () {
332320

333321
expect(getSearchIndexesStub.callCount).to.equal(2);
334322
});
323+
324+
it('renders search indexes list if isReadonlyView >8.0 and has indexes', async function () {
325+
const getSearchIndexesStub = sinon.stub().resolves(searchIndexes);
326+
const dataProvider = {
327+
getSearchIndexes: getSearchIndexesStub,
328+
};
329+
await renderIndexes(undefined, dataProvider, {
330+
indexView: 'search-indexes',
331+
isReadonlyView: true,
332+
serverVersion: '8.1.0',
333+
});
334+
335+
await waitFor(() => {
336+
expect(screen.getByTestId('search-indexes-list')).to.exist;
337+
});
338+
});
339+
340+
it('renders correct empty state if isReadonlyView >8.0 and has no indexes', async function () {
341+
const getSearchIndexesStub = sinon.stub().resolves([]);
342+
const dataProvider = {
343+
getSearchIndexes: getSearchIndexesStub,
344+
};
345+
await renderIndexes(undefined, dataProvider, {
346+
indexView: 'search-indexes',
347+
isReadonlyView: true,
348+
serverVersion: '8.1.0',
349+
});
350+
351+
expect(screen.getByText('No search indexes yet')).to.be.visible;
352+
expect(screen.getByText('Create Atlas Search Index')).to.be.visible;
353+
});
354+
355+
it('renders correct empty state if isReadonlyView 8.0 and has no indexes', async function () {
356+
const getSearchIndexesStub = sinon.stub().resolves([]);
357+
const dataProvider = {
358+
getSearchIndexes: getSearchIndexesStub,
359+
};
360+
await renderIndexes(undefined, dataProvider, {
361+
indexView: 'search-indexes',
362+
isReadonlyView: true,
363+
serverVersion: '8.0.0',
364+
});
365+
366+
expect(screen.queryByTestId('upgrade-cluster-banner-8.0')).to.exist;
367+
expect(screen.queryByText('No standard indexes')).to.exist;
368+
expect(screen.queryByText('Create Atlas Search Index')).to.not.exist;
369+
});
370+
it('renders correct empty state if isReadonlyView <8.0 and has no indexes', async function () {
371+
const getSearchIndexesStub = sinon.stub().resolves([]);
372+
const dataProvider = {
373+
getSearchIndexes: getSearchIndexesStub,
374+
};
375+
await renderIndexes(undefined, dataProvider, {
376+
indexView: 'search-indexes',
377+
isReadonlyView: true,
378+
serverVersion: '7.0.0',
379+
});
380+
381+
expect(
382+
screen.queryByTestId('upgrade-cluster-banner-less-than-8.0')
383+
).to.exist;
384+
expect(screen.queryByText('No standard indexes')).to.exist;
385+
expect(screen.queryByText('Create Atlas Search Index')).to.not.exist;
386+
});
335387
});
336388
});

packages/compass-indexes/src/components/indexes/indexes.tsx

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
spacing,
99
usePersistedState,
1010
EmptyContent,
11+
Body,
1112
} from '@mongodb-js/compass-components';
1213

1314
import IndexesToolbar from '../indexes-toolbar/indexes-toolbar';
@@ -31,7 +32,6 @@ import { getAtlasSearchIndexesLink } from '../../utils/atlas-search-indexes-link
3132
import CreateIndexModal from '../create-index-modal/create-index-modal';
3233
import { ZeroGraphic } from '../search-indexes-table/zero-graphic';
3334
import { ViewVersionIncompatibleBanner } from '../view-version-incompatible-banners/view-version-incompatible-banners';
34-
import type { AtlasClusterMetadata } from '@mongodb-js/connection-info';
3535

3636
// This constant is used as a trigger to show an insight whenever number of
3737
// indexes in a collection is more than what is specified here.
@@ -58,13 +58,7 @@ const ViewVersionIncompatibleEmptyState = ({
5858
mongoDBMajorVersion: number;
5959
enableAtlasSearchIndexes: boolean;
6060
}) => {
61-
const viewIsSearchCompatible = true; // view only contains $addFields, $set or $match stages with the $expr operator.
62-
63-
if (
64-
mongoDBMajorVersion >= 8.1 &&
65-
enableAtlasSearchIndexes &&
66-
viewIsSearchCompatible
67-
) {
61+
if (mongoDBMajorVersion > 8.0 && enableAtlasSearchIndexes) {
6862
return null;
6963
}
7064
return (
@@ -89,32 +83,21 @@ const AtlasIndexesBanner = ({
8983
namespace,
9084
dismissed,
9185
onDismissClick,
92-
atlasMetadata,
93-
isReadonlyView,
94-
mongoDBMajorVersion,
9586
}: {
9687
namespace: string;
9788
dismissed: boolean;
9889
onDismissClick: () => void;
99-
atlasMetadata: AtlasClusterMetadata | undefined;
100-
isReadonlyView?: boolean;
101-
mongoDBMajorVersion: number;
10290
}) => {
103-
const viewIsSearchCompatible = true; // view only contains $addFields, $set or $match stages with the $expr operator.
104-
if (dismissed || (mongoDBMajorVersion > 8.0 && viewIsSearchCompatible)) {
91+
const { atlasMetadata } = useConnectionInfo();
92+
93+
if (!atlasMetadata || dismissed) {
10594
return null;
10695
}
107-
const bannerVariant =
108-
isReadonlyView && !viewIsSearchCompatible ? 'warning' : 'info';
109-
const bannerText =
110-
isReadonlyView && !viewIsSearchCompatible
111-
? 'This view is incompatible with search indexes. To use search indexes, edit the view to only contain $addFields, $set or $match stages with the $expr operator. You can view all search indexes under '
112-
: 'These indexes can be created and viewed under ';
96+
11397
return (
114-
<Banner variant={bannerVariant} dismissible onClose={onDismissClick}>
115-
<b>Looking for search indexes?</b>
116-
<br />
117-
{bannerText}
98+
<Banner variant="info" dismissible onClose={onDismissClick}>
99+
<Body weight="medium">Looking for search indexes?</Body>
100+
These indexes can be created and viewed under{' '}
118101
{atlasMetadata ? (
119102
<Link
120103
href={getAtlasSearchIndexesLink({
@@ -218,7 +201,6 @@ export function Indexes({
218201
<div className={indexesContainersStyles}>
219202
{isReadonlyView && (
220203
<ViewVersionIncompatibleBanner
221-
namespace={namespace}
222204
serverVersion={serverVersion}
223205
mongoDBMajorVersion={mongoDBMajorVersion}
224206
enableAtlasSearchIndexes={enableAtlasSearchIndexes}
@@ -233,9 +215,6 @@ export function Indexes({
233215
onDismissClick={() => {
234216
setDismissed(true);
235217
}}
236-
atlasMetadata={atlasMetadata}
237-
isReadonlyView={isReadonlyView}
238-
mongoDBMajorVersion={mongoDBMajorVersion}
239218
/>
240219
))}
241220
{!isReadonlyView && currentIndexesView === 'regular-indexes' && (

packages/compass-indexes/src/components/view-version-incompatible-banners/view-version-incompatible-banners.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
css,
66
} from '@mongodb-js/compass-components';
77
import { getAtlasUpgradeClusterLink } from '../../utils/atlas-upgrade-cluster-link';
8-
import { getAtlasSearchIndexesLink } from '../../utils/atlas-search-indexes-link';
98
import React from 'react';
109
import type { AtlasClusterMetadata } from '@mongodb-js/connection-info';
1110

@@ -17,13 +16,11 @@ const viewContentStyles = css({
1716
});
1817

1918
export const ViewVersionIncompatibleBanner = ({
20-
namespace,
2119
serverVersion,
2220
mongoDBMajorVersion,
2321
enableAtlasSearchIndexes,
2422
atlasMetadata,
2523
}: {
26-
namespace: string;
2724
serverVersion: string;
2825
mongoDBMajorVersion: number;
2926
enableAtlasSearchIndexes: boolean;
@@ -35,14 +32,17 @@ export const ViewVersionIncompatibleBanner = ({
3532
mongoDBMajorVersion > 8.0 ||
3633
(mongoDBMajorVersion === 8.0 && !enableAtlasSearchIndexes)
3734
) {
38-
// return if 8.1+ or 8.0+ for data explorer
35+
// return if 8.1+ on compass or 8.0+ for data explorer
3936
return null;
4037
}
4138

4239
if (mongoDBMajorVersion < 8.0) {
4340
// data explorer <8.0 and compass <8.0
4441
return (
45-
<Banner variant={BannerVariant.Warning}>
42+
<Banner
43+
variant={BannerVariant.Warning}
44+
data-testid="upgrade-cluster-banner-less-than-8.0"
45+
>
4646
<b>Looking for search indexes?</b>
4747
<br />
4848
<div className={viewContentStyles}>
@@ -75,7 +75,10 @@ export const ViewVersionIncompatibleBanner = ({
7575
if (mongoDBMajorVersion === 8.0 && enableAtlasSearchIndexes) {
7676
// compass 8.0
7777
return (
78-
<Banner variant={BannerVariant.Warning}>
78+
<Banner
79+
variant={BannerVariant.Warning}
80+
data-testid="upgrade-cluster-banner-8.0"
81+
>
7982
<b>Looking for search indexes?</b>
8083
<br />
8184
<div className={viewContentStyles}>

0 commit comments

Comments
 (0)