import { CellValue, ColumnType, DateFormat, FormulaResultType, ISelect, IStatus, ITypeOptions, Language, MaybeAbsentCellValue, NumberFormat, SelectColor, TimeFormat, } from '../../types'; import { StatusType } from '../../types/graphql-global-types'; import { transformCellValue } from '.'; import format from 'date-fns/format'; import parseISO from 'date-fns/parseISO'; describe('transformCellValue', () => { /** * https://www.notion.so/de3837fde2314fefa84566e9e8c85434?v=c2e129c513264919aaf6cb6f415208a9 */ describe('product test cases (https://www.notion.so/Update-Column-7e986343f2c8446b9e5f409e9ea397a2)', () => { /** * https://www.notion.so/Single-line-of-text-ebf35e58ec0d48bd8ae345812a59ab73 */ describe('TEXT -> (https://www.notion.so/Single-line-of-text-ebf35e58ec0d48bd8ae345812a59ab73)', () => { describe('TEXT', () => { test(`"A\\nB"\t-> "A B"`, () => { expect( transformCellValue({ originCellValue: 'A\nB', originTypeOptions: { type: ColumnType.LONG_TEXT }, targetTypeOptions: { type: ColumnType.TEXT }, }) ).toBe('A B'); }); }); describe('MULTI_SELECT', () => { const originTypeOptions = { type: ColumnType.TEXT as const }; const targetTypeOptions = { type: ColumnType.MULTI_SELECT as const, options: [ { name: 'A', optionId: 'mulsel-A', color: SelectColor.blackDarkest, }, { name: 'B', optionId: 'mulsel-B', color: SelectColor.blackDarkest, }, { name: 'A,B', optionId: 'mulsel-A-wide-comma-B', color: SelectColor.blackDarkest, }, { name: 'A B C', optionId: 'mulsel-A-B-C', color: SelectColor.blackDarkest, }, ], }; const transformTextToMultiSelect = (originCellValue: string) => transformCellValue({ originCellValue, originTypeOptions, targetTypeOptions, }); test(`"A,B"\t-> [A] [B]`, () => { expect(transformTextToMultiSelect('A,B')).toEqual([ 'mulsel-A', 'mulsel-B', ]); }); test(`"A, B"\t-> [A] [B] (comma with space)`, () => { expect(transformTextToMultiSelect('A, B')).toEqual([ 'mulsel-A', 'mulsel-B', ]); }); test(`"A,B"\t-> [A,B] (full-width comma)`, () => { expect(transformTextToMultiSelect('A,B')).toEqual([ 'mulsel-A-wide-comma-B', ]); }); test(`"A,A"\t-> [A]`, () => { expect(transformTextToMultiSelect('A,A')).toEqual(['mulsel-A']); }); test(`"A,B,B"\t-> [A] [B]`, () => { expect(transformTextToMultiSelect('A,B,B')).toEqual([ 'mulsel-A', 'mulsel-B', ]); }); test(`"A\\nB\\nC"\t-> [A B C]`, () => { expect( transformCellValue({ originCellValue: 'A\nB\nC', originTypeOptions: { type: ColumnType.LONG_TEXT }, targetTypeOptions, }) ).toEqual(['mulsel-A-B-C']); }); test(`"A、B"\t-> [A] [B] (ideographic comma)`, () => { expect(transformTextToMultiSelect('A、B')).toEqual([ 'mulsel-A', 'mulsel-B', ]); }); }); describe('SELECT', () => { const originTypeOptions = { type: ColumnType.TEXT as const }; const targetTypeOptions = { type: ColumnType.SELECT as const, options: [ { name: 'A,B', optionId: 'sngsel-A-B', color: SelectColor.blackDarkest, }, { name: 'A,B', optionId: 'sngsel-A-wide-comma-B', color: SelectColor.blackDarkest, }, { name: 'B,A', optionId: 'sngsel-B-A', color: SelectColor.blackDarkest, }, { name: 'A,A', optionId: 'sngsel-A-A', color: SelectColor.blackDarkest, }, ], }; const transformTextToSingleSelect = (originCellValue: string) => transformCellValue({ originCellValue, originTypeOptions, targetTypeOptions, }); test(`"A,B"\t-> [A,B]`, () => { expect(transformTextToSingleSelect('A,B')).toEqual('sngsel-A-B'); }); test(`"A,B"\t-> [A,B] (full-width comma)`, () => { expect(transformTextToSingleSelect('A,B')).toEqual( 'sngsel-A-wide-comma-B' ); }); test(`"B,A"\t-> [B,A]`, () => { expect(transformTextToSingleSelect('B,A')).toEqual('sngsel-B-A'); }); test(`"A,A"\t-> [A,A]`, () => { expect(transformTextToSingleSelect('A,A')).toEqual('sngsel-A-A'); }); }); describe('NUMBER', () => { const originTypeOptions = { type: ColumnType.TEXT as const }; const getTargetTypeOptions = ({ precision, }: { precision: number; }) => ({ type: ColumnType.NUMBER as const, numberFormat: NumberFormat.DECIMAL, precision: precision, }); const transformTextToNumber = ({ originCellValue, precision, }: { originCellValue: string; precision: number; }) => transformCellValue({ originCellValue, originTypeOptions, targetTypeOptions: getTargetTypeOptions({ precision }), }); test(`"1a,2b"\t-> 12.00`, () => { expect( transformTextToNumber({ originCellValue: '1a,2b', precision: 2, }) ).toEqual(12.0); }); test(`"1a2b.12"\t-> 12.12`, () => { expect( transformTextToNumber({ originCellValue: '1a2b.12', precision: 2, }) ).toEqual(12.12); }); test(`"1a2b.12.12"\t-> 12.12`, () => { expect( transformTextToNumber({ originCellValue: '1a2b.12.12', precision: 2, }) ).toEqual(12.12); }); test(`"1%2"\t-> 0.01`, () => { expect( transformTextToNumber({ originCellValue: '1%2', precision: 2, }) ).toEqual(0.01); }); test(`"1.1%"\t-> 0.011`, () => { expect( transformTextToNumber({ originCellValue: '1.1%', precision: 3, }) ).toEqual(0.011); }); test(`"1a2b.12%"\t-> 0.1212`, () => { expect( transformTextToNumber({ originCellValue: '1a2b.12%', precision: 4, }) ).toEqual(0.1212); }); test(`"12.12.12%"\t-> 0.1212`, () => { expect( transformTextToNumber({ originCellValue: '12.12.12%', precision: 4, }) ).toEqual(0.1212); }); test(`"1a,2.v3%"\t-> 0.123`, () => { expect( transformTextToNumber({ originCellValue: '1a,2.v3%', precision: 3, }) ).toEqual(0.123); }); test(`"-1.1"\t-> -1.10`, () => { expect( transformTextToNumber({ originCellValue: '-1.1', precision: 2, }) ).toEqual(-1.1); }); test(`"-1.1.-1"\t-> -1.10`, () => { expect( transformTextToNumber({ originCellValue: '-1.1.-1', precision: 3, }) ).toEqual(-1.1); }); test(`"a-1-2"\t-> -1.00`, () => { expect( transformTextToNumber({ originCellValue: 'a-1-2', precision: 2, }) ).toEqual(-1.0); }); test(`"a-11.2%1.1"\t-> -0.1120`, () => { expect( transformTextToNumber({ originCellValue: 'a-11.2%1.1', precision: 4, }) ).toEqual(-0.112); }); }); describe('RATING', () => { const originTypeOptions = { type: ColumnType.TEXT as const }; const targetTypeOptions = { type: ColumnType.RATING as const, ratingMax: 5, }; const transformTextToRating = (originCellValue: string) => transformCellValue({ originCellValue, originTypeOptions, targetTypeOptions, }); test(`"1a"\t-> ★`, () => { expect(transformTextToRating('1a')).toEqual(1); }); test(`"1.1"\t-> ★`, () => { expect(transformTextToRating('1.1')).toEqual(1); }); test(`"1.7"\t-> ★ ★`, () => { expect(transformTextToRating('1.7')).toEqual(2); }); test(`"-1"\t-> 空`, () => { expect(transformTextToRating('-1')).toBeNull(); }); test(`"111%"\t-> ★`, () => { expect(transformTextToRating('111%')).toEqual(1); }); test(`"10"\t-> ★ ★ ★ ★ ★`, () => { expect(transformTextToRating('10')).toEqual(5); }); test(`"2.8"\t-> ★ ★ ★`, () => { expect(transformTextToRating('2.8')).toEqual(3); }); }); describe('CHECKBOX', () => { const transformTextToCheckbox = (originCellValue: string) => transformCellValue({ originCellValue, originTypeOptions: { type: ColumnType.TEXT as const }, targetTypeOptions: { type: ColumnType.CHECKBOX as const }, }); test.each([ 'True', 'TRUE', 'true', '1', '是', 'Yes', 'YES', '已勾选', 'Checked', 'checked', '2', '20%', '20%1212', '07/08/2021', '-1', ])(`"%s" \t-> ☑`, (originCellValue) => { expect(transformTextToCheckbox(originCellValue)).toBe(true); }); test.each(['未勾选', '0', 'false', 'No', 'foo'])( `"%s" \t-> ☐`, (originCellValue) => { expect(transformTextToCheckbox(originCellValue)).toBe(false); } ); }); }); }); describe('localization', () => { test('CHECKBOX -> TEXT', () => { expect( transformCellValue({ originCellValue: true, originTypeOptions: { type: ColumnType.CHECKBOX as const }, targetTypeOptions: { type: ColumnType.TEXT as const }, opts: { locale: Language.en, }, }) ).toBe('checked'); expect( transformCellValue({ originCellValue: true, originTypeOptions: { type: ColumnType.CHECKBOX as const }, targetTypeOptions: { type: ColumnType.TEXT as const }, opts: { locale: Language.zh, }, }) ).toBe('已勾选'); }); }); describe('tech test cases', () => { const targetTypeOptionsBattery: Array<{ descriptor: string; typeOptions: ITypeOptions; }> = [ { descriptor: 'checkbox generic', typeOptions: { type: ColumnType.CHECKBOX }, }, { descriptor: 'collaborator generic', typeOptions: { type: ColumnType.COLLABORATOR, groups: [], useGroup: false, useMultiple: false, useNotify: false, }, }, { descriptor: 'currency precision 0', typeOptions: { type: ColumnType.CURRENCY, currencyFormat: '¥', precision: 0, }, }, { descriptor: 'currency precision 2', typeOptions: { type: ColumnType.CURRENCY, currencyFormat: '$', precision: 2, }, }, { descriptor: 'datetime ISO date only', typeOptions: { type: ColumnType.DATETIME, dateFormat: DateFormat.ISO, includeTime: false, timeFormat: TimeFormat.TWELVE_HOUR, useGMT: false, }, }, { descriptor: 'datetime Friendly 12 hour', typeOptions: { type: ColumnType.DATETIME, dateFormat: DateFormat.FRIENDLY, includeTime: true, timeFormat: TimeFormat.TWELVE_HOUR, useGMT: false, }, }, { descriptor: 'datetime Local', typeOptions: { type: ColumnType.DATETIME, dateFormat: DateFormat.LOCAL, includeTime: true, timeFormat: TimeFormat.TWELVE_HOUR, useGMT: false, }, }, { descriptor: 'datetime ISO 24 hour useGMT', typeOptions: { type: ColumnType.DATETIME, dateFormat: DateFormat.ISO, includeTime: true, timeFormat: TimeFormat.TWOFOUR_HOUR, useGMT: false, }, }, { descriptor: 'email generic', typeOptions: { type: ColumnType.EMAIL } }, { descriptor: 'long text generic', typeOptions: { type: ColumnType.LONG_TEXT }, }, { descriptor: 'multi attachment generic', typeOptions: { type: ColumnType.MULTI_ATTACHMENT }, }, { descriptor: 'multi select with no options', typeOptions: { type: ColumnType.MULTI_SELECT, options: [], }, }, { descriptor: 'multi select with variety of options', typeOptions: { type: ColumnType.MULTI_SELECT, options: [ { name: 'foo', optionId: 'mulsel-foo', color: SelectColor.blackDarkest, }, { name: 'bar', optionId: 'mulsel-bar', color: SelectColor.blackDarkest, }, { name: 'foo, bar', optionId: 'mulsel-foobar', color: SelectColor.blackDarkest, }, { name: '', optionId: 'mulsel-emptyname', color: SelectColor.blackDarkest, }, { name: 'a', optionId: 'mulsel-a', color: SelectColor.blackDarkest, }, { name: 'b', optionId: 'mulsel-b', color: SelectColor.blackDarkest, }, { name: 'a b', optionId: 'mulsel-aspaceb', color: SelectColor.blackDarkest, }, { name: '1', optionId: 'mulsel-one', color: SelectColor.blackDarkest, }, { name: '1.00', optionId: 'mulsel-onepointzerozero', color: SelectColor.blackDarkest, }, { name: 'checked', optionId: 'mulsel-checked', color: SelectColor.blackDarkest, }, { name: '$1.00', optionId: 'mulsel-onedollarandzerocents', color: SelectColor.blackDarkest, }, { name: '2021-03-22', optionId: 'mulsel-adate', color: SelectColor.blackDarkest, }, { name: 'foo@bar.com', optionId: 'mulsel-email', color: SelectColor.blackDarkest, }, { name: 'fileName.png (https://www.treelab.com.cn/id/fileName.png)', optionId: 'mulsel-filename', color: SelectColor.blackDarkest, }, ], }, }, { descriptor: 'number decimal precision 0', typeOptions: { type: ColumnType.NUMBER, numberFormat: NumberFormat.DECIMAL, precision: 0, }, }, { descriptor: 'number percent precision 2', typeOptions: { type: ColumnType.NUMBER, numberFormat: NumberFormat.PERCENTAGE, precision: 2, }, }, { descriptor: 'number.. currency? precision 4', typeOptions: { type: ColumnType.NUMBER, numberFormat: NumberFormat.CURRENCY, precision: 4, }, }, { descriptor: 'phone generic', typeOptions: { type: ColumnType.PHONE } }, { descriptor: 'rating max 5', typeOptions: { type: ColumnType.RATING, ratingMax: 5 }, }, { descriptor: 'rating max 10', typeOptions: { type: ColumnType.RATING, ratingMax: 10 }, }, { descriptor: 'record reference generic', typeOptions: { type: ColumnType.RECORD_REFERENCE, foreignTableId: 'tab1', }, }, { descriptor: 'status with default options', typeOptions: { type: ColumnType.STATUS, statuses: [ { statusId: 'stus-foo-pending', name: 'foo', order: 1, type: StatusType.PENDING, }, { statusId: 'stus-bar-done', name: 'bar', order: 2, type: StatusType.DONE, }, ], }, }, { descriptor: 'status with variety statusType=DOIGN options', typeOptions: { type: ColumnType.STATUS, statuses: [ { statusId: 'stus-foo-pending', name: 'foo', order: 1, type: StatusType.PENDING, }, { statusId: 'stus-bar-doing', name: 'bar', order: 2, type: StatusType.DOING, }, { statusId: 'stus-emptyname-doing', name: '', order: 3, type: StatusType.DOING, }, { name: '1', statusId: 'stus-one-doing', order: 4, type: StatusType.DOING, }, { name: '1.00', statusId: 'stus-onepointzerozero-doing', order: 5, type: StatusType.DOING, }, { name: 'checked', statusId: 'stus-checked-doing', order: 6, type: StatusType.DOING, }, { name: '$1.00', statusId: 'stus-onedollarandzerocents-doing', order: 7, type: StatusType.DOING, }, { name: '2021-03-22', statusId: 'stus-date-doing', order: 8, type: StatusType.DOING, }, { name: 'foo@bar.com', statusId: 'stus-email-doing', order: 9, type: StatusType.DOING, }, { name: 'fileName.png (https://www.treelab.com.cn/id/fileName.png)', statusId: 'stus-filename-doing', order: 10, type: StatusType.DOING, }, { statusId: 'foo,bar', name: 'stus-fooobar-done', order: 11, type: StatusType.DONE, }, ], }, }, { descriptor: 'select with no options', typeOptions: { type: ColumnType.SELECT, options: [], }, }, { descriptor: 'select with variety of options', typeOptions: { type: ColumnType.SELECT, options: [ { name: 'foo', optionId: 'snglsel-foo', color: SelectColor.blackDarkest, }, { name: 'bar', optionId: 'snglsel-bar', color: SelectColor.blackDarkest, }, { name: 'foo, bar', optionId: 'snglsel-foobar', color: SelectColor.blackDarkest, }, { name: '', optionId: 'snglsel-emptyname', color: SelectColor.blackDarkest, }, { name: 'a', optionId: 'snglsel-a', color: SelectColor.blackDarkest, }, { name: 'b', optionId: 'snglsel-b', color: SelectColor.blackDarkest, }, { name: 'a b', optionId: 'snglsel-aspaceb', color: SelectColor.blackDarkest, }, { name: '1', optionId: 'snglsel-one', color: SelectColor.blackDarkest, }, { name: '1.00', optionId: 'snglsel-onepointzerozero', color: SelectColor.blackDarkest, }, { name: 'checked', optionId: 'snglsel-checked', color: SelectColor.blackDarkest, }, { name: '$1.00', optionId: 'snglsel-onedollarandzerocents', color: SelectColor.blackDarkest, }, { name: '2021-03-22', optionId: 'snglsel-adate', color: SelectColor.blackDarkest, }, { name: 'foo@bar.com', optionId: 'snglsel-email', color: SelectColor.blackDarkest, }, { name: 'fileName.png (https://www.treelab.com.cn/id/fileName.png)', optionId: 'snglsel-filename', color: SelectColor.blackDarkest, }, ], }, }, { descriptor: 'text generic', typeOptions: { type: ColumnType.TEXT } }, ]; const getTransformedCellValues = ({ originCellValue, originTypeOptions, }: { originCellValue: CellValue; originTypeOptions: ITypeOptions & { type: T }; }) => targetTypeOptionsBattery.reduce<{ [columnType: string]: MaybeAbsentCellValue; }>( (results, { descriptor, typeOptions: targetTypeOptions }) => ({ ...results, [descriptor]: (() => { const transformedCellValue = transformCellValue({ originCellValue, originTypeOptions, targetTypeOptions, opts: { locale: Language.en, }, }); if (targetTypeOptions.type !== ColumnType.DATETIME) return transformedCellValue; if (!transformedCellValue) return transformedCellValue; return format( parseISO(transformedCellValue as string), "yyyy-MM-dd'T'HH:mm:ss" ); })(), }), {} ); it('throws an error for non-updatable target column types', () => { expect(() => transformCellValue({ originCellValue: 'foo', originTypeOptions: { type: ColumnType.TEXT }, targetTypeOptions: { type: ColumnType.LOOKUP } as ITypeOptions, }) ).toThrowErrorMatchingInlineSnapshot( `"Can't convert cell value to non-updatable column type LOOKUP"` ); expect(() => transformCellValue({ originCellValue: 'foo', originTypeOptions: { type: ColumnType.TEXT }, targetTypeOptions: { type: ColumnType.NOOP } as ITypeOptions, }) ).toThrowErrorMatchingInlineSnapshot( `"Can't convert cell value to non-updatable column type NOOP"` ); expect(() => transformCellValue({ originCellValue: 'foo', originTypeOptions: { type: ColumnType.TEXT }, targetTypeOptions: { type: ColumnType.FORMULA } as ITypeOptions, }) ).toThrowErrorMatchingInlineSnapshot( `"Can't convert cell value to non-updatable column type FORMULA"` ); expect(() => transformCellValue({ originCellValue: 'foo', originTypeOptions: { type: ColumnType.TEXT }, targetTypeOptions: { type: ColumnType.ROLLUP } as ITypeOptions, }) ).toThrowErrorMatchingInlineSnapshot( `"Can't convert cell value to non-updatable column type ROLLUP"` ); expect(() => transformCellValue({ originCellValue: 'foo', originTypeOptions: { type: ColumnType.TEXT }, targetTypeOptions: { type: ColumnType.UNIQUE_ID } as ITypeOptions, }) ).toThrowErrorMatchingInlineSnapshot( `"Can't convert cell value to non-updatable column type UNIQUE_ID"` ); }); it('transforms random TEXT => *', () => { const originCellValue = 'foo'; const originTypeOptions = { type: ColumnType.TEXT } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo", "long text generic": "foo", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-foo", "status with default options": "stus-foo-pending", "status with variety statusType=DOIGN options": "stus-foo-pending", "text generic": "foo", } `); }); it('transforms number TEXT => *', () => { const originCellValue = '1'; const originTypeOptions = { type: ColumnType.TEXT } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1, "currency precision 2": 1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "1", "long text generic": "1", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-one", ], "number decimal precision 0": 1, "number percent precision 2": 1, "number.. currency? precision 4": 1, "phone generic": "1", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-one", "status with default options": null, "status with variety statusType=DOIGN options": "stus-one-doing", "text generic": "1", } `); }); it('transforms currency TEXT => *', () => { const originCellValue = '$1.00'; const originTypeOptions = { type: ColumnType.TEXT } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1, "currency precision 2": 1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "$1.00", "long text generic": "$1.00", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-onedollarandzerocents", ], "number decimal precision 0": 1, "number percent precision 2": 1, "number.. currency? precision 4": 1, "phone generic": "$1.00", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-onedollarandzerocents", "status with default options": null, "status with variety statusType=DOIGN options": "stus-onedollarandzerocents-doing", "text generic": "$1.00", } `); }); it('transforms date TEXT => *', () => { const originCellValue = '2021-03-22'; const originTypeOptions = { type: ColumnType.TEXT } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 2021, "currency precision 2": 2021, "datetime Friendly 12 hour": "2021-03-22T00:00:00", "datetime ISO 24 hour useGMT": "2021-03-22T00:00:00", "datetime ISO date only": "2021-03-22T00:00:00", "datetime Local": "2021-03-22T00:00:00", "email generic": "2021-03-22", "long text generic": "2021-03-22", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-adate", ], "number decimal precision 0": 2021, "number percent precision 2": 2021, "number.. currency? precision 4": 2021, "phone generic": "2021-03-22", "rating max 10": 10, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-adate", "status with default options": null, "status with variety statusType=DOIGN options": "stus-date-doing", "text generic": "2021-03-22", } `); }); it('transforms text with comma TEXT => *', () => { const originCellValue = 'foo, bar'; const originTypeOptions = { type: ColumnType.TEXT } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo, bar", "long text generic": "foo, bar", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", "mulsel-bar", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo, bar", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-foobar", "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "foo, bar", } `); }); it('transforms file name TEXT => *', () => { const originCellValue = 'fileName.png (https://www.treelab.com.cn/id/fileName.png)'; const originTypeOptions = { type: ColumnType.TEXT } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "fileName.png (https://www.treelab.com.cn/id/fileName.png)", "long text generic": "fileName.png (https://www.treelab.com.cn/id/fileName.png)", "multi attachment generic": Array [ Object { "fileId": "fileName", "fileKey": "id/fileName.png", "fileName": "fileName.png", "fileSize": 0, "fileType": "image/png", "largeThumbUrl": "https://www.treelab.com.cn/id/fileName.png?x-oss-process=style/high", "mediumThumbUrl": "https://www.treelab.com.cn/id/fileName.png?x-oss-process=style/middle", "smallThumbUrl": "https://www.treelab.com.cn/id/fileName.png?x-oss-process=style/low", "url": "https://www.treelab.com.cn/id/fileName.png", }, ], "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-filename", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "fileName.png (https://www.treelab.com.cn/id/fileName.png)", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-filename", "status with default options": null, "status with variety statusType=DOIGN options": "stus-filename-doing", "text generic": "fileName.png (https://www.treelab.com.cn/id/fileName.png)", } `); }); it('transforms boolean TEXT => *', () => { const originCellValue = 'true'; const originTypeOptions = { type: ColumnType.TEXT } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "true", "long text generic": "true", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "true", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "true", } `); }); it('transforms checkbox TEXT => *', () => { const originCellValue = 'checked'; const originTypeOptions = { type: ColumnType.TEXT } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "checked", "long text generic": "checked", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-checked", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "checked", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-checked", "status with default options": null, "status with variety statusType=DOIGN options": "stus-checked-doing", "text generic": "checked", } `); }); it('transforms LONG_TEXT => *', () => { const originCellValue = 'a\nb'; const originTypeOptions = { type: ColumnType.LONG_TEXT } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "a b", "long text generic": "a b", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-aspaceb", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "a b", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-aspaceb", "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "a b", } `); }); it('transforms NUMBER => *', () => { const originCellValue = 1; const originTypeOptions = { type: ColumnType.NUMBER, precision: 0, numberFormat: NumberFormat.DECIMAL, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1, "currency precision 2": 1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "1", "long text generic": "1", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-one", ], "number decimal precision 0": 1, "number percent precision 2": 1, "number.. currency? precision 4": 1, "phone generic": "1", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-one", "status with default options": null, "status with variety statusType=DOIGN options": "stus-one-doing", "text generic": "1", } `); }); it('transforms negative NUMBER => *', () => { const originCellValue = -1; const originTypeOptions = { type: ColumnType.NUMBER, precision: 0, numberFormat: NumberFormat.DECIMAL, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": -1, "currency precision 2": -1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "-1", "long text generic": "-1", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": -1, "number percent precision 2": -1, "number.. currency? precision 4": -1, "phone generic": "-1", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "-1", } `); }); it('transforms decimal NUMBER => *', () => { const originCellValue = 1.2345; const originTypeOptions = { type: ColumnType.NUMBER, precision: 4, numberFormat: NumberFormat.DECIMAL, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1.2345, "currency precision 2": 1.2345, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "1.2345", "long text generic": "1.2345", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 1.2345, "number percent precision 2": 1.2345, "number.. currency? precision 4": 1.2345, "phone generic": "1.2345", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "1.2345", } `); }); it('transforms big NUMBER => *', () => { const originCellValue = 12345567890; const originTypeOptions = { type: ColumnType.NUMBER, precision: 0, numberFormat: NumberFormat.DECIMAL, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 12345567890, "currency precision 2": 12345567890, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "12345567890", "long text generic": "12345567890", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 12345567890, "number percent precision 2": 12345567890, "number.. currency? precision 4": 12345567890, "phone generic": "12345567890", "rating max 10": 10, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "12345567890", } `); }); it('transforms percentage NUMBER => *', () => { const originCellValue = 0.12; const originTypeOptions = { type: ColumnType.NUMBER, precision: 0, numberFormat: NumberFormat.PERCENTAGE, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 0.12, "currency precision 2": 0.12, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "12%", "long text generic": "12%", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 0.12, "number percent precision 2": 0.12, "number.. currency? precision 4": 0.12, "phone generic": "12%", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "12%", } `); }); it('transforms one hundred percentage NUMBER => *', () => { const originCellValue = 1; const originTypeOptions = { type: ColumnType.NUMBER, precision: 1, numberFormat: NumberFormat.PERCENTAGE, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1, "currency precision 2": 1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "100.0%", "long text generic": "100.0%", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 1, "number percent precision 2": 1, "number.. currency? precision 4": 1, "phone generic": "100.0%", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "100.0%", } `); }); it('transforms extra precision decimal NUMBER => *', () => { const originCellValue = 1.2345; const originTypeOptions = { type: ColumnType.NUMBER, precision: 2, numberFormat: NumberFormat.DECIMAL, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1.2345, "currency precision 2": 1.2345, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "1.23", "long text generic": "1.23", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 1.2345, "number percent precision 2": 1.2345, "number.. currency? precision 4": 1.2345, "phone generic": "1.23", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "1.23", } `); }); it('transforms decimal with commas => *', () => { const originCellValue = 12345.6789; const originTypeOptions = { type: ColumnType.NUMBER, numberFormat: NumberFormat.DECIMAL_WITH_COMMAS, precision: 4, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 12345.6789, "currency precision 2": 12345.6789, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "12,345.6789", "long text generic": "12,345.6789", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 12345.6789, "number percent precision 2": 12345.6789, "number.. currency? precision 4": 12345.6789, "phone generic": "12,345.6789", "rating max 10": 10, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "12,345.6789", } `); }); it('transforms RATING => *', () => { const originCellValue = 1; const originTypeOptions = { type: ColumnType.RATING, ratingMax: 5, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1, "currency precision 2": 1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "1", "long text generic": "1", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-one", ], "number decimal precision 0": 1, "number percent precision 2": 0.2, "number.. currency? precision 4": 1, "phone generic": "1", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-one", "status with default options": null, "status with variety statusType=DOIGN options": "stus-one-doing", "text generic": "1", } `); }); it('transforms max RATING => *', () => { const originCellValue = 5; const originTypeOptions = { type: ColumnType.RATING, ratingMax: 5, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 5, "currency precision 2": 5, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "5", "long text generic": "5", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 5, "number percent precision 2": 1, "number.. currency? precision 4": 5, "phone generic": "5", "rating max 10": 5, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "5", } `); }); it('transforms true CHECKBOX => *', () => { const originCellValue = true; const originTypeOptions = { type: ColumnType.CHECKBOX } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "checked", "long text generic": "checked", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-checked", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "checked", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-checked", "status with default options": "stus-bar-done", "status with variety statusType=DOIGN options": "foo,bar", "text generic": "checked", } `); }); it('transforms false CHECKBOX => *', () => { const originCellValue = false; const originTypeOptions = { type: ColumnType.CHECKBOX } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "", "long text generic": "", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-emptyname", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-emptyname", "status with default options": "stus-foo-pending", "status with variety statusType=DOIGN options": "stus-foo-pending", "text generic": "", } `); }); it('transforms CURRENCY => *', () => { const originCellValue = 1; const originTypeOptions = { type: ColumnType.CURRENCY, precision: 0, currencyFormat: '$', } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1, "currency precision 2": 1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "$1", "long text generic": "$1", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 1, "number percent precision 2": 1, "number.. currency? precision 4": 1, "phone generic": "$1", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "$1", } `); }); it('transforms negative CURRENCY => *', () => { const originCellValue = -1; const originTypeOptions = { type: ColumnType.CURRENCY, precision: 0, currencyFormat: '$', } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": -1, "currency precision 2": -1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "-$1", "long text generic": "-$1", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": -1, "number percent precision 2": -1, "number.. currency? precision 4": -1, "phone generic": "-$1", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "-$1", } `); }); it('transforms large CURRENCY => *', () => { const originCellValue = 123456789; const originTypeOptions = { type: ColumnType.CURRENCY, precision: 0, currencyFormat: '$', } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 123456789, "currency precision 2": 123456789, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "$123,456,789", "long text generic": "$123,456,789", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 123456789, "number percent precision 2": 123456789, "number.. currency? precision 4": 123456789, "phone generic": "$123,456,789", "rating max 10": 10, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "$123,456,789", } `); }); it('transforms decimal CURRENCY => *', () => { const originCellValue = 1234.56789; const originTypeOptions = { type: ColumnType.CURRENCY, precision: 5, currencyFormat: '$', } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1234.56789, "currency precision 2": 1234.56789, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "$1,234.56789", "long text generic": "$1,234.56789", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 1234.56789, "number percent precision 2": 1234.56789, "number.. currency? precision 4": 1234.56789, "phone generic": "$1,234.56789", "rating max 10": 10, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "$1,234.56789", } `); }); it('transforms weird format CURRENCY => *', () => { const originCellValue = 1234567; const originTypeOptions = { type: ColumnType.CURRENCY, precision: 0, currencyFormat: 'wow I have ', } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1234567, "currency precision 2": 1234567, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "wow I have 1,234,567", "long text generic": "wow I have 1,234,567", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 1234567, "number percent precision 2": 1234567, "number.. currency? precision 4": 1234567, "phone generic": "wow I have 1,234,567", "rating max 10": 10, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "wow I have 1,234,567", } `); }); it.todo('transforms COLLABORATOR => *'); it('transforms iso DATETIME => *', () => { // NOTE: // generally, a DATETIME cell value should end in a "Z" which indicates that // it's in UTC. In this file we're omitting the "Z" so that it can be // interpreted as a local timezone and therefore the tests will pass // anywhere. Ideally we'd accomplish this by setting the local timezone in a // `beforeAll`, but neither of my attempts at doing so worked, and I'm a bit // pressed for time. const originCellValue = '2021-03-22T13:57:00.000'; const originTypeOptions = { type: ColumnType.DATETIME, dateFormat: DateFormat.ISO, timeFormat: TimeFormat.TWOFOUR_HOUR, includeTime: true, useGMT: false, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": "2021-03-22T13:57:00", "datetime ISO 24 hour useGMT": "2021-03-22T13:57:00", "datetime ISO date only": "2021-03-22T13:57:00", "datetime Local": "2021-03-22T13:57:00", "email generic": "2021-03-22 13:57", "long text generic": "2021-03-22 13:57", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "2021-03-22 13:57", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "2021-03-22 13:57", } `); }); it('transforms friendly DATETIME => *', () => { const originCellValue = '2021-03-22T13:57:00.000'; const originTypeOptions = { type: ColumnType.DATETIME, dateFormat: DateFormat.FRIENDLY, timeFormat: TimeFormat.TWELVE_HOUR, includeTime: true, useGMT: false, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": "2021-03-22T13:57:00", "datetime ISO 24 hour useGMT": "2021-03-22T13:57:00", "datetime ISO date only": "2021-03-22T13:57:00", "datetime Local": "2021-03-22T13:57:00", "email generic": "Mar 22nd, 2021 1:57 pm", "long text generic": "Mar 22nd, 2021 1:57 pm", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "Mar 22nd, 2021 1:57 pm", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "Mar 22nd, 2021 1:57 pm", } `); }); it('transforms local DATETIME => *', () => { const originCellValue = '2021-03-22T13:57:00.000'; const originTypeOptions = { type: ColumnType.DATETIME, dateFormat: DateFormat.LOCAL, timeFormat: TimeFormat.TWELVE_HOUR, includeTime: true, useGMT: false, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": "2021-03-22T13:57:00", "datetime ISO 24 hour useGMT": "2021-03-22T13:57:00", "datetime ISO date only": "2021-03-22T13:57:00", "datetime Local": "2021-03-22T13:57:00", "email generic": "03/22/2021 1:57 pm", "long text generic": "03/22/2021 1:57 pm", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "03/22/2021 1:57 pm", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "03/22/2021 1:57 pm", } `); }); it('transforms timeless DATE => *', () => { const originCellValue = '2021-03-22T13:57:00.000'; const originTypeOptions = { type: ColumnType.DATETIME, dateFormat: DateFormat.ISO, timeFormat: TimeFormat.TWELVE_HOUR, includeTime: false, useGMT: false, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": "2021-03-22T13:57:00", "datetime ISO 24 hour useGMT": "2021-03-22T13:57:00", "datetime ISO date only": "2021-03-22T13:57:00", "datetime Local": "2021-03-22T13:57:00", "email generic": "2021-03-22", "long text generic": "2021-03-22", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-adate", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "2021-03-22", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-adate", "status with default options": null, "status with variety statusType=DOIGN options": "stus-date-doing", "text generic": "2021-03-22", } `); }); it('transforms EMAIL => *', () => { const originCellValue = 'foo@bar.com'; const originTypeOptions = { type: ColumnType.EMAIL } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo@bar.com", "long text generic": "foo@bar.com", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-email", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo@bar.com", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-email", "status with default options": null, "status with variety statusType=DOIGN options": "stus-email-doing", "text generic": "foo@bar.com", } `); }); it('transforms PHONE => *', () => { const originCellValue = '(123) 456-7890'; const originTypeOptions = { type: ColumnType.PHONE } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "(123) 456-7890", "long text generic": "(123) 456-7890", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "(123) 456-7890", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "(123) 456-7890", } `); }); it('transforms UNIQUE_ID => *', () => { const originCellValue = '0x1234567890'; const originTypeOptions = { type: ColumnType.UNIQUE_ID } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "0x1234567890", "long text generic": "0x1234567890", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "0x1234567890", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "0x1234567890", } `); }); it('transforms text STATUS => *', () => { const originCellValue = 'stus-foo-pending'; const originTypeOptions = { type: ColumnType.STATUS, statuses: [ { statusId: 'stus-foo-pending', name: 'foo', order: 1, type: StatusType.PENDING, }, { statusId: 'stus-bar-doing', name: 'bar', order: 2, type: StatusType.DOING, }, { statusId: 'stus-foobar-done', name: 'foo,bar', order: 3, type: StatusType.DONE, }, ] as IStatus[], } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo", "long text generic": "foo", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-foo", "status with default options": "stus-foo-pending", "status with variety statusType=DOIGN options": "stus-foo-pending", "text generic": "foo", } `); }); it('transforms number STATUS => *', () => { const originCellValue = 'stus-foo-pending'; const originTypeOptions = { type: ColumnType.STATUS, statuses: [ { statusId: 'stus-foo-pending', name: '1', order: 1, type: StatusType.PENDING, }, { statusId: 'stus-bar-doing', name: 'bar', order: 2, type: StatusType.DOING, }, { statusId: 'stus-foobar-done', name: 'foo,bar', order: 3, type: StatusType.DONE, }, ] as IStatus[], } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1, "currency precision 2": 1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "1", "long text generic": "1", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-one", ], "number decimal precision 0": 1, "number percent precision 2": 1, "number.. currency? precision 4": 1, "phone generic": "1", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-one", "status with default options": "stus-foo-pending", "status with variety statusType=DOIGN options": "stus-foo-pending", "text generic": "1", } `); }); it('transforms date STATUS => *', () => { const originCellValue = 'stus-bar-doing'; const originTypeOptions = { type: ColumnType.STATUS, statuses: [ { statusId: 'stus-foo-pending', name: 'foo', order: 1, type: StatusType.PENDING, }, { statusId: 'stus-bar-doing', name: '2021-03-22', order: 2, type: StatusType.DOING, }, { statusId: 'stus-foobar-done', name: 'foo,bar', order: 3, type: StatusType.DONE, }, ] as IStatus[], } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 2021, "currency precision 2": 2021, "datetime Friendly 12 hour": "2021-03-22T00:00:00", "datetime ISO 24 hour useGMT": "2021-03-22T00:00:00", "datetime ISO date only": "2021-03-22T00:00:00", "datetime Local": "2021-03-22T00:00:00", "email generic": "2021-03-22", "long text generic": "2021-03-22", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-adate", ], "number decimal precision 0": 2021, "number percent precision 2": 2021, "number.. currency? precision 4": 2021, "phone generic": "2021-03-22", "rating max 10": 10, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-adate", "status with default options": null, "status with variety statusType=DOIGN options": "stus-bar-doing", "text generic": "2021-03-22", } `); }); it('transforms text SELECT => *', () => { const originCellValue = 'sel1'; const originTypeOptions = { type: ColumnType.SELECT, options: [ { optionId: 'sel1', name: 'foo', color: SelectColor.blackDarkest }, ] as ISelect[], } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo", "long text generic": "foo", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-foo", "status with default options": "stus-foo-pending", "status with variety statusType=DOIGN options": "stus-foo-pending", "text generic": "foo", } `); }); it('transforms number SELECT => *', () => { const originCellValue = 'sel1'; const originTypeOptions = { type: ColumnType.SELECT, options: [ { optionId: 'sel1', name: '1', color: SelectColor.blackDarkest }, ] as ISelect[], } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1, "currency precision 2": 1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "1", "long text generic": "1", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-one", ], "number decimal precision 0": 1, "number percent precision 2": 1, "number.. currency? precision 4": 1, "phone generic": "1", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-one", "status with default options": null, "status with variety statusType=DOIGN options": "stus-one-doing", "text generic": "1", } `); }); it('transforms date SELECT => *', () => { const originCellValue = 'sel1'; const originTypeOptions = { type: ColumnType.SELECT, options: [ { optionId: 'sel1', name: '2021-03-22', color: SelectColor.blackDarkest, }, ] as ISelect[], } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 2021, "currency precision 2": 2021, "datetime Friendly 12 hour": "2021-03-22T00:00:00", "datetime ISO 24 hour useGMT": "2021-03-22T00:00:00", "datetime ISO date only": "2021-03-22T00:00:00", "datetime Local": "2021-03-22T00:00:00", "email generic": "2021-03-22", "long text generic": "2021-03-22", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-adate", ], "number decimal precision 0": 2021, "number percent precision 2": 2021, "number.. currency? precision 4": 2021, "phone generic": "2021-03-22", "rating max 10": 10, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-adate", "status with default options": null, "status with variety statusType=DOIGN options": "stus-date-doing", "text generic": "2021-03-22", } `); }); it('transforms text MULTI_SELECT => *', () => { const originCellValue = ['sel1', 'sel2']; const originTypeOptions = { type: ColumnType.MULTI_SELECT, options: [ { optionId: 'sel1', name: 'foo', color: SelectColor.blackDarkest }, { optionId: 'sel2', name: 'bar', color: SelectColor.blueDarkest }, ] as ISelect[], } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo, bar", "long text generic": "foo, bar", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", "mulsel-bar", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo, bar", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-foo", "status with default options": "stus-foo-pending", "status with variety statusType=DOIGN options": "stus-foo-pending", "text generic": "foo, bar", } `); }); it('transforms MULTI_ATTACHMENT => *', () => { const originCellValue = [ { fileId: 'fileName', fileKey: 'id/fileName.png', fileName: 'fileName.png', fileSize: 0, fileType: 'image/png', largeThumbUrl: 'https://www.treelab.com.cn/id/fileName.png?x-oss-process=style/high', mediumThumbUrl: 'https://www.treelab.com.cn/id/fileName.png?x-oss-process=style/middle', smallThumbUrl: 'https://www.treelab.com.cn/id/fileName.png?x-oss-process=style/low', url: 'https://www.treelab.com.cn/id/fileName.png', }, ]; const originTypeOptions = { type: ColumnType.MULTI_ATTACHMENT } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "fileName.png (https://www.treelab.com.cn/id/fileName.png)", "long text generic": "fileName.png (https://www.treelab.com.cn/id/fileName.png)", "multi attachment generic": Array [ Object { "fileId": "fileName", "fileKey": "id/fileName.png", "fileName": "fileName.png", "fileSize": 0, "fileType": "image/png", "largeThumbUrl": "https://www.treelab.com.cn/id/fileName.png?x-oss-process=style/high", "mediumThumbUrl": "https://www.treelab.com.cn/id/fileName.png?x-oss-process=style/middle", "smallThumbUrl": "https://www.treelab.com.cn/id/fileName.png?x-oss-process=style/low", "url": "https://www.treelab.com.cn/id/fileName.png", }, ], "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-filename", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "fileName.png (https://www.treelab.com.cn/id/fileName.png)", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-filename", "status with default options": "stus-foo-pending", "status with variety statusType=DOIGN options": "stus-foo-pending", "text generic": "fileName.png (https://www.treelab.com.cn/id/fileName.png)", } `); }); it('transforms FORMULA => *', () => { const originCellValue = 'foo'; const originTypeOptions = { type: ColumnType.FORMULA, formula: 'foo', resultType: FormulaResultType.TEXT, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo", "long text generic": "foo", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-foo", "status with default options": "stus-foo-pending", "status with variety statusType=DOIGN options": "stus-foo-pending", "text generic": "foo", } `); }); it('transforms FORMULA => *', () => { const originCellValue = '1'; const originTypeOptions = { type: ColumnType.FORMULA, formula: '1', resultType: FormulaResultType.NUMBER, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 1, "currency precision 2": 1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "1.0", "long text generic": "1.0", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 1, "number percent precision 2": 1, "number.. currency? precision 4": 1, "phone generic": "1.0", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "1.0", } `); }); it('transforms FORMULA => *', () => { const originCellValue = '2021-03-22'; const originTypeOptions = { type: ColumnType.FORMULA, formula: '2021-03-22', resultType: FormulaResultType.DATE, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 3222021, "currency precision 2": 3222021, "datetime Friendly 12 hour": "2021-03-22T00:00:00", "datetime ISO 24 hour useGMT": "2021-03-22T00:00:00", "datetime ISO date only": "2021-03-22T00:00:00", "datetime Local": "2021-03-22T00:00:00", "email generic": "03/22/2021", "long text generic": "03/22/2021", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": null, "number decimal precision 0": 3222021, "number percent precision 2": 3222021, "number.. currency? precision 4": 3222021, "phone generic": "03/22/2021", "rating max 10": 10, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "03/22/2021", } `); }); it('transforms RECORD_REFERENCE => *', () => { const originCellValue = [ { id: 'row1', visibleName: 'foo' }, { id: 'row2', visibleName: '1' }, { id: 'row3', visibleName: '2021-03-22' }, { id: 'row4', visibleName: 'foo, bar' }, ]; const originTypeOptions = { type: ColumnType.RECORD_REFERENCE, foreignTableId: 'tab4834', } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo, 1, 2021-03-22, foo, bar", "long text generic": "foo, 1, 2021-03-22, foo, bar", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", "mulsel-one", "mulsel-adate", "mulsel-foobar", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo, 1, 2021-03-22, foo, bar", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "foo, 1, 2021-03-22, foo, bar", } `); }); it('transforms number ROLLUP => *', () => { const originCellValue = 'foo'; const originTypeOptions = { type: ColumnType.ROLLUP, formula: 'foo', resultType: FormulaResultType.TEXT, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo", "long text generic": "foo", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-foo", "status with default options": "stus-foo-pending", "status with variety statusType=DOIGN options": "stus-foo-pending", "text generic": "foo", } `); }); it('transforms LOOKUP(TEXT) => *', () => { const originCellValue = ['foo', 'bar', 'foo, bar', '1', '2021-03-22']; const originTypeOptions = { type: ColumnType.LOOKUP, recordReferenceColumnId: 'col1', foreignLookupColumnId: 'col2', lookupColumnType: ColumnType.TEXT, lookupTypeOptions: { type: ColumnType.TEXT }, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo, bar, foo, bar, 1, 2021-03-22", "long text generic": "foo, bar, foo, bar, 1, 2021-03-22", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", "mulsel-bar", "mulsel-foobar", "mulsel-one", "mulsel-adate", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo, bar, foo, bar, 1, 2021-03-22", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "foo, bar, foo, bar, 1, 2021-03-22", } `); }); it('transforms single value LOOKUP(TEXT) => *', () => { const originCellValue = ['foo']; const originTypeOptions = { type: ColumnType.LOOKUP, recordReferenceColumnId: 'col1', foreignLookupColumnId: 'col2', lookupColumnType: ColumnType.TEXT, lookupTypeOptions: { type: ColumnType.TEXT, }, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo", "long text generic": "foo", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-foo", "status with default options": "stus-foo-pending", "status with variety statusType=DOIGN options": "stus-foo-pending", "text generic": "foo", } `); }); it('transforms LOOKUP(NUMBER) => *', () => { const originCellValue = [6, 1.0, -1, 1234, 2345.6789]; const originTypeOptions = { type: ColumnType.LOOKUP, recordReferenceColumnId: 'col1', foreignLookupColumnId: 'col2', lookupColumnType: ColumnType.NUMBER, lookupTypeOptions: { type: ColumnType.NUMBER, numberFormat: NumberFormat.DECIMAL, precision: 2, }, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 6, "currency precision 2": 6, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "6.00, 1.00, -1.00, 1234.00, 2345.68", "long text generic": "6.00, 1.00, -1.00, 1234.00, 2345.68", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-onepointzerozero", ], "number decimal precision 0": 6, "number percent precision 2": 6, "number.. currency? precision 4": 6, "phone generic": "6.00, 1.00, -1.00, 1234.00, 2345.68", "rating max 10": 6, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "6.00, 1.00, -1.00, 1234.00, 2345.68", } `); }); it('transforms LOOKUP(STATUS) => *', () => { const originCellValue = ['stus-bar-doing', 'stus-foobar-done']; const originTypeOptions = { type: ColumnType.LOOKUP, recordReferenceColumnId: 'col1', foreignLookupColumnId: 'col2', lookupColumnType: ColumnType.STATUS, lookupTypeOptions: { type: ColumnType.STATUS, statuses: [ { statusId: 'stus-foo-pending', name: 'foo', order: 1, type: StatusType.PENDING, }, { statusId: 'stus-bar-doing', name: 'bar', order: 2, type: StatusType.DOING, }, { statusId: 'stus-foobar-done', name: 'foo,bar', order: 3, type: StatusType.DONE, }, ] as IStatus[], }, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "bar, foo,bar", "long text generic": "bar, foo,bar", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-bar", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "bar, foo,bar", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "bar, foo,bar", } `); }); it('transforms LOOKUP(SELECT) => *', () => { const originCellValue = ['sel1', 'sel2', 'sel3', 'sel4']; const originTypeOptions = { type: ColumnType.LOOKUP, recordReferenceColumnId: 'col1', foreignLookupColumnId: 'col2', lookupColumnType: ColumnType.SELECT, lookupTypeOptions: { type: ColumnType.SELECT, options: [ { name: 'foo', optionId: 'sel1', color: SelectColor.blackDarkest }, { name: 'bar', optionId: 'sel2', color: SelectColor.blackDarkest }, { name: 'foo, bar', optionId: 'sel3', color: SelectColor.blackDarkest, }, { name: '1', optionId: 'sel4', color: SelectColor.blackDarkest }, ] as ISelect[], }, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": null, "currency precision 2": null, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo, bar, foo, bar, 1", "long text generic": "foo, bar, foo, bar, 1", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", "mulsel-bar", "mulsel-foobar", "mulsel-one", ], "number decimal precision 0": null, "number percent precision 2": null, "number.. currency? precision 4": null, "phone generic": "foo, bar, foo, bar, 1", "rating max 10": null, "rating max 5": null, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-foo", "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "foo, bar, foo, bar, 1", } `); }); it('transforms LOOKUP(MULTI_SELECT) => *', () => { const originCellValue = [ 'sel1', // 'sel2', 'sel3', // 'sel1', 'sel3', // 'sel1', 'sel2', 'sel4', 'sel3', ]; const originTypeOptions = { type: ColumnType.LOOKUP, recordReferenceColumnId: 'col1', foreignLookupColumnId: 'col2', lookupColumnType: ColumnType.MULTI_SELECT, lookupTypeOptions: { type: ColumnType.MULTI_SELECT, options: [ { name: 'foo', optionId: 'sel1', color: SelectColor.blackDarkest }, { name: 'bar', optionId: 'sel2', color: SelectColor.blackDarkest }, { name: 'foo, bar', optionId: 'sel3', color: SelectColor.blackDarkest, }, { name: '1', optionId: 'sel4', color: SelectColor.blackDarkest }, ] as ISelect[], }, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": false, "collaborator generic": null, "currency precision 0": 1, "currency precision 2": 1, "datetime Friendly 12 hour": null, "datetime ISO 24 hour useGMT": null, "datetime ISO date only": null, "datetime Local": null, "email generic": "foo, bar, foo, bar, foo, foo, bar, foo, bar, 1, foo, bar", "long text generic": "foo, bar, foo, bar, foo, foo, bar, foo, bar, 1, foo, bar", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-foo", "mulsel-bar", "mulsel-foobar", "mulsel-one", ], "number decimal precision 0": 1, "number percent precision 2": 1, "number.. currency? precision 4": 1, "phone generic": "foo, bar, foo, bar, foo, foo, bar, foo, bar, 1, foo, bar", "rating max 10": 1, "rating max 5": 1, "record reference generic": null, "select with no options": null, "select with variety of options": "snglsel-foo", "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "foo, bar, foo, bar, foo, foo, bar, foo, bar, 1, foo, bar", } `); }); it('transforms LOOKUP(DATETIME) => *', () => { const originCellValue = [ '2020-01-22T13:57:00.000', '2021-03-22T13:57:00.000', ]; const originTypeOptions = { type: ColumnType.LOOKUP, recordReferenceColumnId: 'col1', foreignLookupColumnId: 'col2', lookupColumnType: ColumnType.DATETIME, lookupTypeOptions: { type: ColumnType.DATETIME, dateFormat: DateFormat.ISO, timeFormat: TimeFormat.TWELVE_HOUR, includeTime: false, useGMT: false, }, } as const; expect( getTransformedCellValues({ originCellValue, originTypeOptions, }) ).toMatchInlineSnapshot(` Object { "checkbox generic": true, "collaborator generic": null, "currency precision 0": 2020, "currency precision 2": 2020, "datetime Friendly 12 hour": "2020-01-22T00:00:00", "datetime ISO 24 hour useGMT": "2020-01-22T00:00:00", "datetime ISO date only": "2020-01-22T00:00:00", "datetime Local": "2020-01-22T00:00:00", "email generic": "2020-01-22, 2021-03-22", "long text generic": "2020-01-22, 2021-03-22", "multi attachment generic": null, "multi select with no options": null, "multi select with variety of options": Array [ "mulsel-adate", ], "number decimal precision 0": 2020, "number percent precision 2": 2020, "number.. currency? precision 4": 2020, "phone generic": "2020-01-22, 2021-03-22", "rating max 10": 10, "rating max 5": 5, "record reference generic": null, "select with no options": null, "select with variety of options": null, "status with default options": null, "status with variety statusType=DOIGN options": null, "text generic": "2020-01-22, 2021-03-22", } `); }); }); });