Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ describe('CollectionHeaderActions [Component]', function () {
namespace="test.test"
isReadonly={false}
onOpenMockDataModal={sinon.stub()}
hasSchemaAnalysisData={true}
analyzedSchemaDepth={2}
{...props}
/>
</PreferencesProvider>
Expand Down Expand Up @@ -221,119 +223,6 @@ describe('CollectionHeaderActions [Component]', function () {
},
};

it('should not show Mock Data Generator button when user is in control group', async function () {
mockUseAssignment.returns({
assignment: {
assignmentData: {
variant: 'mockDataGeneratorControl',
},
},
});

await renderCollectionHeaderActions(
{
namespace: 'test.collection',
isReadonly: false,
},
{},
atlasConnectionInfo
);

expect(
screen.queryByTestId('collection-header-generate-mock-data-button')
).to.not.exist;
});

it('should not show Mock Data Generator button when not in Atlas', async function () {
mockUseAssignment.returns({
assignment: {
assignmentData: {
variant: 'treatment',
},
},
});

await renderCollectionHeaderActions({
namespace: 'test.collection',
isReadonly: false,
// Don't pass atlasConnectionInfo, to simulate not being in Atlas
});

expect(
screen.queryByTestId('collection-header-generate-mock-data-button')
).to.not.exist;
});

it('should not show Mock Data Generator button for readonly collections', async function () {
mockUseAssignment.returns({
assignment: {
assignmentData: {
variant: 'treatment',
},
},
});

await renderCollectionHeaderActions(
{
namespace: 'test.collection',
isReadonly: true,
},
{},
atlasConnectionInfo
);

expect(
screen.queryByTestId('collection-header-generate-mock-data-button')
).to.not.exist;
});

it('should not show Mock Data Generator button for views (sourceName present)', async function () {
mockUseAssignment.returns({
assignment: {
assignmentData: {
variant: 'treatment',
},
},
});

await renderCollectionHeaderActions(
{
namespace: 'test.collection',
isReadonly: false,
sourceName: 'source-collection',
},
{},
atlasConnectionInfo
);

expect(
screen.queryByTestId('collection-header-generate-mock-data-button')
).to.not.exist;
});

it('should show Mock Data Generator button when user is in treatment group and in Atlas', async function () {
mockUseAssignment.returns({
assignment: {
assignmentData: {
variant: 'mockDataGeneratorVariant',
},
},
});

await renderCollectionHeaderActions(
{
namespace: 'test.collection',
isReadonly: false,
},
{},
atlasConnectionInfo
);

expect(
screen.getByTestId('collection-header-generate-mock-data-button')
).to.exist;
});

it('should call useAssignment with correct parameters', async function () {
await renderCollectionHeaderActions({
namespace: 'test.collection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import {
ExperimentTestGroup,
} from '@mongodb-js/compass-telemetry/provider';

/**
* Maximum allowed nesting depth for collections to show Mock Data Generator
*/
const MAX_COLLECTION_NESTING_DEPTH = 4;

const collectionHeaderActionsStyles = css({
display: 'flex',
alignItems: 'center',
Expand Down Expand Up @@ -47,6 +52,8 @@ type CollectionHeaderActionsProps = {
sourceName?: string;
sourcePipeline?: unknown[];
onOpenMockDataModal: () => void;
hasSchemaAnalysisData: boolean;
analyzedSchemaDepth: number;
};

const CollectionHeaderActions: React.FunctionComponent<
Expand All @@ -58,6 +65,8 @@ const CollectionHeaderActions: React.FunctionComponent<
sourceName,
sourcePipeline,
onOpenMockDataModal,
hasSchemaAnalysisData,
analyzedSchemaDepth,
}: CollectionHeaderActionsProps) => {
const connectionInfo = useConnectionInfo();
const { id: connectionId, atlasMetadata } = connectionInfo;
Expand All @@ -84,10 +93,8 @@ const CollectionHeaderActions: React.FunctionComponent<
isInMockDataTreatmentVariant &&
atlasMetadata && // Only show in Atlas
!isReadonly && // Don't show for readonly collections (views)
!sourceName; // sourceName indicates it's a view
// TODO: CLOUDP-337090: also filter out overly nested collections

const hasData = true; // TODO: CLOUDP-337090
!sourceName && // sourceName indicates it's a view
analyzedSchemaDepth < MAX_COLLECTION_NESTING_DEPTH; // Filter out overly nested collections
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q - Do we care about observing when analyzedSchemaDepth < MAX_COLLECTION_NESTING_DEPTH ? If so, might be worth doing this check in the thunk and logging it there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting thought. I can ask analytics

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the meantime, if we do decide on this, how about we include this change as part of the analytics ticket?

Copy link
Collaborator

@kpamaran kpamaran Sep 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: max is an inclusive term so use <= and change to 3 instead


return (
<div
Expand All @@ -111,13 +118,13 @@ const CollectionHeaderActions: React.FunctionComponent<
)}
{shouldShowMockDataButton && (
<Tooltip
enabled={!hasData}
enabled={!hasSchemaAnalysisData}
trigger={
<div>
<Button
data-testid="collection-header-generate-mock-data-button"
size={ButtonSize.Small}
disabled={!hasData}
disabled={!hasSchemaAnalysisData}
onClick={onOpenMockDataModal}
leftGlyph={<Icon glyph="Sparkle" />}
>
Expand Down
Loading
Loading