17
17
* under the License.
18
18
*/
19
19
20
+ import { DateTime } from 'luxon' ;
20
21
import { Store } from 'redux' ;
21
22
22
23
import { MockGlobalSpec , MockSeriesSpec } from '../../../../mocks/specs/specs' ;
@@ -26,7 +27,7 @@ import { onMouseDown, onMouseUp, onPointerMove } from '../../../../state/actions
26
27
import { GlobalChartState } from '../../../../state/chart_state' ;
27
28
import { createOnBrushEndCaller } from './on_brush_end_caller' ;
28
29
29
- describe ( 'Heatmap brush' , ( ) => {
30
+ describe ( 'Categorical heatmap brush' , ( ) => {
30
31
let store : Store < GlobalChartState > ;
31
32
let onBrushEndMock = jest . fn ( ) ;
32
33
@@ -87,3 +88,79 @@ describe('Heatmap brush', () => {
87
88
expect ( brushEvent . y ) . toEqual ( [ 'ya' , 'yb' , 'yc' ] ) ;
88
89
} ) ;
89
90
} ) ;
91
+ describe ( 'Temporal heatmap brush' , ( ) => {
92
+ let store : Store < GlobalChartState > ;
93
+ let onBrushEndMock = jest . fn ( ) ;
94
+ const start = DateTime . fromISO ( '2021-07-01T00:00:00.000Z' ) ;
95
+ beforeEach ( ( ) => {
96
+ store = MockStore . default ( { width : 300 , height : 300 , top : 0 , left : 0 } , 'chartId' ) ;
97
+ onBrushEndMock = jest . fn ( ) ;
98
+ MockStore . addSpecs (
99
+ [
100
+ MockGlobalSpec . settingsNoMargins ( ) ,
101
+ MockSeriesSpec . heatmap ( {
102
+ xScaleType : ScaleType . Time ,
103
+ data : [
104
+ { x : start . toMillis ( ) , y : 'ya' , value : 1 } ,
105
+ { x : start . plus ( { days : 1 } ) . toMillis ( ) , y : 'ya' , value : 2 } ,
106
+ { x : start . plus ( { days : 2 } ) . toMillis ( ) , y : 'ya' , value : 3 } ,
107
+ { x : start . toMillis ( ) , y : 'yb' , value : 4 } ,
108
+ { x : start . plus ( { days : 1 } ) . toMillis ( ) , y : 'yb' , value : 5 } ,
109
+ { x : start . plus ( { days : 2 } ) . toMillis ( ) , y : 'yb' , value : 6 } ,
110
+ { x : start . toMillis ( ) , y : 'yc' , value : 7 } ,
111
+ { x : start . plus ( { days : 1 } ) . toMillis ( ) , y : 'yc' , value : 8 } ,
112
+ { x : start . plus ( { days : 2 } ) . toMillis ( ) , y : 'yc' , value : 9 } ,
113
+ ] ,
114
+ config : {
115
+ grid : {
116
+ cellHeight : {
117
+ max : 'fill' ,
118
+ } ,
119
+ cellWidth : {
120
+ max : 'fill' ,
121
+ } ,
122
+ } ,
123
+ xAxisLabel : {
124
+ visible : false ,
125
+ } ,
126
+ yAxisLabel : {
127
+ visible : false ,
128
+ } ,
129
+ margin : { top : 0 , bottom : 0 , left : 0 , right : 0 } ,
130
+ onBrushEnd : onBrushEndMock ,
131
+ } ,
132
+ } ) ,
133
+ ] ,
134
+ store ,
135
+ ) ;
136
+ } ) ;
137
+
138
+ it ( 'should brush on the x scale + minInterval' , ( ) => {
139
+ const caller = createOnBrushEndCaller ( ) ;
140
+ store . dispatch ( onPointerMove ( { x : 50 , y : 50 } , 0 ) ) ;
141
+ store . dispatch ( onMouseDown ( { x : 50 , y : 50 } , 100 ) ) ;
142
+ store . dispatch ( onPointerMove ( { x : 250 , y : 250 } , 200 ) ) ;
143
+ store . dispatch ( onMouseUp ( { x : 250 , y : 250 } , 300 ) ) ;
144
+ caller ( store . getState ( ) ) ;
145
+ expect ( onBrushEndMock ) . toBeCalledTimes ( 1 ) ;
146
+ const brushEvent = onBrushEndMock . mock . calls [ 0 ] [ 0 ] ;
147
+ expect ( brushEvent . cells ) . toHaveLength ( 6 ) ;
148
+ // it covers from the beginning of the cell to the end of the next cell
149
+ expect ( brushEvent . x ) . toEqual ( [ start . toMillis ( ) , start . plus ( { days : 2 } ) . toMillis ( ) ] ) ;
150
+ expect ( brushEvent . y ) . toEqual ( [ 'ya' , 'yb' , 'yc' ] ) ;
151
+ } ) ;
152
+ it ( 'should brush on the x scale + minInterval on a single cell' , ( ) => {
153
+ const caller = createOnBrushEndCaller ( ) ;
154
+ store . dispatch ( onPointerMove ( { x : 50 , y : 50 } , 0 ) ) ;
155
+ store . dispatch ( onMouseDown ( { x : 50 , y : 50 } , 100 ) ) ;
156
+ store . dispatch ( onPointerMove ( { x : 60 , y : 60 } , 200 ) ) ;
157
+ store . dispatch ( onMouseUp ( { x : 60 , y : 60 } , 300 ) ) ;
158
+ caller ( store . getState ( ) ) ;
159
+ expect ( onBrushEndMock ) . toBeCalledTimes ( 1 ) ;
160
+ const brushEvent = onBrushEndMock . mock . calls [ 0 ] [ 0 ] ;
161
+ expect ( brushEvent . cells ) . toHaveLength ( 1 ) ;
162
+ // it covers from the beginning of the cell to the end of the next cell
163
+ expect ( brushEvent . x ) . toEqual ( [ start . toMillis ( ) , start . plus ( { days : 1 } ) . toMillis ( ) ] ) ;
164
+ expect ( brushEvent . y ) . toEqual ( [ 'ya' ] ) ;
165
+ } ) ;
166
+ } ) ;
0 commit comments