10
10
import React from 'react' ;
11
11
import { mount , shallow } from 'enzyme' ;
12
12
import { mountWithIntl } from '@kbn/test-jest-helpers' ;
13
+
13
14
import {
14
15
AreaSeries ,
15
16
Axis ,
@@ -36,6 +37,7 @@ import {
36
37
import { Datatable } from '@kbn/expressions-plugin/common' ;
37
38
import { EmptyPlaceholder } from '@kbn/charts-plugin/public' ;
38
39
import { dataPluginMock } from '@kbn/data-plugin/public/mocks' ;
40
+ import { ESQL_TABLE_TYPE } from '@kbn/data-plugin/common' ;
39
41
import { eventAnnotationServiceMock } from '@kbn/event-annotation-plugin/public/mocks' ;
40
42
import { EventAnnotationOutput } from '@kbn/event-annotation-plugin/common' ;
41
43
import { DataLayerConfig } from '../../common' ;
@@ -106,6 +108,23 @@ describe('XYChart component', () => {
106
108
return shallow ( < XYChart { ...defaultProps } args = { args } /> ) ;
107
109
} ;
108
110
111
+ const dataFromESQL : Datatable = {
112
+ type : 'datatable' ,
113
+ columns : [
114
+ { id : 'a' , name : 'a' , meta : { type : 'number' } } ,
115
+ { id : 'b' , name : 'b' , meta : { type : 'number' } } ,
116
+ { id : 'c' , name : 'c' , meta : { type : 'string' } } ,
117
+ { id : 'd' , name : 'd' , meta : { type : 'string' } } ,
118
+ ] ,
119
+ rows : [
120
+ { a : 1 , b : 2 , c : 'I' , d : 'Row 1' } ,
121
+ { a : 1 , b : 5 , c : 'J' , d : 'Row 2' } ,
122
+ ] ,
123
+ meta : {
124
+ type : ESQL_TABLE_TYPE ,
125
+ } ,
126
+ } ;
127
+
109
128
beforeEach ( ( ) => {
110
129
convertSpy = jest . fn ( ( x ) => x ) ;
111
130
getFormatSpy = jest . fn ( ) ;
@@ -1517,6 +1536,69 @@ describe('XYChart component', () => {
1517
1536
expect ( wrapper . find ( Settings ) . first ( ) . prop ( 'legendAction' ) ) . toBeUndefined ( ) ;
1518
1537
} ) ;
1519
1538
1539
+ test ( 'legendAction is not triggering event on ES|QL charts when unified search is on KQL/Lucene mode' , ( ) => {
1540
+ const { args } = sampleArgs ( ) ;
1541
+
1542
+ const newArgs = {
1543
+ ...args ,
1544
+ layers : args . layers . map ( ( l ) => ( {
1545
+ ...l ,
1546
+ table : dataFromESQL ,
1547
+ } ) ) ,
1548
+ } ;
1549
+ const dataMock = dataPluginMock . createStartContract ( ) ;
1550
+ const newProps = {
1551
+ ...defaultProps ,
1552
+ data : {
1553
+ ...dataMock ,
1554
+ query : {
1555
+ ...dataMock . query ,
1556
+ queryString : {
1557
+ ...dataMock . query . queryString ,
1558
+ getQuery : ( ) => ( {
1559
+ language : 'kuery' ,
1560
+ query : 'field:value' ,
1561
+ } ) ,
1562
+ } ,
1563
+ } ,
1564
+ } ,
1565
+ } ;
1566
+ const wrapper = mountWithIntl ( < XYChart { ...newProps } args = { newArgs } interactive = { true } /> ) ;
1567
+
1568
+ expect ( wrapper . find ( Settings ) . first ( ) . prop ( 'legendAction' ) ) . toBeUndefined ( ) ;
1569
+ } ) ;
1570
+
1571
+ test ( 'legendAction is triggering event on ES|QL charts when unified search is on ES|QL mode' , ( ) => {
1572
+ const { args } = sampleArgs ( ) ;
1573
+
1574
+ const newArgs = {
1575
+ ...args ,
1576
+ layers : args . layers . map ( ( l ) => ( {
1577
+ ...l ,
1578
+ table : dataFromESQL ,
1579
+ } ) ) ,
1580
+ } ;
1581
+ const dataMock = dataPluginMock . createStartContract ( ) ;
1582
+ const newProps = {
1583
+ ...defaultProps ,
1584
+ data : {
1585
+ ...dataMock ,
1586
+ query : {
1587
+ ...dataMock . query ,
1588
+ queryString : {
1589
+ ...dataMock . query . queryString ,
1590
+ getQuery : ( ) => ( {
1591
+ esql : 'FROM "index-pattern" WHERE "field" = "value"' ,
1592
+ } ) ,
1593
+ } ,
1594
+ } ,
1595
+ } ,
1596
+ } ;
1597
+ const wrapper = mountWithIntl ( < XYChart { ...newProps } args = { newArgs } interactive = { true } /> ) ;
1598
+
1599
+ expect ( wrapper . find ( Settings ) . first ( ) . prop ( 'legendAction' ) ) . toBeDefined ( ) ;
1600
+ } ) ;
1601
+
1520
1602
test ( 'it renders stacked bar' , ( ) => {
1521
1603
const { args } = sampleArgs ( ) ;
1522
1604
const component = shallow (
0 commit comments