diff --git a/app/src/components/Map.js b/app/src/components/Map.js index 5dda16ee..3c5ed0d5 100644 --- a/app/src/components/Map.js +++ b/app/src/components/Map.js @@ -411,6 +411,8 @@ function ManageMap() { ; } + const catalogLoaded = Array.isArray(catalog); + /* * A fragment, not a `PageContainer`. `MapRoute` already provides the page chrome -- a * `wrolpi-stack` wrapper with its own top margin -- so a second one put this page a further @@ -433,11 +435,16 @@ function ManageMap() {
Map Subscriptions
- + {/* A pending or failed catalog is not "zero regions": the preview waits for one. The + modal is mounted only then, so it receives the state array itself and its map is + not rebuilt by a fresh `[]` on every status tick. */} +
- setAllRegionsOpen(false)}/> + {catalogLoaded && setAllRegionsOpen(false)}/>} {catalog === undefined ? Could not fetch map subscriptions diff --git a/app/src/components/MapTables.test.js b/app/src/components/MapTables.test.js index a7f4060b..efbf0242 100644 --- a/app/src/components/MapTables.test.js +++ b/app/src/components/MapTables.test.js @@ -120,4 +120,29 @@ describe('the Manage tab subscriptions table', () => { }); expect(screen.getByText(NO_RESULTS)).toBeInTheDocument(); }); + + // The "View All Regions" preview draws the catalog; a pending or failed catalog must not be + // previewed as zero regions. + test('pending: the regions preview is disabled', async () => { + api.fetchMapSubscriptions.mockReturnValue(pending()); + renderAt('/map/manage'); + await act(async () => { + }); + expect(screen.getByRole('button', {name: 'View All Regions'})).toBeDisabled(); + }); + + test('failed: the regions preview is disabled', async () => { + api.fetchMapSubscriptions.mockResolvedValue(undefined); + renderAt('/map/manage'); + await act(async () => { + }); + expect(screen.getByRole('button', {name: 'View All Regions'})).toBeDisabled(); + }); + + test('loaded: the regions preview is enabled', async () => { + renderAt('/map/manage'); + await act(async () => { + }); + expect(screen.getByRole('button', {name: 'View All Regions'})).toBeEnabled(); + }); });