Skip to content

Commit 481bbd4

Browse files
update indexes-toolbar test
1 parent cdbbfc8 commit 481bbd4

File tree

3 files changed

+69
-16
lines changed

3 files changed

+69
-16
lines changed

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

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,49 @@ describe('IndexesToolbar Component', function () {
113113
});
114114
});
115115
});
116-
117-
it('should not render a warning', function () {
118-
expect(screen.queryByText('Readonly views may not contain indexes')).to
119-
.not.exist;
120-
});
121116
});
122117

123118
describe('when it is a readonly view', function () {
124-
beforeEach(function () {
125-
renderIndexesToolbar({
126-
isReadonlyView: true,
119+
describe('and server version is < 8.1+', function () {
120+
beforeEach(function () {
121+
renderIndexesToolbar({
122+
isReadonlyView: true,
123+
indexView: 'search-indexes',
124+
});
127125
});
128-
});
129126

130-
it('should not render the create index button', function () {
131-
expect(screen.queryByText('Create Index')).to.not.exist;
127+
it('should not render the create index button', function () {
128+
expect(screen.queryByText('Create Index')).to.not.exist;
129+
});
130+
131+
it('should not render the create search index button', function () {
132+
expect(screen.queryByText('Create Search Index')).to.not.exist;
133+
});
134+
135+
it('should not render the refresh button', function () {
136+
expect(screen.queryByText('Refresh')).to.not.exist;
137+
});
132138
});
139+
describe('and server version is > 8.1+', function () {
140+
beforeEach(function () {
141+
renderIndexesToolbar({
142+
isReadonlyView: true,
143+
serverVersion: '8.1.0',
144+
indexView: 'search-indexes',
145+
});
146+
});
147+
148+
it('should not render the create index button', function () {
149+
expect(screen.queryByText('Create Index')).to.not.exist;
150+
});
133151

134-
it('should render a warning', function () {
135-
expect(screen.getByText('Readonly views may not contain indexes.')).to.be
136-
.visible;
152+
it('should render the create search index button <8.1', function () {
153+
expect(screen.getByText('Create Search Index')).to.be.visible;
154+
});
155+
156+
it('should not render the refresh button', function () {
157+
expect(screen.queryByText('Refresh')).to.be.visible;
158+
});
137159
});
138160
});
139161

@@ -332,5 +354,27 @@ describe('IndexesToolbar Component', function () {
332354
expect(segmentControl.closest('button')).to.have.attr('disabled');
333355
expect(onChangeViewCallback).to.not.have.been.calledOnce;
334356
});
357+
358+
describe('and readonly view >8.1', function () {
359+
beforeEach(function () {
360+
renderIndexesToolbar({
361+
isReadonlyView: true,
362+
onIndexViewChanged: onChangeViewCallback,
363+
serverVersion: '8.1.0',
364+
});
365+
});
366+
367+
it('it renders tabs with Indexes disabled and automatically selects Search Indexes', function () {
368+
const indexesTab = screen.getByText('Indexes');
369+
expect(indexesTab).to.be.visible;
370+
expect(indexesTab.closest('button')).to.have.attr('disabled');
371+
372+
expect(screen.getByText('Search Indexes')).to.be.visible;
373+
expect(onChangeViewCallback).to.have.been.calledOnce;
374+
expect(onChangeViewCallback.firstCall.args[0]).to.equal(
375+
'search-indexes'
376+
);
377+
});
378+
});
335379
});
336380
});

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Button,
99
css,
1010
DropdownMenuButton,
11+
ErrorSummary,
1112
Icon,
1213
Link,
1314
PerformanceSignals,
@@ -102,6 +103,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
102103
onRefreshIndexes,
103104
onIndexViewChanged,
104105
serverVersion,
106+
readOnly, // preferences readOnly.
105107
}) => {
106108
const isSearchManagementActive = usePreference('enableAtlasSearchIndexes');
107109
const mongoDBMajorVersion = parseFloat(
@@ -110,7 +112,9 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
110112
const { atlasMetadata } = useConnectionInfo();
111113
const showInsights = usePreference('showInsights') && !errorMessage;
112114
const showCreateIndexButton =
113-
(!isReadonlyView || mongoDBMajorVersion > 8.0) && !errorMessage;
115+
(!isReadonlyView || mongoDBMajorVersion > 8.0) &&
116+
!readOnly &&
117+
!errorMessage;
114118
const refreshButtonIcon = isRefreshing ? (
115119
<div className={spinnerStyles}>
116120
<SpinLoader title="Refreshing Indexes" />
@@ -272,6 +276,9 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
272276
</div>
273277
</div>
274278
)}
279+
{!!errorMessage && (
280+
<ErrorSummary data-testid="indexes-error" errors={[errorMessage]} />
281+
)}
275282
</div>
276283
);
277284
};

packages/compass-indexes/src/stores/store.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ export function activateIndexesPlugin(
156156
});
157157

158158
void store.dispatch(fetchRegularIndexes());
159-
void store.dispatch(fetchSearchIndexes());
159+
if (options.isSearchIndexesSupported || options.isReadonly) {
160+
void store.dispatch(fetchSearchIndexes());
161+
}
160162

161163
on(collectionModel, 'change:status', (model: Collection, status: string) => {
162164
if (status === 'ready') {

0 commit comments

Comments
 (0)