@thoughtspot/ts-chart-sdk 0.0.2-alpha.8 → 1.0.0
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.
- package/README.md +126 -50
- package/dist/ts-chart-sdk.d.ts +337 -31
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/main/custom-chart-context.d.ts +15 -3
- package/lib/main/custom-chart-context.d.ts.map +1 -1
- package/lib/main/custom-chart-context.js +45 -16
- package/lib/main/custom-chart-context.js.map +1 -1
- package/lib/main/custom-chart-context.spec.js +302 -4
- package/lib/main/custom-chart-context.spec.js.map +1 -1
- package/lib/main/logger.d.ts +13 -0
- package/lib/main/logger.d.ts.map +1 -0
- package/lib/main/logger.js +64 -0
- package/lib/main/logger.js.map +1 -0
- package/lib/main/logger.spec.d.ts +2 -0
- package/lib/main/logger.spec.d.ts.map +1 -0
- package/lib/main/logger.spec.js +88 -0
- package/lib/main/logger.spec.js.map +1 -0
- package/lib/main/util.d.ts +2 -0
- package/lib/main/util.d.ts.map +1 -1
- package/lib/main/util.js +11 -0
- package/lib/main/util.js.map +1 -1
- package/lib/main/util.spec.d.ts +2 -0
- package/lib/main/util.spec.d.ts.map +1 -0
- package/lib/main/util.spec.js +73 -0
- package/lib/main/util.spec.js.map +1 -0
- package/lib/react/use-custom-chart-context.d.ts.map +1 -1
- package/lib/react/use-custom-chart-context.js +3 -1
- package/lib/react/use-custom-chart-context.js.map +1 -1
- package/lib/react/use-custom-chart-context.spec.js +0 -1
- package/lib/react/use-custom-chart-context.spec.js.map +1 -1
- package/lib/react/use-custom-chart-context.util.d.ts.map +1 -1
- package/lib/react/use-custom-chart-context.util.js +5 -3
- package/lib/react/use-custom-chart-context.util.js.map +1 -1
- package/lib/types/answer-column.types.d.ts +15 -5
- package/lib/types/answer-column.types.d.ts.map +1 -1
- package/lib/types/answer-column.types.js +10 -3
- package/lib/types/answer-column.types.js.map +1 -1
- package/lib/types/chart-to-ts-event.types.d.ts +2 -0
- package/lib/types/chart-to-ts-event.types.d.ts.map +1 -1
- package/lib/types/chart-to-ts-event.types.js +1 -0
- package/lib/types/chart-to-ts-event.types.js.map +1 -1
- package/lib/types/common.types.d.ts +65 -5
- package/lib/types/common.types.d.ts.map +1 -1
- package/lib/types/common.types.js.map +1 -1
- package/lib/types/conditional-formatting.types.d.ts +1 -16
- package/lib/types/conditional-formatting.types.d.ts.map +1 -1
- package/lib/types/conditional-formatting.types.js.map +1 -1
- package/lib/types/configurator.types.d.ts +3 -1
- package/lib/types/configurator.types.d.ts.map +1 -1
- package/lib/types/number-formatting.types.d.ts +55 -0
- package/lib/types/number-formatting.types.d.ts.map +1 -0
- package/lib/types/number-formatting.types.js +23 -0
- package/lib/types/number-formatting.types.js.map +1 -0
- package/lib/types/ts-to-chart-event.types.d.ts +19 -6
- package/lib/types/ts-to-chart-event.types.d.ts.map +1 -1
- package/lib/types/ts-to-chart-event.types.js +1 -0
- package/lib/types/ts-to-chart-event.types.js.map +1 -1
- package/lib/types/visual-prop.types.d.ts +71 -3
- package/lib/types/visual-prop.types.d.ts.map +1 -1
- package/lib/types/visual-prop.types.js +32 -1
- package/lib/types/visual-prop.types.js.map +1 -1
- package/lib/utils/conditional-formatting/conditional-formatting.spec.js +2 -1
- package/lib/utils/conditional-formatting/conditional-formatting.spec.js.map +1 -1
- package/lib/utils/date-formatting.d.ts +85 -1
- package/lib/utils/date-formatting.d.ts.map +1 -1
- package/lib/utils/date-formatting.js +344 -9
- package/lib/utils/date-formatting.js.map +1 -1
- package/lib/utils/date-formatting.spec.js +303 -32
- package/lib/utils/date-formatting.spec.js.map +1 -1
- package/lib/utils/date-utils.d.ts +6 -0
- package/lib/utils/date-utils.d.ts.map +1 -0
- package/lib/utils/date-utils.js +20 -0
- package/lib/utils/date-utils.js.map +1 -0
- package/lib/utils/date-utils.spec.d.ts +2 -0
- package/lib/utils/date-utils.spec.d.ts.map +1 -0
- package/lib/utils/date-utils.spec.js +63 -0
- package/lib/utils/date-utils.spec.js.map +1 -0
- package/lib/utils/formatting-util.d.ts +10 -0
- package/lib/utils/formatting-util.d.ts.map +1 -0
- package/lib/utils/formatting-util.js +78 -0
- package/lib/utils/formatting-util.js.map +1 -0
- package/lib/utils/formatting-util.spec.d.ts +2 -0
- package/lib/utils/formatting-util.spec.d.ts.map +1 -0
- package/lib/utils/formatting-util.spec.js +247 -0
- package/lib/utils/formatting-util.spec.js.map +1 -0
- package/lib/utils/globalize-Initializer/globalize-utils.d.ts +16 -0
- package/lib/utils/globalize-Initializer/globalize-utils.d.ts.map +1 -0
- package/lib/utils/globalize-Initializer/globalize-utils.js +101 -0
- package/lib/utils/globalize-Initializer/globalize-utils.js.map +1 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.d.ts +2 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.d.ts.map +1 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.js +149 -0
- package/lib/utils/globalize-Initializer/globalize-utils.spec.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.d.ts +20 -0
- package/lib/utils/number-formatting/number-formatting-utils.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.js +159 -0
- package/lib/utils/number-formatting/number-formatting-utils.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.d.ts +2 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.js +221 -0
- package/lib/utils/number-formatting/number-formatting-utils.spec.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting.d.ts +5 -0
- package/lib/utils/number-formatting/number-formatting.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting.js +128 -0
- package/lib/utils/number-formatting/number-formatting.js.map +1 -0
- package/lib/utils/number-formatting/number-formatting.spec.d.ts +2 -0
- package/lib/utils/number-formatting/number-formatting.spec.d.ts.map +1 -0
- package/lib/utils/number-formatting/number-formatting.spec.js +159 -0
- package/lib/utils/number-formatting/number-formatting.spec.js.map +1 -0
- package/package.json +5 -2
- package/src/index.ts +3 -0
- package/src/main/custom-chart-context.spec.ts +356 -6
- package/src/main/custom-chart-context.ts +182 -15
- package/src/main/logger.spec.ts +114 -0
- package/src/main/logger.ts +97 -0
- package/src/main/util.spec.ts +94 -0
- package/src/main/util.ts +20 -0
- package/src/react/use-custom-chart-context.spec.tsx +0 -1
- package/src/react/use-custom-chart-context.tsx +4 -1
- package/src/react/use-custom-chart-context.util.ts +6 -3
- package/src/types/answer-column.types.ts +29 -6
- package/src/types/chart-to-ts-event.types.ts +7 -0
- package/src/types/common.types.ts +103 -8
- package/src/types/conditional-formatting.types.ts +2 -17
- package/src/types/configurator.types.ts +15 -1
- package/src/types/number-formatting.types.ts +80 -0
- package/src/types/ts-to-chart-event.types.ts +54 -5
- package/src/types/visual-prop.types.ts +197 -3
- package/src/utils/conditional-formatting/conditional-formatting.spec.ts +2 -0
- package/src/utils/date-formatting.spec.ts +377 -32
- package/src/utils/date-formatting.ts +587 -14
- package/src/utils/date-utils.spec.ts +93 -0
- package/src/utils/date-utils.ts +69 -0
- package/src/utils/formatting-util.spec.ts +312 -0
- package/src/utils/formatting-util.ts +234 -0
- package/src/utils/globalize-Initializer/globalize-utils.spec.ts +192 -0
- package/src/utils/globalize-Initializer/globalize-utils.ts +216 -0
- package/src/utils/number-formatting/number-formatting-utils.spec.ts +296 -0
- package/src/utils/number-formatting/number-formatting-utils.ts +260 -0
- package/src/utils/number-formatting/number-formatting.spec.ts +243 -0
- package/src/utils/number-formatting/number-formatting.ts +264 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ChartColumn, ColumnTimeBucket } from '../types/answer-column.types';
|
|
2
|
+
import {
|
|
3
|
+
getCustomCalendarGuid,
|
|
4
|
+
getFormatPatternForBucket,
|
|
5
|
+
showDateFinancialYearFormat,
|
|
6
|
+
} from './date-utils';
|
|
7
|
+
|
|
8
|
+
describe('getFormatPatternForBucket', () => {
|
|
9
|
+
const mockDatasourceIdToCustomCalendarMap = {
|
|
10
|
+
datasource1: {
|
|
11
|
+
fiscal: 'guid-123',
|
|
12
|
+
custom: 'guid-456',
|
|
13
|
+
},
|
|
14
|
+
datasource2: {
|
|
15
|
+
fiscal: 'guid-789',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
test('should return correct format pattern for YEARLY bucket', () => {
|
|
20
|
+
const result = getFormatPatternForBucket(ColumnTimeBucket.YEARLY);
|
|
21
|
+
expect(result).toBe('yyyy');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('should return correct format pattern for MONTHLY bucket', () => {
|
|
25
|
+
const result = getFormatPatternForBucket(ColumnTimeBucket.MONTHLY);
|
|
26
|
+
expect(result).toBe('MONTH_WITH_YEAR');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should return correct format pattern for WEEKLY bucket', () => {
|
|
30
|
+
const result = getFormatPatternForBucket(ColumnTimeBucket.WEEKLY);
|
|
31
|
+
expect(result).toBe('DATE_SHORT');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('should handle undefined input gracefully', () => {
|
|
35
|
+
const result = getFormatPatternForBucket(undefined as any);
|
|
36
|
+
expect(result).toBeUndefined();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should return true for QUARTERLY time bucket', () => {
|
|
40
|
+
const col = { timeBucket: ColumnTimeBucket.QUARTERLY } as ChartColumn;
|
|
41
|
+
const result = showDateFinancialYearFormat(col);
|
|
42
|
+
|
|
43
|
+
expect(result).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('should return true for YEARLY time bucket', () => {
|
|
47
|
+
const col = { timeBucket: ColumnTimeBucket.YEARLY } as ChartColumn;
|
|
48
|
+
const result = showDateFinancialYearFormat(col);
|
|
49
|
+
expect(result).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('should return true for MONTLY time bucket', () => {
|
|
53
|
+
const col = { timeBucket: ColumnTimeBucket.MONTHLY } as ChartColumn;
|
|
54
|
+
const result = showDateFinancialYearFormat(col);
|
|
55
|
+
expect(result).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
test('should return the custom calendar GUID when datasourceId and name are valid', () => {
|
|
58
|
+
const datasourceId = 'datasource1';
|
|
59
|
+
const name = 'fiscal';
|
|
60
|
+
|
|
61
|
+
const result = getCustomCalendarGuid(
|
|
62
|
+
name,
|
|
63
|
+
datasourceId,
|
|
64
|
+
mockDatasourceIdToCustomCalendarMap,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(result).toBe('guid-123');
|
|
68
|
+
});
|
|
69
|
+
test('should return undefined when the datasourceId is valid but the name does not exist', () => {
|
|
70
|
+
const datasourceId = 'datasource1';
|
|
71
|
+
const name = 'nonexistent';
|
|
72
|
+
|
|
73
|
+
const result = getCustomCalendarGuid(
|
|
74
|
+
name,
|
|
75
|
+
datasourceId,
|
|
76
|
+
mockDatasourceIdToCustomCalendarMap,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(result).toBeUndefined();
|
|
80
|
+
});
|
|
81
|
+
test('should return undefined when the datasourceId does not exist in the map', () => {
|
|
82
|
+
const datasourceId = 'nonexistentDatasource';
|
|
83
|
+
const name = 'fiscal';
|
|
84
|
+
|
|
85
|
+
const result = getCustomCalendarGuid(
|
|
86
|
+
name,
|
|
87
|
+
datasourceId,
|
|
88
|
+
mockDatasourceIdToCustomCalendarMap,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(result).toBeUndefined();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { ChartColumn, ColumnTimeBucket } from '../types/answer-column.types';
|
|
3
|
+
import { bucketizationToDatePreset, timeBuckets } from './date-formatting';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves the date format pattern associated with a specific time bucket.
|
|
7
|
+
*
|
|
8
|
+
* This function maps a `ColumnTimeBucket` value to its corresponding date format
|
|
9
|
+
* pattern using a predefined configuration (`bucketizationToDatePreset`). It is used
|
|
10
|
+
* to ensure that date formatting aligns with the granularity defined by the bucket type.
|
|
11
|
+
*
|
|
12
|
+
* @param bucket - The time bucket (`ColumnTimeBucket`) for which the format pattern is needed.
|
|
13
|
+
*
|
|
14
|
+
* @returns The date format pattern associated with the provided bucket, or `undefined`
|
|
15
|
+
* if no format pattern exists for the specified bucket.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const formatPattern = getFormatPatternForBucket(ColumnTimeBucket.DAY_OF_WEEK);
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export function getFormatPatternForBucket(bucket: ColumnTimeBucket): any {
|
|
22
|
+
return bucketizationToDatePreset[
|
|
23
|
+
ColumnTimeBucket[bucket] as keyof typeof bucketizationToDatePreset
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const getTimeBucket = (col: ChartColumn): string =>
|
|
28
|
+
_.get(timeBuckets, ColumnTimeBucket[col.timeBucket], timeBuckets.NO_BUCKET);
|
|
29
|
+
|
|
30
|
+
export const showDateFinancialYearFormat = (col: ChartColumn) => {
|
|
31
|
+
const supportedBucketizations = [timeBuckets.QUARTERLY, timeBuckets.YEARLY];
|
|
32
|
+
const currentBucketization = getTimeBucket(col);
|
|
33
|
+
return supportedBucketizations.some((supportedBucketization) => {
|
|
34
|
+
return supportedBucketization === currentBucketization;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the GUID (Globally Unique Identifier) for a custom calendar based on
|
|
40
|
+
* the calendar name and data source ID.
|
|
41
|
+
*
|
|
42
|
+
* This function looks up a custom calendar GUID from a mapping that associates
|
|
43
|
+
* data source IDs with calendar names. If the specified data source ID and calendar
|
|
44
|
+
* name exist in the provided map, it returns the corresponding GUID; otherwise,
|
|
45
|
+
* it returns `undefined`. This is used because we have some TS defined custom calender
|
|
46
|
+
* such as fiscal, geogrian,etc. We apply some custom formatting for those.
|
|
47
|
+
* to see where we are getting this refer-
|
|
48
|
+
* @link AppConfig
|
|
49
|
+
* @param name - The name of the custom calendar to look up.
|
|
50
|
+
* @param datasourceId - The ID of the data source associated with the custom calendar.
|
|
51
|
+
* @param datsourceIdToCustomCalendarMap - A mapping object where each data source ID
|
|
52
|
+
* maps to another object that associates calendar names with their GUIDs.
|
|
53
|
+
*
|
|
54
|
+
* @returns The GUID for the custom calendar associated with the given `name` and
|
|
55
|
+
* `datasourceId`, or `undefined` if no matching GUID is found.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const calendarGuid = getCustomCalendarGuid('fiscal', 'dataSource1', calendarMap);
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
export function getCustomCalendarGuid(
|
|
62
|
+
name: string,
|
|
63
|
+
datasourceId: string,
|
|
64
|
+
datsourceIdToCustomCalendarMap: any,
|
|
65
|
+
) {
|
|
66
|
+
return datsourceIdToCustomCalendarMap[datasourceId]
|
|
67
|
+
? datsourceIdToCustomCalendarMap[datasourceId][name]
|
|
68
|
+
: undefined;
|
|
69
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChartColumn,
|
|
3
|
+
ChartSpecificColumnType,
|
|
4
|
+
ColumnTimeBucket,
|
|
5
|
+
ColumnType,
|
|
6
|
+
DataType,
|
|
7
|
+
} from '../types/answer-column.types';
|
|
8
|
+
import * as DateFormatting from './date-formatting';
|
|
9
|
+
import {
|
|
10
|
+
getFormatPatternForBucket,
|
|
11
|
+
showDateFinancialYearFormat,
|
|
12
|
+
} from './date-utils';
|
|
13
|
+
import {
|
|
14
|
+
generateMapOptions,
|
|
15
|
+
getBaseTypeFormatterInstance,
|
|
16
|
+
getDataFormatter,
|
|
17
|
+
getFormatPattern,
|
|
18
|
+
} from './formatting-util';
|
|
19
|
+
|
|
20
|
+
jest.mock('./date-utils', () => ({
|
|
21
|
+
getFormatPatternForBucket: jest.fn(),
|
|
22
|
+
showDateFinancialYearFormat: jest.fn(),
|
|
23
|
+
getCustomCalendarGuid: jest
|
|
24
|
+
.fn()
|
|
25
|
+
.mockReturnValue('7573c08b-753b-478b-84fd-6e702d481ff6'),
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
describe('formatting utils', () => {
|
|
29
|
+
const mockOptions = {
|
|
30
|
+
quarterStartMonth: 1,
|
|
31
|
+
tsLocaleBasedStringsFormats: {
|
|
32
|
+
null_value_placeholder_label: '{Null}',
|
|
33
|
+
empty_value_placeholder_label: '{Empty}',
|
|
34
|
+
other_value_placeholder_label: '{Other}',
|
|
35
|
+
unavailabe_column_sample_value: '{Unavailable}',
|
|
36
|
+
weekOfDay: {
|
|
37
|
+
Friday: 'Friday',
|
|
38
|
+
Monday: 'Monday',
|
|
39
|
+
Saturday: 'Saturday',
|
|
40
|
+
Sunday: 'Sunday',
|
|
41
|
+
Thursday: 'Thursday',
|
|
42
|
+
Tuesday: 'Tuesday',
|
|
43
|
+
Wednesday: 'Wednesday',
|
|
44
|
+
},
|
|
45
|
+
monthOfYear: {
|
|
46
|
+
April: 'April',
|
|
47
|
+
August: 'August',
|
|
48
|
+
December: 'December',
|
|
49
|
+
February: 'February',
|
|
50
|
+
January: 'January',
|
|
51
|
+
July: 'July',
|
|
52
|
+
June: 'June',
|
|
53
|
+
March: 'March',
|
|
54
|
+
May: 'May',
|
|
55
|
+
November: 'November',
|
|
56
|
+
October: 'October',
|
|
57
|
+
September: 'September',
|
|
58
|
+
},
|
|
59
|
+
quarter_of_year: 'Q{1}',
|
|
60
|
+
},
|
|
61
|
+
tsDateConstants: {
|
|
62
|
+
day_in_month_format: 'e',
|
|
63
|
+
day_in_quarter_format: 'e',
|
|
64
|
+
day_in_year_format: 'j',
|
|
65
|
+
day_of_week_format: 'e',
|
|
66
|
+
month_in_quarter_format: 'm',
|
|
67
|
+
month_in_year_format: 'm',
|
|
68
|
+
special_value_unavailable: 'N/A',
|
|
69
|
+
week_in_year_format: 'V',
|
|
70
|
+
},
|
|
71
|
+
tsLocaleBasedDateFormats: {
|
|
72
|
+
DATE_SHORT: 'y',
|
|
73
|
+
},
|
|
74
|
+
quarter_of_year: 'Q{1}',
|
|
75
|
+
tsDefinedCustomCalenders: {
|
|
76
|
+
'43121d86-347a-4dbb-bea8-5e5bb899e427': {
|
|
77
|
+
calendar: '7573c08b-753b-478b-84fd-6e702d481ff6',
|
|
78
|
+
fiscal: 'bfa39848-ba4f-46d8-80fd-b695064e61b7',
|
|
79
|
+
french: 'a7316e8d-d4dd-4eaf-9294-396db951b422',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
displayToCustomCalendarValueMap: {
|
|
83
|
+
'1234567891': {
|
|
84
|
+
v: {
|
|
85
|
+
s: 'start',
|
|
86
|
+
e: 'end',
|
|
87
|
+
},
|
|
88
|
+
d: 'custom Date',
|
|
89
|
+
},
|
|
90
|
+
'1234567892': {
|
|
91
|
+
v: {
|
|
92
|
+
s: '1234567890',
|
|
93
|
+
e: 'end',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
test('getFormatPattern should call getFormatPatternForBucket with bucket and return pattern', () => {
|
|
99
|
+
const column = {
|
|
100
|
+
id: 'testId',
|
|
101
|
+
name: 'test',
|
|
102
|
+
type: ColumnType.MEASURE,
|
|
103
|
+
chartSpecificColumnType: ChartSpecificColumnType.UNKNOWN,
|
|
104
|
+
timeBucket: ColumnTimeBucket.YEARLY,
|
|
105
|
+
dataType: DataType.DATE,
|
|
106
|
+
calenderGuid: '12345',
|
|
107
|
+
} as ChartColumn;
|
|
108
|
+
|
|
109
|
+
expect(getFormatPattern(column)).toBe(undefined);
|
|
110
|
+
expect(getFormatPatternForBucket).toHaveBeenCalledWith(
|
|
111
|
+
column.timeBucket,
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
test('should return date formatter if column is date', () => {
|
|
115
|
+
const column = {
|
|
116
|
+
id: 'testId',
|
|
117
|
+
name: 'test',
|
|
118
|
+
type: ColumnType.MEASURE,
|
|
119
|
+
chartSpecificColumnType: ChartSpecificColumnType.UNKNOWN,
|
|
120
|
+
timeBucket: ColumnTimeBucket.YEARLY,
|
|
121
|
+
dataType: DataType.DATE,
|
|
122
|
+
calenderGuid: '12345',
|
|
123
|
+
} as ChartColumn;
|
|
124
|
+
const options = { isMillisIncluded: true };
|
|
125
|
+
|
|
126
|
+
const formatter = getBaseTypeFormatterInstance(column, options);
|
|
127
|
+
|
|
128
|
+
expect(typeof formatter).toBe('function');
|
|
129
|
+
const formattedDate = formatter(1234567890, mockOptions);
|
|
130
|
+
expect(formattedDate).toBe('2009');
|
|
131
|
+
const customFormattedDate = formatter(1234567891, mockOptions);
|
|
132
|
+
const customFormattedDateWithoutDisplayValue = formatter(
|
|
133
|
+
1234567892,
|
|
134
|
+
mockOptions,
|
|
135
|
+
);
|
|
136
|
+
expect(customFormattedDateWithoutDisplayValue).toBe('2009');
|
|
137
|
+
expect(customFormattedDate).toBe('custom Date');
|
|
138
|
+
expect(showDateFinancialYearFormat).toHaveBeenCalledWith(column);
|
|
139
|
+
});
|
|
140
|
+
test('should return dateNum formatter if column is dateNum', () => {
|
|
141
|
+
const column = {
|
|
142
|
+
id: 'testId',
|
|
143
|
+
name: 'test',
|
|
144
|
+
type: ColumnType.ATTRIBUTE,
|
|
145
|
+
chartSpecificColumnType: ChartSpecificColumnType.UNKNOWN,
|
|
146
|
+
timeBucket: ColumnTimeBucket.HOUR_OF_DAY,
|
|
147
|
+
dataType: DataType.INT64,
|
|
148
|
+
calenderGuid: '12345',
|
|
149
|
+
} as ChartColumn;
|
|
150
|
+
const options = { isMillisIncluded: true };
|
|
151
|
+
const formatter = getBaseTypeFormatterInstance(column, options);
|
|
152
|
+
|
|
153
|
+
expect(typeof formatter).toBe('function');
|
|
154
|
+
const formattedDate = formatter(1234567890, mockOptions);
|
|
155
|
+
expect(formattedDate).toBe(1234567890);
|
|
156
|
+
const customFormattedDate = formatter(1234567891, mockOptions);
|
|
157
|
+
const customFormattedDateWithoutDisplayValue = formatter(
|
|
158
|
+
1234567892,
|
|
159
|
+
mockOptions,
|
|
160
|
+
);
|
|
161
|
+
expect(customFormattedDateWithoutDisplayValue).toBe(1234567892);
|
|
162
|
+
expect(customFormattedDate).toBe('custom Date');
|
|
163
|
+
});
|
|
164
|
+
test('should return a default formatter for non-date types', () => {
|
|
165
|
+
const column = {
|
|
166
|
+
id: 'testId',
|
|
167
|
+
name: 'test',
|
|
168
|
+
type: ColumnType.MEASURE,
|
|
169
|
+
chartSpecificColumnType: ChartSpecificColumnType.UNKNOWN,
|
|
170
|
+
timeBucket: ColumnTimeBucket.HOUR_OF_DAY,
|
|
171
|
+
dataType: DataType.INT64,
|
|
172
|
+
calenderGuid: '12345',
|
|
173
|
+
} as ChartColumn;
|
|
174
|
+
const options = { isMillisIncluded: true };
|
|
175
|
+
const formatter = getBaseTypeFormatterInstance(column, options);
|
|
176
|
+
|
|
177
|
+
expect(formatter('test')).toBe('test');
|
|
178
|
+
});
|
|
179
|
+
test('getDataFormatter should return appropriate formatter based on column type', () => {
|
|
180
|
+
const column = {
|
|
181
|
+
id: 'testId',
|
|
182
|
+
name: 'test',
|
|
183
|
+
type: ColumnType.ATTRIBUTE,
|
|
184
|
+
chartSpecificColumnType: ChartSpecificColumnType.UNKNOWN,
|
|
185
|
+
timeBucket: ColumnTimeBucket.YEARLY,
|
|
186
|
+
dataType: DataType.DATE,
|
|
187
|
+
calenderGuid: '12345',
|
|
188
|
+
} as ChartColumn;
|
|
189
|
+
const options = { isMillisIncluded: true };
|
|
190
|
+
|
|
191
|
+
const formatter = getDataFormatter(column, options);
|
|
192
|
+
|
|
193
|
+
expect(typeof formatter).toBe('function');
|
|
194
|
+
const formattedDate = formatter(1234567890, mockOptions);
|
|
195
|
+
expect(formattedDate).toBe('2009');
|
|
196
|
+
const customFormattedDate = formatter(1234567891, mockOptions);
|
|
197
|
+
const customFormattedDateWithoutDisplayValue = formatter(
|
|
198
|
+
1234567892,
|
|
199
|
+
mockOptions,
|
|
200
|
+
);
|
|
201
|
+
expect(customFormattedDateWithoutDisplayValue).toBe('2009');
|
|
202
|
+
expect(customFormattedDate).toBe('custom Date');
|
|
203
|
+
expect(showDateFinancialYearFormat).toHaveBeenCalledWith(column);
|
|
204
|
+
});
|
|
205
|
+
test('generateMapOptions should return map options based on appConfig and column', () => {
|
|
206
|
+
const column = {
|
|
207
|
+
id: 'testId',
|
|
208
|
+
name: 'test',
|
|
209
|
+
type: ColumnType.ATTRIBUTE,
|
|
210
|
+
chartSpecificColumnType: ChartSpecificColumnType.UNKNOWN,
|
|
211
|
+
timeBucket: ColumnTimeBucket.YEARLY,
|
|
212
|
+
dataType: DataType.DATE,
|
|
213
|
+
calenderGuid: '12345',
|
|
214
|
+
} as ChartColumn;
|
|
215
|
+
|
|
216
|
+
const appConfig = {
|
|
217
|
+
localeOptions: { locale: 'en-US', quarterStartMonth: 1 },
|
|
218
|
+
dateFormatsConfig: {
|
|
219
|
+
tsLocaleBasedDateFormats: 'MM-DD-YYYY',
|
|
220
|
+
tsLocaleBasedStringsFormats: 'YYYY/MM/DD',
|
|
221
|
+
tsDateConstants: {},
|
|
222
|
+
tsDefinedCustomCalenders: {},
|
|
223
|
+
DEFAULT_DATASOURCE_ID: 'source1',
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
const data = [{ v: { s: 'key1' } }, { v: { s: 'key2' } }];
|
|
227
|
+
|
|
228
|
+
const mapOptions = generateMapOptions(appConfig, column, data);
|
|
229
|
+
|
|
230
|
+
expect(mapOptions.locale).toBe('en-US');
|
|
231
|
+
expect(mapOptions.quarterStartMonth).toBe(1);
|
|
232
|
+
expect(mapOptions.displayToCustomCalendarValueMap).toEqual({
|
|
233
|
+
key1: data[0],
|
|
234
|
+
key2: data[1],
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
test('should have format pattern as DATETIME_SHORT_WITH_MILLIS when format pattern is null', () => {
|
|
238
|
+
const column = {
|
|
239
|
+
id: 'testId',
|
|
240
|
+
name: 'test',
|
|
241
|
+
type: ColumnType.VIRTUAL,
|
|
242
|
+
chartSpecificColumnType: ChartSpecificColumnType.UNKNOWN,
|
|
243
|
+
timeBucket: ColumnTimeBucket.MONTHLY,
|
|
244
|
+
dataType: DataType.DATE_TIME,
|
|
245
|
+
calenderGuid: '12345',
|
|
246
|
+
} as ChartColumn;
|
|
247
|
+
const options = { isMillisIncluded: true };
|
|
248
|
+
const formatter = getBaseTypeFormatterInstance(column, options);
|
|
249
|
+
expect(typeof formatter).toBe('function');
|
|
250
|
+
});
|
|
251
|
+
test('should correctly set format pattern for date-time column with and without milliseconds', () => {
|
|
252
|
+
jest.spyOn(DateFormatting, 'formatDate').mockImplementation(jest.fn());
|
|
253
|
+
const column = {
|
|
254
|
+
id: 'testId',
|
|
255
|
+
name: 'test',
|
|
256
|
+
type: ColumnType.MEASURE,
|
|
257
|
+
chartSpecificColumnType: ChartSpecificColumnType.UNKNOWN,
|
|
258
|
+
timeBucket: ColumnTimeBucket.MONTHLY,
|
|
259
|
+
dataType: DataType.DATE_TIME, // Indicates it's a date-time column
|
|
260
|
+
calenderGuid: '12345',
|
|
261
|
+
} as ChartColumn;
|
|
262
|
+
|
|
263
|
+
const optionsWithMillis = { isMillisIncluded: true };
|
|
264
|
+
const optionsWithoutMillis = { isMillisIncluded: false };
|
|
265
|
+
|
|
266
|
+
const formatterWithMillis = getBaseTypeFormatterInstance(
|
|
267
|
+
column,
|
|
268
|
+
optionsWithMillis,
|
|
269
|
+
);
|
|
270
|
+
const formatterWithoutMillis = getBaseTypeFormatterInstance(
|
|
271
|
+
column,
|
|
272
|
+
optionsWithoutMillis,
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
expect(typeof formatterWithMillis).toBe('function');
|
|
276
|
+
expect(typeof formatterWithoutMillis).toBe('function');
|
|
277
|
+
|
|
278
|
+
// Mock dateFormatPresets to test the format patterns
|
|
279
|
+
const dateFormatPresetsMock = {
|
|
280
|
+
DATETIME_SHORT_WITH_MILLIS: 'DATETIME_SHORT_WITH_MILLIS',
|
|
281
|
+
DATETIME_SHORT_WITH_SECONDS: 'DATETIME_SHORT_WITH_SECONDS',
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// Mock formatted dates based on dateFormatPresets
|
|
285
|
+
const formattedDateWithMillis = formatterWithMillis(
|
|
286
|
+
1234567890,
|
|
287
|
+
mockOptions,
|
|
288
|
+
);
|
|
289
|
+
expect(DateFormatting.formatDate).toHaveBeenCalledWith(
|
|
290
|
+
1234567890,
|
|
291
|
+
dateFormatPresetsMock.DATETIME_SHORT_WITH_MILLIS,
|
|
292
|
+
true,
|
|
293
|
+
{
|
|
294
|
+
...mockOptions,
|
|
295
|
+
customCalendarOverridesFiscalOffset: true,
|
|
296
|
+
},
|
|
297
|
+
);
|
|
298
|
+
const formattedDateWithoutMillis = formatterWithoutMillis(
|
|
299
|
+
1234567890,
|
|
300
|
+
mockOptions,
|
|
301
|
+
);
|
|
302
|
+
expect(DateFormatting.formatDate).toHaveBeenCalledWith(
|
|
303
|
+
1234567890,
|
|
304
|
+
dateFormatPresetsMock.DATETIME_SHORT_WITH_SECONDS,
|
|
305
|
+
true,
|
|
306
|
+
{
|
|
307
|
+
...mockOptions,
|
|
308
|
+
customCalendarOverridesFiscalOffset: true,
|
|
309
|
+
},
|
|
310
|
+
);
|
|
311
|
+
});
|
|
312
|
+
});
|