import { ValueStatus , EditableValue } from "mendix" ; import { Big } from "big.js" ; type Writable < T > = { - readonly [ K in keyof T ] : T [ K ] ; } ; export enum FormatterType { Number = "number" , DateTime = "datetime" } export class EditableValueBuilder < T extends string | boolean | Date | Big > { private readonly editableValue : Writable < EditableValue < T > > = { value : undefined , displayValue : "" , status : ValueStatus . Available , validation : undefined , readOnly : false , formatter : { format : jest . fn ( name => `Formatted ${ name }` ) , parse : jest . fn ( ) , withConfig : jest . fn ( ( ) => new EditableValueBuilder ( ) . build ( ) . formatter ) as any , getFormatPlaceholder : jest . fn ( ) , type : FormatterType . DateTime as any , config : { } as any } , setValidator : jest . fn ( ) , setValue : jest . fn ( ( value ) => this . withValue ( value ) ) , setTextValue : jest . fn ( ) , setFormatter : jest . fn ( ) } ; withValue ( value ? ) { this . editableValue . value = value ; this . editableValue . displayValue = this . editableValue . formatter . format ( value ) ; return this ; } withFormatter ( formatter ) { this . editableValue . formatter = formatter ; return this ; } isReadOnly ( ) { this . editableValue . readOnly = true ; return this ; } isLoading ( ) { this . editableValue . status = ValueStatus . Loading ; return this . isReadOnly ( ) ; } isUnavailable ( ) { this . editableValue . status = ValueStatus . Unavailable ; return this . isReadOnly ( ) ; } withValidation ( validation ? ) { this . editableValue . validation = validation ; return this ; } withUniverse ( ... values ) { this . editableValue . universe = values ; return this ; } build ( ) { return this . editableValue ; } }