Skip to content

Commit 4050da7

Browse files
committed
Handle undefined
1 parent 031c2a3 commit 4050da7

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

packages/compass-collection/src/components/collection-header/collection-header.spec.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,35 @@ describe('CollectionHeader [Component]', function () {
294294
});
295295
});
296296
});
297+
298+
it('should handle undefined schemaAnalysis gracefully and render collection header successfully', function () {
299+
// Create a store with undefined schemaAnalysis to simulate initial state
300+
const mockStoreWithUndefinedSchema = createStore(() => ({
301+
mockDataGenerator: {
302+
isModalOpen: false,
303+
currentStep: MockDataGeneratorStep.SCHEMA_CONFIRMATION,
304+
},
305+
// schemaAnalysis not provided
306+
}));
307+
308+
expect(() => {
309+
renderWithConnections(
310+
<Provider store={mockStoreWithUndefinedSchema}>
311+
<WorkspacesServiceProvider value={{} as WorkspacesService}>
312+
<CollectionHeader
313+
isAtlas={false}
314+
isReadonly={false}
315+
isTimeSeries={false}
316+
isClustered={false}
317+
isFLE={false}
318+
namespace="test.test"
319+
/>
320+
</WorkspacesServiceProvider>
321+
</Provider>
322+
);
323+
}).to.not.throw();
324+
325+
expect(screen.getByTestId('collection-header')).to.exist;
326+
expect(screen.getByTestId('collection-header-actions')).to.exist;
327+
});
297328
});

packages/compass-collection/src/components/collection-header/collection-header.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,12 @@ const mapStateToProps = (state: CollectionState) => {
194194

195195
return {
196196
hasData:
197+
schemaAnalysis &&
197198
schemaAnalysis.status === SCHEMA_ANALYSIS_STATE_COMPLETE &&
198199
schemaAnalysis.processedSchema &&
199200
Object.keys(schemaAnalysis.processedSchema).length > 0,
200201
maxNestingDepth:
202+
schemaAnalysis &&
201203
schemaAnalysis.status === SCHEMA_ANALYSIS_STATE_COMPLETE &&
202204
schemaAnalysis.schemaMetadata
203205
? schemaAnalysis.schemaMetadata.maxNestingDepth

0 commit comments

Comments
 (0)