diff --git a/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx b/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx index 5aee98274fb..10baef42329 100644 --- a/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx +++ b/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx @@ -5,13 +5,14 @@ import { screen, fireEvent, within, + waitFor, } from '@testing-library/react'; import { expect } from 'chai'; import sinon from 'sinon'; import userEvent from '@testing-library/user-event'; import type { Document } from 'mongodb'; -import { SearchIndexesTable } from './search-indexes-table'; +import { POLLING_INTERVAL, SearchIndexesTable } from './search-indexes-table'; import { SearchIndexesStatuses } from '../../modules/search-indexes'; import { searchIndexes as indexes } from './../../../test/fixtures/search-indexes'; @@ -184,4 +185,18 @@ describe('SearchIndexesTable Component', function () { expect(onEditIndexSpy.callCount).to.equal(1); }); }); + + describe('connectivity', function () { + it('does poll the index for changes in online mode', async function () { + const onPollIndexesSpy = sinon.spy(); + renderIndexList({ onPollIndexes: onPollIndexesSpy, isWritable: true }); + + await waitFor( + () => { + expect(onPollIndexesSpy.callCount).to.be.greaterThanOrEqual(1); + }, + { timeout: POLLING_INTERVAL * 2 } + ); + }); + }); }); diff --git a/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.tsx b/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.tsx index 28dca9effc9..abbe2beaea7 100644 --- a/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.tsx +++ b/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.tsx @@ -31,7 +31,7 @@ import { IndexesTable } from '../indexes-table'; import IndexActions from './search-index-actions'; import { ZeroGraphic } from './zero-graphic'; -const POLLING_INTERVAL = 5000; +export const POLLING_INTERVAL = 5000; type SearchIndexesTableProps = { indexes: SearchIndex[]; diff --git a/packages/compass-indexes/src/modules/search-indexes.spec.ts b/packages/compass-indexes/src/modules/search-indexes.spec.ts index f343337356f..9bcf3941554 100644 --- a/packages/compass-indexes/src/modules/search-indexes.spec.ts +++ b/packages/compass-indexes/src/modules/search-indexes.spec.ts @@ -20,6 +20,7 @@ import { readonlyViewChanged } from './is-readonly-view'; // Importing this to stub showConfirmation import * as searchIndexesSlice from './search-indexes'; +import { writeStateChanged } from './is-writable'; describe('search-indexes module', function () { let store: ReturnType; @@ -68,6 +69,18 @@ describe('search-indexes module', function () { expect(store.getState().searchIndexes.status).to.equal('NOT_READY'); }); + it('does nothing if isWritable is false (offline mode)', function () { + store.dispatch(writeStateChanged(false)); + + expect(store.getState().isWritable).to.equal(false); + expect(getSearchIndexesStub.callCount).to.equal(0); + + store.dispatch(fetchSearchIndexes); + + expect(getSearchIndexesStub.callCount).to.equal(0); + expect(store.getState().searchIndexes.status).to.equal('NOT_READY'); + }); + it('does nothing if there is no dataService', function () { store.getState().dataService = null; store.dispatch(fetchSearchIndexes); diff --git a/packages/compass-indexes/src/modules/search-indexes.ts b/packages/compass-indexes/src/modules/search-indexes.ts index 96d0ae85ef9..9a0c378f043 100644 --- a/packages/compass-indexes/src/modules/search-indexes.ts +++ b/packages/compass-indexes/src/modules/search-indexes.ts @@ -518,12 +518,13 @@ const fetchIndexes = ( return async (dispatch, getState) => { const { isReadonlyView, + isWritable, dataService, namespace, searchIndexes: { sortColumn, sortOrder, status }, } = getState(); - if (isReadonlyView) { + if (isReadonlyView || !isWritable) { return; }