import { ControlMock } from "../../controls/control/control.mock" ; import { OptionSetControlMock } from "../../controls/optionsetcontrol/optionsetcontrol.mock" ; import { OptionSetValueMock } from "../../optionsetvalue/optionsetvalue.mock" ; import { EnumAttributeMock , IEnumAttributeComponents } from "../enumattribute/enumattribute.mock" ; export class OptionSetAttributeMock extends EnumAttributeMock < OptionSetControlMock , number > implements Xrm . Attributes . OptionSetAttribute { public static create ( name , value ? ) { return new OptionSetAttributeMock ( { name , value } ) ; } private static defaultComponents ( components ) { components . attributeType = "optionset" ; return components ; } public options : OptionSetValueMock [ ] ; public selectedOption : OptionSetValueMock ; constructor ( components ) { super ( OptionSetAttributeMock . defaultComponents ( components ) ) ; this . options = components . options ? components . options . map ( ( o ) => { return new OptionSetValueMock ( o . text , o . value ) ; } ) : components . value || components . value === 0 ? [ { text : components . value . toString ( ) , value : components . value , } ] : [ ] ; this . format = components . format || "language" ; this . selectedOption = this . getOption ( this . getValue ( ) ) ; } public getFormat ( ) { return super . getFormat ( ) as Xrm . Attributes . OptionSetAttributeFormat ; } public getOption ( param ) { return typeof param === "number" ? this . options . filter ( ( o ) => o . value === param ) [ 0 ] : this . options . filter ( ( o ) => o . text === param ) [ 0 ] ; } public getOptions ( ) { return this . options ; } public getSelectedOption ( ) { return this . selectedOption ; } public getText ( ) { return this . selectedOption . text ; } public setValue ( value ) { super . setValue ( value ) ; this . selectedOption = this . getOption ( value ) ; } } export interface IOptionSetAttributeComponents extends IEnumAttributeComponents < OptionSetControlMock , number > { format ? : Xrm . Attributes . OptionSetAttributeFormat ; options ? : Xrm . OptionSetValue [ ] ; selectedOption ? : Xrm . OptionSetValue ; }