@thoughtspot/ts-chart-sdk 0.0.1-alpha.9 → 0.0.2-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/dist/ts-chart-sdk.d.ts +449 -31
  2. package/lib/index.d.ts +3 -0
  3. package/lib/index.d.ts.map +1 -1
  4. package/lib/index.js +3 -0
  5. package/lib/index.js.map +1 -1
  6. package/lib/main/custom-chart-context.d.ts +17 -5
  7. package/lib/main/custom-chart-context.d.ts.map +1 -1
  8. package/lib/main/custom-chart-context.js +74 -34
  9. package/lib/main/custom-chart-context.js.map +1 -1
  10. package/lib/main/custom-chart-context.spec.js +256 -257
  11. package/lib/main/custom-chart-context.spec.js.map +1 -1
  12. package/lib/main/post-message-event-bridge.d.ts +3 -3
  13. package/lib/main/post-message-event-bridge.d.ts.map +1 -1
  14. package/lib/main/post-message-event-bridge.js +24 -36
  15. package/lib/main/post-message-event-bridge.js.map +1 -1
  16. package/lib/main/post-message-event-bridge.spec.js +0 -2
  17. package/lib/main/post-message-event-bridge.spec.js.map +1 -1
  18. package/lib/main/util.d.ts +2 -0
  19. package/lib/main/util.d.ts.map +1 -0
  20. package/lib/main/util.js +9 -0
  21. package/lib/main/util.js.map +1 -0
  22. package/lib/react/use-custom-chart-context.spec.js +128 -121
  23. package/lib/react/use-custom-chart-context.spec.js.map +1 -1
  24. package/lib/test/test-conditional-formatting-utils.d.ts +5 -0
  25. package/lib/test/test-conditional-formatting-utils.d.ts.map +1 -0
  26. package/lib/test/test-conditional-formatting-utils.js +43 -0
  27. package/lib/test/test-conditional-formatting-utils.js.map +1 -0
  28. package/lib/types/answer-column.types.d.ts +54 -1
  29. package/lib/types/answer-column.types.d.ts.map +1 -1
  30. package/lib/types/answer-column.types.js +47 -0
  31. package/lib/types/answer-column.types.js.map +1 -1
  32. package/lib/types/common.types.d.ts +51 -4
  33. package/lib/types/common.types.d.ts.map +1 -1
  34. package/lib/types/common.types.js +15 -1
  35. package/lib/types/common.types.js.map +1 -1
  36. package/lib/types/conditional-formatting.types.d.ts +155 -0
  37. package/lib/types/conditional-formatting.types.d.ts.map +1 -0
  38. package/lib/types/conditional-formatting.types.js +60 -0
  39. package/lib/types/conditional-formatting.types.js.map +1 -0
  40. package/lib/types/configurator.types.d.ts +5 -0
  41. package/lib/types/configurator.types.d.ts.map +1 -1
  42. package/lib/types/ts-to-chart-event.types.d.ts +3 -0
  43. package/lib/types/ts-to-chart-event.types.d.ts.map +1 -1
  44. package/lib/types/ts-to-chart-event.types.js.map +1 -1
  45. package/lib/types/visual-prop.types.d.ts +3 -0
  46. package/lib/types/visual-prop.types.d.ts.map +1 -1
  47. package/lib/utils/conditional-formatting/conditional-formatting.d.ts +10 -0
  48. package/lib/utils/conditional-formatting/conditional-formatting.d.ts.map +1 -0
  49. package/lib/utils/conditional-formatting/conditional-formatting.js +103 -0
  50. package/lib/utils/conditional-formatting/conditional-formatting.js.map +1 -0
  51. package/lib/utils/conditional-formatting/conditional-formatting.spec.d.ts +2 -0
  52. package/lib/utils/conditional-formatting/conditional-formatting.spec.d.ts.map +1 -0
  53. package/lib/utils/conditional-formatting/conditional-formatting.spec.js +142 -0
  54. package/lib/utils/conditional-formatting/conditional-formatting.spec.js.map +1 -0
  55. package/lib/utils/date-formatting.d.ts +19 -0
  56. package/lib/utils/date-formatting.d.ts.map +1 -0
  57. package/lib/utils/date-formatting.js +56 -0
  58. package/lib/utils/date-formatting.js.map +1 -0
  59. package/lib/utils/date-formatting.spec.d.ts +2 -0
  60. package/lib/utils/date-formatting.spec.d.ts.map +1 -0
  61. package/lib/utils/date-formatting.spec.js +124 -0
  62. package/lib/utils/date-formatting.spec.js.map +1 -0
  63. package/package.json +10 -7
  64. package/src/index.ts +3 -0
  65. package/src/main/custom-chart-context.spec.ts +291 -266
  66. package/src/main/custom-chart-context.ts +164 -46
  67. package/src/main/post-message-event-bridge.spec.ts +0 -3
  68. package/src/main/post-message-event-bridge.ts +36 -62
  69. package/src/main/util.ts +11 -0
  70. package/src/react/use-custom-chart-context.spec.tsx +149 -122
  71. package/src/test/test-conditional-formatting-utils.ts +95 -0
  72. package/src/types/answer-column.types.ts +98 -0
  73. package/src/types/common.types.ts +82 -10
  74. package/src/types/conditional-formatting.types.ts +172 -0
  75. package/src/types/configurator.types.ts +21 -0
  76. package/src/types/ts-to-chart-event.types.ts +15 -0
  77. package/src/types/visual-prop.types.ts +7 -0
  78. package/src/utils/conditional-formatting/conditional-formatting.spec.ts +469 -0
  79. package/src/utils/conditional-formatting/conditional-formatting.ts +229 -0
  80. package/src/utils/date-formatting.spec.ts +168 -0
  81. package/src/utils/date-formatting.ts +109 -0
  82. package/cjs/index.d.ts +0 -9
  83. package/cjs/index.d.ts.map +0 -1
  84. package/cjs/index.js +0 -25
  85. package/cjs/index.js.map +0 -1
  86. package/cjs/main/custom-chart-context.d.ts +0 -47
  87. package/cjs/main/custom-chart-context.d.ts.map +0 -1
  88. package/cjs/main/custom-chart-context.js +0 -326
  89. package/cjs/main/custom-chart-context.js.map +0 -1
  90. package/cjs/main/custom-chart-context.spec.d.ts +0 -2
  91. package/cjs/main/custom-chart-context.spec.d.ts.map +0 -1
  92. package/cjs/main/custom-chart-context.spec.js +0 -699
  93. package/cjs/main/custom-chart-context.spec.js.map +0 -1
  94. package/cjs/main/post-message-event-bridge.d.ts +0 -6
  95. package/cjs/main/post-message-event-bridge.d.ts.map +0 -1
  96. package/cjs/main/post-message-event-bridge.js +0 -46
  97. package/cjs/main/post-message-event-bridge.js.map +0 -1
  98. package/cjs/main/post-message-event-bridge.spec.d.ts +0 -2
  99. package/cjs/main/post-message-event-bridge.spec.d.ts.map +0 -1
  100. package/cjs/main/post-message-event-bridge.spec.js +0 -124
  101. package/cjs/main/post-message-event-bridge.spec.js.map +0 -1
  102. package/cjs/react/custom-chart-context-service.d.ts +0 -33
  103. package/cjs/react/custom-chart-context-service.d.ts.map +0 -1
  104. package/cjs/react/custom-chart-context-service.js +0 -118
  105. package/cjs/react/custom-chart-context-service.js.map +0 -1
  106. package/cjs/react/custom-chart.context.d.ts +0 -26
  107. package/cjs/react/custom-chart.context.d.ts.map +0 -1
  108. package/cjs/react/custom-chart.context.js +0 -105
  109. package/cjs/react/custom-chart.context.js.map +0 -1
  110. package/cjs/react/custom-chart.spec.d.ts +0 -2
  111. package/cjs/react/custom-chart.spec.d.ts.map +0 -1
  112. package/cjs/react/custom-chart.spec.js +0 -72
  113. package/cjs/react/custom-chart.spec.js.map +0 -1
  114. package/cjs/react/mocks/custom-chart-context-mock.d.ts +0 -3
  115. package/cjs/react/mocks/custom-chart-context-mock.d.ts.map +0 -1
  116. package/cjs/react/mocks/custom-chart-context-mock.js +0 -100
  117. package/cjs/react/mocks/custom-chart-context-mock.js.map +0 -1
  118. package/cjs/react/use-custom-chart-context.d.ts +0 -4
  119. package/cjs/react/use-custom-chart-context.d.ts.map +0 -1
  120. package/cjs/react/use-custom-chart-context.js +0 -95
  121. package/cjs/react/use-custom-chart-context.js.map +0 -1
  122. package/cjs/react/use-custom-chart-context.spec.d.ts +0 -2
  123. package/cjs/react/use-custom-chart-context.spec.d.ts.map +0 -1
  124. package/cjs/react/use-custom-chart-context.spec.js +0 -391
  125. package/cjs/react/use-custom-chart-context.spec.js.map +0 -1
  126. package/cjs/react/use-custom-chart-context.util.d.ts +0 -6
  127. package/cjs/react/use-custom-chart-context.util.d.ts.map +0 -1
  128. package/cjs/react/use-custom-chart-context.util.js +0 -60
  129. package/cjs/react/use-custom-chart-context.util.js.map +0 -1
  130. package/cjs/react/use-custom-chart-types.d.ts +0 -23
  131. package/cjs/react/use-custom-chart-types.d.ts.map +0 -1
  132. package/cjs/react/use-custom-chart-types.js +0 -3
  133. package/cjs/react/use-custom-chart-types.js.map +0 -1
  134. package/cjs/test/test-utils.d.ts +0 -7
  135. package/cjs/test/test-utils.d.ts.map +0 -1
  136. package/cjs/test/test-utils.js +0 -14
  137. package/cjs/test/test-utils.js.map +0 -1
  138. package/cjs/types/answer-column.types.d.ts +0 -69
  139. package/cjs/types/answer-column.types.d.ts.map +0 -1
  140. package/cjs/types/answer-column.types.js +0 -59
  141. package/cjs/types/answer-column.types.js.map +0 -1
  142. package/cjs/types/chart-to-ts-event.types.d.ts +0 -98
  143. package/cjs/types/chart-to-ts-event.types.d.ts.map +0 -1
  144. package/cjs/types/chart-to-ts-event.types.js +0 -32
  145. package/cjs/types/chart-to-ts-event.types.js.map +0 -1
  146. package/cjs/types/common.types.d.ts +0 -51
  147. package/cjs/types/common.types.d.ts.map +0 -1
  148. package/cjs/types/common.types.js +0 -3
  149. package/cjs/types/common.types.js.map +0 -1
  150. package/cjs/types/configurator.types.d.ts +0 -15
  151. package/cjs/types/configurator.types.d.ts.map +0 -1
  152. package/cjs/types/configurator.types.js +0 -3
  153. package/cjs/types/configurator.types.js.map +0 -1
  154. package/cjs/types/ts-to-chart-event.types.d.ts +0 -91
  155. package/cjs/types/ts-to-chart-event.types.d.ts.map +0 -1
  156. package/cjs/types/ts-to-chart-event.types.js +0 -18
  157. package/cjs/types/ts-to-chart-event.types.js.map +0 -1
  158. package/cjs/types/visual-prop.types.d.ts +0 -73
  159. package/cjs/types/visual-prop.types.d.ts.map +0 -1
  160. package/cjs/types/visual-prop.types.js +0 -3
  161. package/cjs/types/visual-prop.types.js.map +0 -1
  162. package/lib/dist/ts-chart-sdk.d.ts +0 -312
  163. package/lib/react/custom-chart-context-service.d.ts +0 -33
  164. package/lib/react/custom-chart-context-service.d.ts.map +0 -1
  165. package/lib/react/custom-chart-context-service.js +0 -91
  166. package/lib/react/custom-chart-context-service.js.map +0 -1
  167. package/lib/react/custom-chart.context.d.ts +0 -26
  168. package/lib/react/custom-chart.context.d.ts.map +0 -1
  169. package/lib/react/custom-chart.context.js +0 -78
  170. package/lib/react/custom-chart.context.js.map +0 -1
  171. package/lib/react/custom-chart.spec.d.ts +0 -2
  172. package/lib/react/custom-chart.spec.d.ts.map +0 -1
  173. package/lib/react/custom-chart.spec.js +0 -67
  174. package/lib/react/custom-chart.spec.js.map +0 -1
@@ -3,18 +3,20 @@ import { renderHook } from '@testing-library/react-hooks';
3
3
  import React from 'react';
4
4
  import * as PostMessageEventBridge from '../main/post-message-event-bridge';
5
5
  import { mockInitializeContextPayload } from '../test/test-utils';
6
+ import { ColumnType } from '../types/answer-column.types';
6
7
  import { ChartToTSEvent } from '../types/chart-to-ts-event.types';
7
8
  import { TSToChartEvent } from '../types/ts-to-chart-event.types';
8
9
  import { contextChartProps } from './mocks/custom-chart-context-mock';
9
10
  import { useChartContext } from './use-custom-chart-context';
10
11
 
11
- jest.mock('../main/post-message-event-bridge');
12
-
13
12
  describe('useChartContext initialization', () => {
14
13
  let eventProcessor: any;
15
14
  let mockInitMessage;
16
15
  let mockPostMessageToHost;
17
- const mockedChartModel = { columns: [], config: {} };
16
+ const mockedChartModel = {
17
+ columns: [{ type: ColumnType.MEASURE }, { type: ColumnType.ATTRIBUTE }],
18
+ config: {},
19
+ };
18
20
  beforeEach(() => {
19
21
  mockInitMessage = jest.spyOn(
20
22
  PostMessageEventBridge,
@@ -26,6 +28,7 @@ describe('useChartContext initialization', () => {
26
28
  );
27
29
  mockInitMessage.mockImplementation((fn: any) => {
28
30
  eventProcessor = fn;
31
+ return () => null;
29
32
  });
30
33
 
31
34
  mockPostMessageToHost.mockImplementation(() => {
@@ -35,6 +38,7 @@ describe('useChartContext initialization', () => {
35
38
  afterEach(() => {
36
39
  // Clear mock implementations after each test
37
40
  jest.clearAllMocks();
41
+ PostMessageEventBridge.globalThis.isInitialized = false;
38
42
  });
39
43
 
40
44
  test('should initialize the context only after intialize completes', async () => {
@@ -47,32 +51,84 @@ describe('useChartContext initialization', () => {
47
51
  expect(result.current.hasInitialized).toBe(false);
48
52
  expect(result.current.chartModel).toBeUndefined();
49
53
  const mockPostMessage = jest.fn();
50
- eventProcessor({
51
- data: {
52
- payload: {
53
- componentId: 'COMPONENT_ID',
54
- hostUrl: 'https://some.chart.app',
55
- chartModel: mockedChartModel,
56
- },
57
- eventType: TSToChartEvent.Initialize,
58
- source: 'ts-host-app',
54
+ await eventProcessor({
55
+ payload: {
56
+ componentId: 'COMPONENT_ID',
57
+ hostUrl: 'https://some.chart.app',
58
+ chartModel: mockedChartModel,
59
59
  },
60
- ports: [{ postMessage: mockPostMessage }],
60
+ eventType: TSToChartEvent.Initialize,
61
61
  });
62
-
63
- eventProcessor({
64
- data: {
65
- payload: {},
66
- eventType: TSToChartEvent.InitializeComplete,
67
- source: 'ts-host-app',
68
- },
69
- ports: [{ postMessage: mockPostMessage }],
62
+ await eventProcessor({
63
+ payload: {},
64
+ eventType: TSToChartEvent.InitializeComplete,
65
+ source: 'ts-host-app',
70
66
  });
67
+
71
68
  await waitFor(() => {
72
69
  expect(result.current.hasInitialized).toBe(true);
73
70
  expect(result.current.chartModel).toEqual(mockedChartModel);
74
71
  });
75
- result.current?.destroy();
72
+ });
73
+
74
+ test('should trigger getDataQuery and fetch correct query response', async () => {
75
+ // Render the hook with the custom chart context props
76
+ const { result, waitFor } = renderHook(() =>
77
+ useChartContext(contextChartProps),
78
+ );
79
+
80
+ // Assert that the context is not initialized initially
81
+ expect(result.current.hasInitialized).toBe(false);
82
+ expect(result.current.chartModel).toBeUndefined();
83
+ await eventProcessor({
84
+ payload: {
85
+ componentId: 'COMPONENT_ID',
86
+ hostUrl: 'https://some.chart.app',
87
+ chartModel: mockedChartModel,
88
+ },
89
+ eventType: TSToChartEvent.Initialize,
90
+ });
91
+ const response = await eventProcessor({
92
+ payload: {
93
+ config: [
94
+ {
95
+ key: 'column',
96
+ dimensions: [
97
+ {
98
+ key: 'x',
99
+ columns: [mockedChartModel.columns[0]],
100
+ },
101
+ {
102
+ key: 'y',
103
+ columns: [mockedChartModel.columns[1]],
104
+ },
105
+ ],
106
+ },
107
+ ],
108
+ },
109
+ eventType: TSToChartEvent.GetDataQuery,
110
+ source: 'ts-host-app',
111
+ });
112
+ await eventProcessor({
113
+ payload: {},
114
+ eventType: TSToChartEvent.TriggerRenderChart,
115
+ source: 'ts-host-app',
116
+ });
117
+ await eventProcessor({
118
+ payload: {},
119
+ eventType: TSToChartEvent.InitializeComplete,
120
+ source: 'ts-host-app',
121
+ });
122
+
123
+ await waitFor(() => {
124
+ expect(response.queries[0].queryColumns[0]).toBe(
125
+ mockedChartModel.columns[0],
126
+ );
127
+ expect(response.queries[0].queryColumns[1]).toBe(
128
+ mockedChartModel.columns[1],
129
+ );
130
+ expect(result.current.hasInitialized).toBeTruthy();
131
+ });
76
132
  });
77
133
 
78
134
  test('should make sure hasInitialized to remain false when context initialization failed', async () => {
@@ -84,7 +140,6 @@ describe('useChartContext initialization', () => {
84
140
  emitEvent: jest.fn(),
85
141
  on: jest.fn(),
86
142
  getChartModel: jest.fn(),
87
- renderChart: jest.fn(),
88
143
  destroy: jest.fn(),
89
144
  })),
90
145
  }));
@@ -117,6 +172,7 @@ describe('useChartContext emit', () => {
117
172
  );
118
173
  mockInitMessage.mockImplementation((fn: any) => {
119
174
  eventProcessor = fn;
175
+ return () => null;
120
176
  });
121
177
 
122
178
  mockPostMessageToHost.mockImplementation(() => {
@@ -126,6 +182,7 @@ describe('useChartContext emit', () => {
126
182
  afterEach(() => {
127
183
  // Clear mock implementations after each test
128
184
  jest.clearAllMocks();
185
+ PostMessageEventBridge.globalThis.isInitialized = false;
129
186
  });
130
187
 
131
188
  test('should trigger the emitter correctly when context is initialized', async () => {
@@ -134,23 +191,17 @@ describe('useChartContext emit', () => {
134
191
  useChartContext(contextChartProps),
135
192
  );
136
193
  const mockPostMessage = jest.fn();
137
- eventProcessor({
138
- data: {
139
- payload: mockInitializeContextPayload,
140
- eventType: TSToChartEvent.Initialize,
141
- source: 'ts-host-app',
142
- },
143
- ports: [{ postMessage: mockPostMessage }],
194
+ await eventProcessor({
195
+ payload: mockInitializeContextPayload,
196
+ eventType: TSToChartEvent.Initialize,
144
197
  });
145
198
 
146
- eventProcessor({
147
- data: {
148
- payload: {},
149
- eventType: TSToChartEvent.InitializeComplete,
150
- source: 'ts-host-app',
151
- },
152
- ports: [{ postMessage: mockPostMessage }],
199
+ await eventProcessor({
200
+ payload: {},
201
+ eventType: TSToChartEvent.InitializeComplete,
202
+ source: 'ts-host-app',
153
203
  });
204
+
154
205
  await waitFor(() => {
155
206
  expect(result.current.hasInitialized).toBe(true);
156
207
  });
@@ -174,14 +225,12 @@ describe('useChartContext emit', () => {
174
225
  useChartContext(contextChartProps),
175
226
  );
176
227
  const mockPostMessage = jest.fn();
177
- eventProcessor({
178
- data: {
179
- payload: mockInitializeContextPayload,
180
- eventType: TSToChartEvent.Initialize,
181
- source: 'ts-host-app',
182
- },
183
- ports: [{ postMessage: mockPostMessage }],
228
+ await eventProcessor({
229
+ payload: mockInitializeContextPayload,
230
+ eventType: TSToChartEvent.Initialize,
231
+ source: 'ts-host-app',
184
232
  });
233
+
185
234
  await waitFor(() => {
186
235
  expect(result.current.hasInitialized).toBe(false);
187
236
  });
@@ -207,6 +256,7 @@ describe('useChartContext setOn listeners', () => {
207
256
  );
208
257
  mockInitMessage.mockImplementation((fn: any) => {
209
258
  eventProcessor = fn;
259
+ return () => null;
210
260
  });
211
261
 
212
262
  mockPostMessageToHost.mockImplementation(() => {
@@ -216,6 +266,7 @@ describe('useChartContext setOn listeners', () => {
216
266
  afterEach(() => {
217
267
  // Clear mock implementations after each test
218
268
  jest.clearAllMocks();
269
+ PostMessageEventBridge.globalThis.isInitialized = false;
219
270
  });
220
271
 
221
272
  test('should trigger the setOnEvent correctly when context is initialized', async () => {
@@ -227,63 +278,49 @@ describe('useChartContext setOn listeners', () => {
227
278
  // Assert that the context is not initialized initially
228
279
  expect(result.current.hasInitialized).toBe(false);
229
280
  expect(result.current.chartModel).toBeUndefined();
230
- const mockPostMessage = jest.fn();
231
- eventProcessor({
232
- data: {
233
- payload: {
234
- componentId: 'COMPONENT_ID',
235
- hostUrl: 'https://some.chart.app',
236
- chartModel: mockedChartModel,
237
- },
238
- eventType: TSToChartEvent.Initialize,
239
- source: 'ts-host-app',
281
+ await eventProcessor({
282
+ payload: {
283
+ componentId: 'COMPONENT_ID',
284
+ hostUrl: 'https://some.chart.app',
285
+ chartModel: mockedChartModel,
240
286
  },
241
- ports: [{ postMessage: mockPostMessage }],
287
+ eventType: TSToChartEvent.Initialize,
242
288
  });
243
289
 
244
- eventProcessor({
245
- data: {
246
- payload: {},
247
- eventType: TSToChartEvent.InitializeComplete,
248
- source: 'ts-host-app',
249
- },
250
- ports: [{ postMessage: mockPostMessage }],
290
+ await eventProcessor({
291
+ payload: {},
292
+ eventType: TSToChartEvent.InitializeComplete,
293
+ source: 'ts-host-app',
251
294
  });
295
+
252
296
  await waitFor(() => {
253
297
  expect(result.current.hasInitialized).toBe(true);
254
298
  expect(result.current.chartModel).toEqual(mockedChartModel);
255
299
  });
256
300
 
257
- eventProcessor({
258
- data: {
259
- payload: { chartModel: {} },
260
- eventType: TSToChartEvent.ChartModelUpdate,
261
- source: 'ts-host-app',
262
- },
263
- ports: [{ postMessage: mockPostMessage }],
301
+ const resp = await eventProcessor({
302
+ payload: { chartModel: {} },
303
+ eventType: TSToChartEvent.ChartModelUpdate,
304
+ source: 'ts-host-app',
264
305
  });
306
+
265
307
  await waitFor(() => {
266
- expect(mockPostMessage).toHaveBeenCalledWith({
308
+ expect(resp).toEqual({
267
309
  triggerRenderChart: true,
268
310
  });
269
311
  expect(result.current.chartModel).toEqual({});
270
312
  });
271
313
 
272
- eventProcessor({
273
- data: {
274
- payload: { visualProps: { color: 'red' } },
275
- eventType: TSToChartEvent.VisualPropsUpdate,
276
- source: 'ts-host-app',
277
- },
278
- ports: [{ postMessage: mockPostMessage }],
314
+ const propsUpdateResp = await eventProcessor({
315
+ payload: { visualProps: { color: 'red' } },
316
+ eventType: TSToChartEvent.VisualPropsUpdate,
317
+ source: 'ts-host-app',
279
318
  });
280
- expect(mockPostMessage).toHaveBeenCalledWith({
319
+
320
+ expect(propsUpdateResp).toEqual({
281
321
  triggerRenderChart: true,
282
322
  });
283
323
  await waitFor(() => {
284
- expect(mockPostMessage).toHaveBeenCalledWith({
285
- triggerRenderChart: true,
286
- });
287
324
  expect(result.current.chartModel?.visualProps).toEqual({
288
325
  color: 'red',
289
326
  });
@@ -297,14 +334,12 @@ describe('useChartContext setOn listeners', () => {
297
334
  useChartContext(contextChartProps),
298
335
  );
299
336
  const mockPostMessage = jest.fn();
300
- eventProcessor({
301
- data: {
302
- payload: mockInitializeContextPayload,
303
- eventType: TSToChartEvent.Initialize,
304
- source: 'ts-host-app',
305
- },
306
- ports: [{ postMessage: mockPostMessage }],
337
+ await eventProcessor({
338
+ payload: mockInitializeContextPayload,
339
+ eventType: TSToChartEvent.Initialize,
340
+ source: 'ts-host-app',
307
341
  });
342
+
308
343
  await waitFor(() => {
309
344
  expect(result.current.hasInitialized).toBe(false);
310
345
  });
@@ -333,6 +368,7 @@ describe('useChartContext on React Wrapper component', () => {
333
368
  );
334
369
  mockInitMessage.mockImplementation((fn: any) => {
335
370
  eventProcessor = fn;
371
+ return () => null;
336
372
  });
337
373
 
338
374
  mockPostMessageToHost.mockImplementation(() => {
@@ -342,6 +378,7 @@ describe('useChartContext on React Wrapper component', () => {
342
378
  afterEach(() => {
343
379
  // Clear mock implementations after each test
344
380
  jest.clearAllMocks();
381
+ PostMessageEventBridge.globalThis.isInitialized = false;
345
382
  });
346
383
  test('TSChartContext renders children and should not increase counter for useEffect on chartModel if visualProps is updated', async () => {
347
384
  const CustomChartComponent = () => {
@@ -364,18 +401,15 @@ describe('useChartContext on React Wrapper component', () => {
364
401
  const { getByTestId, rerender } = render(<CustomChartComponent />);
365
402
 
366
403
  const mockPostMessage = jest.fn();
367
- eventProcessor({
368
- data: {
369
- payload: {
370
- componentId: 'COMPONENT_ID',
371
- hostUrl: 'https://some.chart.app',
372
- chartModel: mockedChartModel,
373
- },
374
- eventType: TSToChartEvent.Initialize,
375
- source: 'ts-host-app',
404
+ await eventProcessor({
405
+ payload: {
406
+ componentId: 'COMPONENT_ID',
407
+ hostUrl: 'https://some.chart.app',
408
+ chartModel: mockedChartModel,
376
409
  },
377
- ports: [{ postMessage: mockPostMessage }],
410
+ eventType: TSToChartEvent.Initialize,
378
411
  });
412
+
379
413
  rerender(<CustomChartComponent />);
380
414
 
381
415
  // Check if the child element is rendered
@@ -385,13 +419,10 @@ describe('useChartContext on React Wrapper component', () => {
385
419
  );
386
420
  });
387
421
 
388
- eventProcessor({
389
- data: {
390
- payload: { visualProps: { color: 'red' } },
391
- eventType: TSToChartEvent.VisualPropsUpdate,
392
- source: 'ts-host-app',
393
- },
394
- ports: [{ postMessage: mockPostMessage }],
422
+ await eventProcessor({
423
+ payload: { visualProps: { color: 'red' } },
424
+ eventType: TSToChartEvent.VisualPropsUpdate,
425
+ source: 'ts-host-app',
395
426
  });
396
427
 
397
428
  // Re-render the component with a new key
@@ -432,26 +463,22 @@ describe('useChartContext on React Wrapper component', () => {
432
463
 
433
464
  // Re-render the component with a new key
434
465
  const mockPostMessage = jest.fn();
435
- eventProcessor({
436
- data: {
437
- payload: {
438
- componentId: 'COMPONENT_ID',
439
- hostUrl: 'https://some.chart.app',
440
- chartModel: mockedChartModel,
441
- },
442
- eventType: TSToChartEvent.Initialize,
443
- source: 'ts-host-app',
466
+ await eventProcessor({
467
+ payload: {
468
+ componentId: 'COMPONENT_ID',
469
+ hostUrl: 'https://some.chart.app',
470
+ chartModel: mockedChartModel,
444
471
  },
445
- ports: [{ postMessage: mockPostMessage }],
472
+ eventType: TSToChartEvent.Initialize,
473
+ source: 'ts-host-app',
446
474
  });
447
- eventProcessor({
448
- data: {
449
- payload: { visualProps: { color: 'red' } },
450
- eventType: TSToChartEvent.VisualPropsUpdate,
451
- source: 'ts-host-app',
452
- },
453
- ports: [{ postMessage: mockPostMessage }],
475
+
476
+ await eventProcessor({
477
+ payload: { visualProps: { color: 'red' } },
478
+ eventType: TSToChartEvent.VisualPropsUpdate,
479
+ source: 'ts-host-app',
454
480
  });
481
+
455
482
  rerender(<CustomChartComponent />);
456
483
  // Check if the child element is still in the document after re-render
457
484
  const updatedChildElement = getByTestId('child-element');
@@ -0,0 +1,95 @@
1
+ /**
2
+ * @file: Test Conditional Formatting Utils
3
+ *
4
+ * @author Yashvardhan Nehra <yashvardhan.nehra@thoughtspot.com>
5
+ *
6
+ * Copyright: ThoughtSpot Inc. 2023
7
+ */
8
+ import {
9
+ BackgroundFormatTypes,
10
+ ConditionalFormattingComparisonTypes,
11
+ ConditionalMetric,
12
+ Operators,
13
+ } from '../types/conditional-formatting.types';
14
+
15
+ /**
16
+ * Creates a metric operator for conditional formatting.
17
+ *
18
+ * @param operator - The operator to use for the metric (e.g., LessThan, GreaterThan).
19
+ * @param lhsColumnId - (Optional) The ID of the left-hand side column.
20
+ * @param rhsColumnId - (Optional) The ID of the right-hand side column.
21
+ * @param comparisonParameterId - (Optional) The ID of the comparison parameter.
22
+ * @param comparisonType - The type of comparison to use (default is ValueBased).
23
+ * @returns A ConditionalMetric object configured with the specified parameters.
24
+ */
25
+ export const createMetricOperator = (
26
+ operator: Operators,
27
+ lhsColumnId?: string,
28
+ rhsColumnId?: string,
29
+ comparisonParameterId?: string,
30
+ comparisonType = ConditionalFormattingComparisonTypes.ValueBased,
31
+ ): ConditionalMetric => {
32
+ return {
33
+ solidBackgroundAttrs: {
34
+ color: '#000',
35
+ },
36
+ backgroundFormatType: 'SOLID' as BackgroundFormatTypes,
37
+ operator,
38
+ value: '200',
39
+ plotAsBand: false,
40
+ comparisonParameterId,
41
+ comparisonType,
42
+ lhsColumnId,
43
+ rhsColumnId,
44
+ };
45
+ };
46
+
47
+ /**
48
+ * Creates a between metric operator for conditional formatting.
49
+ *
50
+ * @param operator - The operator to use for the metric (e.g., IsBetween).
51
+ * @param min - The minimum value for the range (default is 100).
52
+ * @param max - The maximum value for the range (default is 200).
53
+ * @returns A ConditionalMetric object configured with the specified parameters.
54
+ */
55
+ export const createBetweenMetricOperator = (
56
+ operator: Operators,
57
+ min = 100,
58
+ max = 200,
59
+ ): ConditionalMetric => {
60
+ return {
61
+ backgroundFormatType: 'SOLID' as BackgroundFormatTypes,
62
+ solidBackgroundAttrs: {
63
+ color: '#000',
64
+ },
65
+ operator,
66
+ rangeValues: {
67
+ min,
68
+ max,
69
+ },
70
+ plotAsBand: false,
71
+ lhsColumnId: undefined,
72
+ rhsColumnId: undefined,
73
+ comparisonParameterId: undefined,
74
+ comparisonType: ConditionalFormattingComparisonTypes.ValueBased,
75
+ };
76
+ };
77
+
78
+ /**
79
+ * Creates an attribute operator for conditional formatting.
80
+ *
81
+ * @param operator - The operator to use for the attribute (e.g., Is, IsNot).
82
+ * @param comparisonType - (Optional) The type of comparison to use.
83
+ * @returns A ConditionalMetric object configured with the specified parameters.
84
+ */
85
+ export const createAttributeOperator = (
86
+ operator: Operators,
87
+ comparisonType?: ConditionalFormattingComparisonTypes,
88
+ ): ConditionalMetric => {
89
+ return {
90
+ backgroundFormatType: 'SOLID' as BackgroundFormatTypes,
91
+ operator,
92
+ value: 'check attribute',
93
+ comparisonType,
94
+ };
95
+ };
@@ -1,7 +1,21 @@
1
+ import { ConditionalFormatting, Maybe } from './conditional-formatting.types';
2
+
1
3
  export enum ColumnType {
2
4
  UNKNOWN,
3
5
  MEASURE,
4
6
  ATTRIBUTE,
7
+ // Virtual columns that are measure name/value columns
8
+ VIRTUAL,
9
+ }
10
+
11
+ /**
12
+ * When the column is generated for the chart for creating views,
13
+ * on top of measure columns from the worksheet which are part of answer query.
14
+ */
15
+ export enum ChartSpecificColumnType {
16
+ UNKNOWN,
17
+ MEASURE_NAMES,
18
+ MEASURE_VALUES,
5
19
  }
6
20
 
7
21
  /**
@@ -71,6 +85,51 @@ export enum CurrencyFormatType {
71
85
  ISO_CODE,
72
86
  }
73
87
 
88
+ /**
89
+ * Type of aggregations applied on the column data
90
+ *
91
+ * @version SDK: 0.1 | ThoughtSpot:
92
+ */
93
+ export enum ColumnAggregationType {
94
+ AGGREGATE,
95
+ AGGREGATE_DISTINCT,
96
+ APPROX_AGGR_DISTINCT,
97
+ APPROX_AGGR_DISTINCT_MERGE,
98
+ APPROX_COUNT_DISTINCT,
99
+ AVERAGE,
100
+ COUNT,
101
+ COUNT_DISTINCT,
102
+ CUMULATIVE_AVERAGE,
103
+ CUMULATIVE_COUNT,
104
+ CUMULATIVE_MAX,
105
+ CUMULATIVE_MIN,
106
+ CUMULATIVE_SUM,
107
+ GROWTH,
108
+ MAX,
109
+ MEDIAN,
110
+ MIN,
111
+ MOVING_AVERAGE,
112
+ MOVING_COUNT,
113
+ MOVING_MAX,
114
+ MOVING_MIN,
115
+ MOVING_SUM,
116
+ NONE,
117
+ PERCENTILE,
118
+ RANK,
119
+ RANK_PERCENTILE,
120
+ SQL_BOOL_AGGREGATE_OP,
121
+ SQL_DATE_AGGREGATE_OP,
122
+ SQL_DATE_TIME_AGGREGATE_OP,
123
+ SQL_DOUBLE_AGGREGATE_OP,
124
+ SQL_INT_AGGREGATE_OP,
125
+ SQL_STRING_AGGREGATE_OP,
126
+ SQL_TIME_AGGREGATE_OP,
127
+ STD_DEVIATION,
128
+ SUM,
129
+ TABLE_AGGR,
130
+ VARIANCE,
131
+ }
132
+
74
133
  /**
75
134
  * Currency format for the column defined in the worksheet
76
135
  *
@@ -171,4 +230,43 @@ export interface ChartColumn {
171
230
  * @version SDK: 0.1 | ThoughtSpot:
172
231
  */
173
232
  format?: ColumnFormat;
233
+
234
+ /**
235
+ * Column Properties of the columns
236
+ *
237
+ * @version SDK: 0.1 | ThoughtSpot:
238
+ */
239
+ columnProperties?: {
240
+ conditionalFormatting?: Maybe<ConditionalFormatting>;
241
+ };
242
+
243
+ /**
244
+ * Aggregation applied on the column data
245
+ *
246
+ * @version SDK: 0.1 | ThoughtSpot:
247
+ */
248
+ aggregationType?: ColumnAggregationType;
249
+
250
+ /**
251
+ * Custom sort order defined for the column to sort charts in a specific order
252
+ * Defined in worksheet
253
+ *
254
+ * @version SDK: 0.1 | ThoughtSpot:
255
+ */
256
+ customOrder?: Array<string>;
257
+
258
+ /**
259
+ * Guid of Custom calender for the column if defined in worksheet else null
260
+ *
261
+ * @version SDK: 0.1 | ThoughtSpot: sdcwdc
262
+ */
263
+ calenderGuid?: string;
264
+
265
+ /**
266
+ * Type of arbitrary column, can be measure names or measure values
267
+ * also, unknown if regular column
268
+ *
269
+ * @version SDK: 0.1 | ThoughtSpot:
270
+ */
271
+ chartSpecificColumnType: ChartSpecificColumnType;
174
272
  }