@@ -90,6 +90,218 @@ describe('ResultSet', () => {
90
90
} ) ;
91
91
} ) ;
92
92
93
+ describe ( 'chartPivot' , ( ) => {
94
+ test ( 'String field' , ( ) => {
95
+ const resultSet = new ResultSet ( {
96
+ query : {
97
+ measures : [ 'Foo.count' ] ,
98
+ dimensions : [ 'Foo.name' ] ,
99
+ filters : [ ] ,
100
+ timezone : 'UTC' ,
101
+ timeDimensions : [ ] ,
102
+ } ,
103
+ data : [ {
104
+ 'Foo.name' : 'Name 1' ,
105
+ 'Foo.count' : 'Some string' ,
106
+ } ] ,
107
+ lastRefreshTime : '2020-03-18T13:41:04.436Z' ,
108
+ usedPreAggregations : { } ,
109
+ annotation : {
110
+ measures : {
111
+ 'Foo.count' : {
112
+ title : 'Foo Count' ,
113
+ shortTitle : 'Count' ,
114
+ type : 'number' ,
115
+ } ,
116
+ } ,
117
+ dimensions : {
118
+ 'Foo.name' : {
119
+ title : 'Foo Name' ,
120
+ shortTitle : 'Name' ,
121
+ type : 'string' ,
122
+ } ,
123
+ } ,
124
+ segments : { } ,
125
+ timeDimensions : { } ,
126
+ } ,
127
+ } ) ;
128
+
129
+ expect ( resultSet . chartPivot ( ) ) . toEqual ( [ {
130
+ x : 'Name 1' ,
131
+ category : 'Name 1' ,
132
+ 'Foo.count' : 'Some string' ,
133
+ } ] ) ;
134
+ } ) ;
135
+
136
+ test ( 'Null field' , ( ) => {
137
+ const resultSet = new ResultSet ( {
138
+ query : {
139
+ measures : [ 'Foo.count' ] ,
140
+ dimensions : [ 'Foo.name' ] ,
141
+ filters : [ ] ,
142
+ timezone : 'UTC' ,
143
+ timeDimensions : [ ] ,
144
+ } ,
145
+ data : [ {
146
+ 'Foo.name' : 'Name 1' ,
147
+ 'Foo.count' : null ,
148
+ } ] ,
149
+ lastRefreshTime : '2020-03-18T13:41:04.436Z' ,
150
+ usedPreAggregations : { } ,
151
+ annotation : {
152
+ measures : {
153
+ 'Foo.count' : {
154
+ title : 'Foo Count' ,
155
+ shortTitle : 'Count' ,
156
+ type : 'number' ,
157
+ } ,
158
+ } ,
159
+ dimensions : {
160
+ 'Foo.name' : {
161
+ title : 'Foo Name' ,
162
+ shortTitle : 'Name' ,
163
+ type : 'string' ,
164
+ } ,
165
+ } ,
166
+ segments : { } ,
167
+ timeDimensions : { } ,
168
+ } ,
169
+ } ) ;
170
+
171
+ expect ( resultSet . chartPivot ( ) ) . toEqual ( [ {
172
+ x : 'Name 1' ,
173
+ category : 'Name 1' ,
174
+ 'Foo.count' : null ,
175
+ } ] ) ;
176
+ } ) ;
177
+
178
+ test ( 'Empty field' , ( ) => {
179
+ const resultSet = new ResultSet ( {
180
+ query : {
181
+ measures : [ 'Foo.count' ] ,
182
+ dimensions : [ 'Foo.name' ] ,
183
+ filters : [ ] ,
184
+ timezone : 'UTC' ,
185
+ timeDimensions : [ ] ,
186
+ } ,
187
+ data : [ {
188
+ 'Foo.name' : 'Name 1' ,
189
+ 'Foo.count' : undefined ,
190
+ } ] ,
191
+ lastRefreshTime : '2020-03-18T13:41:04.436Z' ,
192
+ usedPreAggregations : { } ,
193
+ annotation : {
194
+ measures : {
195
+ 'Foo.count' : {
196
+ title : 'Foo Count' ,
197
+ shortTitle : 'Count' ,
198
+ type : 'number' ,
199
+ } ,
200
+ } ,
201
+ dimensions : {
202
+ 'Foo.name' : {
203
+ title : 'Foo Name' ,
204
+ shortTitle : 'Name' ,
205
+ type : 'string' ,
206
+ } ,
207
+ } ,
208
+ segments : { } ,
209
+ timeDimensions : { } ,
210
+ } ,
211
+ } ) ;
212
+
213
+ expect ( resultSet . chartPivot ( ) ) . toEqual ( [ {
214
+ x : 'Name 1' ,
215
+ category : 'Name 1' ,
216
+ 'Foo.count' : undefined ,
217
+ } ] ) ;
218
+ } ) ;
219
+
220
+ test ( 'Number field' , ( ) => {
221
+ const resultSet = new ResultSet ( {
222
+ query : {
223
+ measures : [ 'Foo.count' ] ,
224
+ dimensions : [ 'Foo.name' ] ,
225
+ filters : [ ] ,
226
+ timezone : 'UTC' ,
227
+ timeDimensions : [ ] ,
228
+ } ,
229
+ data : [ {
230
+ 'Foo.name' : 'Name 1' ,
231
+ 'Foo.count' : 10 ,
232
+ } ] ,
233
+ lastRefreshTime : '2020-03-18T13:41:04.436Z' ,
234
+ usedPreAggregations : { } ,
235
+ annotation : {
236
+ measures : {
237
+ 'Foo.count' : {
238
+ title : 'Foo Count' ,
239
+ shortTitle : 'Count' ,
240
+ type : 'number' ,
241
+ } ,
242
+ } ,
243
+ dimensions : {
244
+ 'Foo.name' : {
245
+ title : 'Foo Name' ,
246
+ shortTitle : 'Name' ,
247
+ type : 'string' ,
248
+ } ,
249
+ } ,
250
+ segments : { } ,
251
+ timeDimensions : { } ,
252
+ } ,
253
+ } ) ;
254
+
255
+ expect ( resultSet . chartPivot ( ) ) . toEqual ( [ {
256
+ x : 'Name 1' ,
257
+ category : 'Name 1' ,
258
+ 'Foo.count' : 10 ,
259
+ } ] ) ;
260
+ } ) ;
261
+
262
+ test ( 'time field results' , ( ) => {
263
+ const resultSet = new ResultSet ( {
264
+ query : {
265
+ measures : [ 'Foo.latestRun' ] ,
266
+ dimensions : [ 'Foo.name' ] ,
267
+ filters : [ ] ,
268
+ timezone : 'UTC' ,
269
+ timeDimensions : [ ] ,
270
+ } ,
271
+ data : [ {
272
+ 'Foo.name' : 'Name 1' ,
273
+ 'Foo.latestRun' : '2020-03-11T18:06:09.403Z' ,
274
+ } ] ,
275
+ lastRefreshTime : '2020-03-18T13:41:04.436Z' ,
276
+ usedPreAggregations : { } ,
277
+ annotation : {
278
+ measures : {
279
+ 'Foo.latestRun' : {
280
+ title : 'Foo Latest Run' ,
281
+ shortTitle : 'Latest Run' ,
282
+ type : 'number' ,
283
+ } ,
284
+ } ,
285
+ dimensions : {
286
+ 'Foo.name' : {
287
+ title : 'Foo Name' ,
288
+ shortTitle : 'Name' ,
289
+ type : 'string' ,
290
+ } ,
291
+ } ,
292
+ segments : { } ,
293
+ timeDimensions : { } ,
294
+ } ,
295
+ } ) ;
296
+
297
+ expect ( resultSet . chartPivot ( ) ) . toEqual ( [ {
298
+ x : 'Name 1' ,
299
+ category : 'Name 1' ,
300
+ 'Foo.latestRun' : new Date ( '2020-03-11T18:06:09.403Z' ) ,
301
+ } ] ) ;
302
+ } ) ;
303
+ } ) ;
304
+
93
305
describe ( 'normalizePivotConfig' , ( ) => {
94
306
test ( 'fills missing x, y' , ( ) => {
95
307
const resultSet = new ResultSet ( {
0 commit comments