@@ -3,6 +3,7 @@ import React, { type ComponentProps } from 'react';
33import {
44 renderWithActiveConnection ,
55 screen ,
6+ waitFor ,
67} from '@mongodb-js/testing-library-compass' ;
78import sinon from 'sinon' ;
89import {
@@ -14,6 +15,7 @@ import { CompassExperimentationProvider } from '@mongodb-js/compass-telemetry';
1415import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider' ;
1516
1617import CollectionHeaderActions from '../collection-header-actions' ;
18+ import { MAX_COLLECTION_NESTING_DEPTH } from '../mock-data-generator-modal/utils' ;
1719
1820describe ( 'CollectionHeaderActions [Component]' , function ( ) {
1921 let mockUseAssignment : sinon . SinonStub ;
@@ -230,94 +232,132 @@ describe('CollectionHeaderActions [Component]', function () {
230232 ) ;
231233 } ) ;
232234
233- it ( 'should call onOpenMockDataModal when CTA button is clicked' , async function ( ) {
234- const onOpenMockDataModal = sinon . stub ( ) ;
235+ context ( 'when in the mock data generator treatment variant' , function ( ) {
236+ beforeEach ( function ( ) {
237+ mockUseAssignment . returns ( {
238+ assignment : {
239+ assignmentData : {
240+ variant : 'mockDataGeneratorVariant' ,
241+ } ,
242+ } ,
243+ } ) ;
244+ } ) ;
235245
236- mockUseAssignment . returns ( {
237- assignment : {
238- assignmentData : {
239- variant : 'mockDataGeneratorVariant' ,
246+ it ( 'should send a track event when the button is viewed' , async function ( ) {
247+ const result = await renderCollectionHeaderActions (
248+ {
249+ namespace : 'test.collection' ,
250+ isReadonly : false ,
240251 } ,
241- } ,
252+ { } ,
253+ atlasConnectionInfo
254+ ) ;
255+
256+ await waitFor ( ( ) => {
257+ expect ( result . track ) . to . have . been . calledWith (
258+ 'Mock Data Generator CTA Button Viewed' ,
259+ {
260+ button_enabled : true ,
261+ gen_ai_features_enabled : false ,
262+ send_sample_values_enabled : false ,
263+ }
264+ ) ;
265+ } ) ;
242266 } ) ;
243267
244- await renderCollectionHeaderActions (
245- {
246- namespace : 'test.collection' ,
247- isReadonly : false ,
248- onOpenMockDataModal,
249- } ,
250- { } ,
251- atlasConnectionInfo
252- ) ;
268+ it ( 'should call onOpenMockDataModal when CTA button is clicked' , async function ( ) {
269+ const onOpenMockDataModal = sinon . stub ( ) ;
270+ await renderCollectionHeaderActions (
271+ {
272+ namespace : 'test.collection' ,
273+ isReadonly : false ,
274+ onOpenMockDataModal,
275+ } ,
276+ { } ,
277+ atlasConnectionInfo
278+ ) ;
253279
254- const button = screen . getByTestId (
255- 'collection-header-generate-mock-data-button'
256- ) ;
257- button . click ( ) ;
280+ const button = screen . getByTestId (
281+ 'collection-header-generate-mock-data-button'
282+ ) ;
283+ button . click ( ) ;
258284
259- expect ( onOpenMockDataModal ) . to . have . been . calledOnce ;
260- } ) ;
285+ expect ( onOpenMockDataModal ) . to . have . been . calledOnce ;
286+ } ) ;
261287
262- it ( 'should disable button for deeply nested collections' , async function ( ) {
263- mockUseAssignment . returns ( {
264- assignment : {
265- assignmentData : {
266- variant : 'mockDataGeneratorVariant' , // Treatment variant
288+ it ( 'sends a track event when CTA button is clicked' , async function ( ) {
289+ const onOpenMockDataModal = sinon . stub ( ) ;
290+
291+ const result = await renderCollectionHeaderActions (
292+ {
293+ namespace : 'test.collection' ,
294+ isReadonly : false ,
295+ onOpenMockDataModal,
267296 } ,
268- } ,
269- } ) ;
297+ { } ,
298+ atlasConnectionInfo
299+ ) ;
270300
271- await renderCollectionHeaderActions (
272- {
273- namespace : 'test.collection' ,
274- isReadonly : false ,
275- hasSchemaAnalysisData : true ,
276- analyzedSchemaDepth : 8 , // Exceeds MAX_COLLECTION_NESTING_DEPTH (7)
277- schemaAnalysisStatus : 'complete' ,
278- onOpenMockDataModal : sinon . stub ( ) ,
279- } ,
280- { } ,
281- atlasConnectionInfo
282- ) ;
301+ const button = screen . getByTestId (
302+ 'collection-header-generate-mock-data-button'
303+ ) ;
304+ button . click ( ) ;
283305
284- const button = screen . getByTestId (
285- 'collection-header-generate-mock-data-button'
286- ) ;
287- expect ( button ) . to . exist ;
288- expect ( button ) . to . have . attribute ( 'aria-disabled' , 'true' ) ;
289- } ) ;
306+ await waitFor ( ( ) => {
307+ expect ( result . track ) . to . have . been . calledWith (
308+ 'Mock Data Generator Opened' ,
309+ {
310+ gen_ai_features_enabled : false ,
311+ send_sample_values_enabled : false ,
312+ }
313+ ) ;
314+ } ) ;
315+ } ) ;
290316
291- it ( 'should show an error banner when the schema is in an unsupported state' , async function ( ) {
292- mockUseAssignment . returns ( {
293- assignment : {
294- assignmentData : {
295- variant : 'mockDataGeneratorVariant' ,
317+ it ( 'should disable button for deeply nested collections' , async function ( ) {
318+ await renderCollectionHeaderActions (
319+ {
320+ namespace : 'test.collection' ,
321+ isReadonly : false ,
322+ hasSchemaAnalysisData : true ,
323+ analyzedSchemaDepth : MAX_COLLECTION_NESTING_DEPTH + 1 ,
324+ schemaAnalysisStatus : 'complete' ,
325+ onOpenMockDataModal : sinon . stub ( ) ,
296326 } ,
297- } ,
327+ { } ,
328+ atlasConnectionInfo
329+ ) ;
330+
331+ const button = screen . getByTestId (
332+ 'collection-header-generate-mock-data-button'
333+ ) ;
334+ expect ( button ) . to . exist ;
335+ expect ( button ) . to . have . attribute ( 'aria-disabled' , 'true' ) ;
298336 } ) ;
299337
300- await renderCollectionHeaderActions (
301- {
302- namespace : 'test.collection' ,
303- isReadonly : false ,
304- hasSchemaAnalysisData : false ,
305- schemaAnalysisStatus : 'error' ,
306- schemaAnalysisError : {
307- errorType : 'unsupportedState' ,
308- errorMessage : 'Unsupported state' ,
338+ it ( 'should show an error banner when the schema is in an unsupported state' , async function ( ) {
339+ await renderCollectionHeaderActions (
340+ {
341+ namespace : 'test.collection' ,
342+ isReadonly : false ,
343+ hasSchemaAnalysisData : false ,
344+ schemaAnalysisStatus : 'error' ,
345+ schemaAnalysisError : {
346+ errorType : 'unsupportedState' ,
347+ errorMessage : 'Unsupported state' ,
348+ } ,
349+ onOpenMockDataModal : sinon . stub ( ) ,
309350 } ,
310- onOpenMockDataModal : sinon . stub ( ) ,
311- } ,
312- { } ,
313- atlasConnectionInfo
314- ) ;
351+ { } ,
352+ atlasConnectionInfo
353+ ) ;
315354
316- const button = screen . getByTestId (
317- 'collection-header-generate-mock-data-button'
318- ) ;
319- expect ( button ) . to . exist ;
320- expect ( button ) . to . have . attribute ( 'aria-disabled' , 'true' ) ;
355+ const button = screen . getByTestId (
356+ 'collection-header-generate-mock-data-button'
357+ ) ;
358+ expect ( button ) . to . exist ;
359+ expect ( button ) . to . have . attribute ( 'aria-disabled' , 'true' ) ;
360+ } ) ;
321361 } ) ;
322362 } ) ;
323363} ) ;
0 commit comments