1- import Formatter from './Formatter' ;
1+ import dh from '@deephaven/jsapi-shim' ;
2+ import { TestUtils } from '@deephaven/utils' ;
3+ import Formatter , { FormattingRule } from './Formatter' ;
24import FormatterUtils , {
5+ createFormatterFromSettings ,
36 getColumnFormats ,
47 getDateTimeFormatterOptions ,
58} from './FormatterUtils' ;
@@ -9,7 +12,31 @@ import {
912 TableColumnFormatType ,
1013} from './formatters' ;
1114import TableUtils from './TableUtils' ;
12- import { ColumnFormatSettings , DateTimeFormatSettings } from './Settings' ;
15+ import Settings , {
16+ ColumnFormatSettings ,
17+ DateTimeFormatSettings ,
18+ } from './Settings' ;
19+
20+ jest . mock ( './Formatter' , ( ) => {
21+ const FormatterActual = jest . requireActual ( './Formatter' ) . default ;
22+
23+ // Extract static methods
24+ const { makeColumnFormatMap, makeColumnFormattingRule } = FormatterActual ;
25+
26+ // Wrap Formatter constructor so we can spy on it
27+ const mockFormatter = jest . fn ( ( ...args ) => new FormatterActual ( ...args ) ) ;
28+
29+ return {
30+ __esModule : true ,
31+ default : Object . assign ( mockFormatter , {
32+ makeColumnFormatMap,
33+ makeColumnFormattingRule,
34+ } ) ,
35+ } ;
36+ } ) ;
37+
38+ const { createMockProxy } = TestUtils ;
39+ const FormatterActual = jest . requireActual ( './Formatter' ) . default ;
1340
1441function makeFormatter ( ...settings : ConstructorParameters < typeof Formatter > ) {
1542 return new Formatter ( ...settings ) ;
@@ -23,6 +50,46 @@ function makeFormattingRule(
2350 return { label, formatString, type } ;
2451}
2552
53+ describe ( 'createFormatterFromSettings' , ( ) => {
54+ const mockSettings = createMockProxy < Settings > ( {
55+ formatter : [
56+ createMockProxy < FormattingRule > ( {
57+ format : createMockProxy < TableColumnFormat > ( ) ,
58+ } ) ,
59+ ] ,
60+ } ) ;
61+
62+ it . each ( [ undefined , mockSettings ] ) (
63+ 'should create a formatter with the given settings: %s' ,
64+ settings => {
65+ const columnRules = getColumnFormats ( settings ) ;
66+ const dateTimeOptions = getDateTimeFormatterOptions ( settings ) ;
67+
68+ const {
69+ defaultDecimalFormatOptions,
70+ defaultIntegerFormatOptions,
71+ truncateNumbersWithPound,
72+ showEmptyStrings,
73+ showNullStrings,
74+ } = settings ?? { } ;
75+
76+ const actual = createFormatterFromSettings ( dh , settings ) ;
77+
78+ expect ( Formatter ) . toHaveBeenCalledWith (
79+ dh ,
80+ columnRules ,
81+ dateTimeOptions ,
82+ defaultDecimalFormatOptions ,
83+ defaultIntegerFormatOptions ,
84+ truncateNumbersWithPound ,
85+ showEmptyStrings ,
86+ showNullStrings
87+ ) ;
88+ expect ( actual ) . toBeInstanceOf ( FormatterActual ) ;
89+ }
90+ ) ;
91+ } ) ;
92+
2693describe ( 'isCustomColumnFormatDefined' , ( ) => {
2794 const columnFormats = [
2895 Formatter . makeColumnFormattingRule (
0 commit comments