import { ColumnType, SelectColor } from '../../types'; import { StatusType } from '../../types/graphql-global-types'; import { transformCellValueToStatus } from './transformCellValueToStatus'; describe('transformCellValueToStatus', () => { it('returns notFound=true when a matching status option is not found', () => { expect( transformCellValueToStatus({ originCellValue: 'foo', originTypeOptions: { type: ColumnType.TEXT }, targetTypeOptions: { statuses: [ { name: 'bar1', statusId: 'status1', order: 1, type: StatusType.PENDING, }, { name: 'bar2', statusId: 'status2', order: 2, color: SelectColor.blackLightest, type: StatusType.DOING, }, { name: 'bar3', statusId: 'status3', order: 3, color: SelectColor.greenDarkest, type: StatusType.DONE, }, ], }, }).optionNotFound ).toBe(true); }); it('returns notFound=false when a matching status option is found', () => { expect( transformCellValueToStatus({ originCellValue: 'foo', originTypeOptions: { type: ColumnType.TEXT }, targetTypeOptions: { statuses: [ { name: 'foo', statusId: 'status1', order: 1, type: StatusType.PENDING, }, { name: 'bar2', statusId: 'status2', order: 2, color: SelectColor.blackLightest, type: StatusType.DOING, }, { name: 'bar3', statusId: 'status3', order: 3, color: SelectColor.greenDarkest, type: StatusType.DONE, }, ], }, }).optionNotFound ).toBe(false); }); it('returns notFound=false when the input is empty and the options has type=PENDING', () => { expect( transformCellValueToStatus({ originCellValue: '', originTypeOptions: { type: ColumnType.TEXT }, targetTypeOptions: { statuses: [ { name: 'foo', statusId: 'status1', order: 1, type: StatusType.PENDING, }, { name: 'bar2', statusId: 'status2', order: 2, type: StatusType.DOING, }, { name: 'bar3', statusId: 'status3', order: 3, type: StatusType.DONE, }, ], }, }).optionNotFound ).toBe(false); }); it('returns right statusId when a matching status option is found', () => { expect( transformCellValueToStatus({ originCellValue: 'sel1', originTypeOptions: { type: ColumnType.SELECT, options: [ { optionId: 'sel1', name: 'foo', color: SelectColor.blackDarkest, }, ], }, targetTypeOptions: { statuses: [ { name: 'foo', statusId: 'status1', order: 1, type: StatusType.PENDING, }, { name: 'bar2', statusId: 'status2', order: 2, color: SelectColor.blackLightest, type: StatusType.DOING, }, { name: 'bar3', statusId: 'status3', order: 3, color: SelectColor.greenDarkest, type: StatusType.DONE, }, ], }, }).statusId ).toBe('status1'); }); it('returns null when a matching status option is not found', () => { expect( transformCellValueToStatus({ originCellValue: 'sel1', originTypeOptions: { type: ColumnType.SELECT, options: [ { optionId: 'sel1', name: 'foo', color: SelectColor.blackDarkest, }, ], }, targetTypeOptions: { statuses: [ { name: 'bar1', statusId: 'status1', order: 1, type: StatusType.PENDING, }, { name: 'bar2', statusId: 'status2', color: SelectColor.blackLightest, order: 2, type: StatusType.DOING, }, { name: 'bar3', statusId: 'status3', order: 3, type: StatusType.DONE, }, ], }, }).statusId ).toBe(null); }); it('returns type=DONE‘s statusId when CHECKBOX is checked', () => { expect( transformCellValueToStatus({ originCellValue: true, originTypeOptions: { type: ColumnType.CHECKBOX }, targetTypeOptions: { statuses: [ { name: 'bar1', statusId: 'status1', order: 1, type: StatusType.PENDING, }, { name: 'bar2', statusId: 'status2', order: 2, type: StatusType.DOING, }, { name: 'bar3', statusId: 'status3', order: 3, type: StatusType.DONE, }, ], }, }).statusId ).toBe('status3'); }); it('returns type=PENDING‘s statusId when CHECKBOX is unchecked', () => { expect( transformCellValueToStatus({ originCellValue: false, originTypeOptions: { type: ColumnType.CHECKBOX }, targetTypeOptions: { statuses: [ { name: 'bar1', statusId: 'status1', order: 1, type: StatusType.PENDING, }, { name: 'bar2', statusId: 'status2', order: 2, type: StatusType.DOING, }, { name: 'bar3', statusId: 'status3', order: 3, type: StatusType.DONE, }, ], }, }).statusId ).toBe('status1'); }); it('returns type=PENDING‘s statusId when column type is 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', }, ]; expect( transformCellValueToStatus({ originCellValue, originTypeOptions: { type: ColumnType.MULTI_ATTACHMENT, }, targetTypeOptions: { statuses: [ { name: 'bar1', statusId: 'status1', order: 1, type: StatusType.PENDING, }, { name: 'bar2', statusId: 'status2', order: 2, type: StatusType.DOING, }, { name: 'bar3', statusId: 'status3', order: 3, type: StatusType.DONE, }, ], }, }).statusId ).toBe('status1'); }); });