@@ -21,7 +21,7 @@ import { Pick2 } from '../../common/utility_types';
2121
2222type MockIndexPattern = Pick <
2323 IndexPattern ,
24- 'id' | 'title' | 'type' | 'getTimeField' | 'isTimeBased' | 'getFieldByName'
24+ 'id' | 'title' | 'type' | 'getTimeField' | 'isTimeBased' | 'getFieldByName' | 'getComputedFields'
2525> ;
2626export type MockIndexPatternSpec = Pick <
2727 IIndexPattern ,
@@ -35,23 +35,7 @@ export const MockIndexPatternsKibanaContextProvider: React.FC<{
3535 mockIndexPatterns : MockIndexPatternSpec [ ] ;
3636} > = ( { asyncDelay, children, mockIndexPatterns } ) => {
3737 const indexPatterns = useMemo (
38- ( ) =>
39- createIndexPatternsMock (
40- asyncDelay ,
41- mockIndexPatterns . map ( ( { id, title, type = undefined , fields, timeFieldName } ) => {
42- const indexPatternFields = fields . map ( ( fieldSpec ) => new IndexPatternField ( fieldSpec ) ) ;
43-
44- return {
45- id,
46- title,
47- type,
48- getTimeField : ( ) => indexPatternFields . find ( ( { name } ) => name === timeFieldName ) ,
49- isTimeBased : ( ) => timeFieldName != null ,
50- getFieldByName : ( fieldName ) =>
51- indexPatternFields . find ( ( { name } ) => name === fieldName ) ,
52- } ;
53- } )
54- ) ,
38+ ( ) => createIndexPatternsMock ( asyncDelay , mockIndexPatterns . map ( createIndexPatternMock ) ) ,
5539 [ asyncDelay , mockIndexPatterns ]
5640 ) ;
5741
@@ -71,7 +55,7 @@ export const MockIndexPatternsKibanaContextProvider: React.FC<{
7155 ) ;
7256} ;
7357
74- const createIndexPatternsMock = (
58+ export const createIndexPatternsMock = (
7559 asyncDelay : number ,
7660 indexPatterns : MockIndexPattern [ ]
7761) : {
@@ -93,3 +77,36 @@ const createIndexPatternsMock = (
9377 } ,
9478 } ;
9579} ;
80+
81+ export const createIndexPatternMock = ( {
82+ id,
83+ title,
84+ type = undefined ,
85+ fields,
86+ timeFieldName,
87+ } : MockIndexPatternSpec ) : MockIndexPattern => {
88+ const indexPatternFields = fields . map ( ( fieldSpec ) => new IndexPatternField ( fieldSpec ) ) ;
89+
90+ return {
91+ id,
92+ title,
93+ type,
94+ getTimeField : ( ) => indexPatternFields . find ( ( { name } ) => name === timeFieldName ) ,
95+ isTimeBased : ( ) => timeFieldName != null ,
96+ getFieldByName : ( fieldName ) => indexPatternFields . find ( ( { name } ) => name === fieldName ) ,
97+ getComputedFields : ( ) => ( {
98+ docvalueFields : [ ] ,
99+ runtimeFields : indexPatternFields . reduce ( ( accumulatedRuntimeFields , field ) => {
100+ if ( field . runtimeField != null ) {
101+ return {
102+ ...accumulatedRuntimeFields ,
103+ [ field . name ] : field . runtimeField ,
104+ } ;
105+ }
106+ return accumulatedRuntimeFields ;
107+ } , { } ) ,
108+ scriptFields : { } ,
109+ storedFields : [ ] ,
110+ } ) ,
111+ } ;
112+ } ;
0 commit comments