@@ -2,6 +2,8 @@ import { cloneDeep } from 'lodash'
2
2
import React from 'react'
3
3
import { instance , mock } from 'ts-mockito'
4
4
import { cleanup , mockedStore , render , fireEvent , act , screen , waitForEuiToolTipVisible } from 'uiSrc/utils/test-utils'
5
+ import { TelemetryEvent , sendEventTelemetry } from 'uiSrc/telemetry'
6
+ import { INSTANCE_ID_MOCK } from 'uiSrc/mocks/handlers/instances/instancesHandlers'
5
7
import QueryCardHeader , { Props } from './QueryCardHeader'
6
8
7
9
const mockedProps = mock < Props > ( )
@@ -28,6 +30,11 @@ jest.mock('uiSrc/slices/app/plugins', () => ({
28
30
} ) ,
29
31
} ) )
30
32
33
+ jest . mock ( 'uiSrc/telemetry' , ( ) => ( {
34
+ ...jest . requireActual ( 'uiSrc/telemetry' ) ,
35
+ sendEventTelemetry : jest . fn ( ) ,
36
+ } ) )
37
+
31
38
describe ( 'QueryCardHeader' , ( ) => {
32
39
it ( 'should render' , ( ) => {
33
40
// connectedInstanceSelector.mockImplementation(() => ({
@@ -57,4 +64,25 @@ describe('QueryCardHeader', () => {
57
64
58
65
expect ( screen . getByTestId ( 'copy-command' ) ) . toBeDisabled ( )
59
66
} )
67
+
68
+ it ( 'should render disabled copy button' , async ( ) => {
69
+ const command = 'info'
70
+ const sendEventTelemetryMock = jest . fn ( ) ;
71
+ ( sendEventTelemetry as jest . Mock ) . mockImplementation ( ( ) => sendEventTelemetryMock )
72
+ render ( < QueryCardHeader { ...instance ( mockedProps ) } query = { command } /> )
73
+
74
+ await act ( async ( ) => {
75
+ fireEvent . click ( screen . getByTestId ( 'copy-command' ) )
76
+ } )
77
+
78
+ expect ( sendEventTelemetry ) . toBeCalledWith ( {
79
+ event : TelemetryEvent . WORKBENCH_COMMAND_COPIED ,
80
+ eventData : {
81
+ command,
82
+ databaseId : INSTANCE_ID_MOCK ,
83
+ }
84
+ } ) ;
85
+
86
+ ( sendEventTelemetry as jest . Mock ) . mockRestore ( )
87
+ } )
60
88
} )
0 commit comments