import { findIndex } from "../../../xrm-mock-generator/helpers/array.helper" ; import { ItemCollectionMock } from "../../collection/itemcollection/itemcollection.mock" ; import { SectionMock } from "../section/section.mock" ; import { UiCanGetVisibleElementMock } from "../uicangetvisibleelement/uicangetvisibleelement.mock" ; import { UiFocusableMock } from "../uifocusable/uifocusable.mock" ; import { UiLabelElementMock } from "../uilabelelement/uilabelelement.mock" ; import { UiStandardElementMock } from "../uistandardelement/uistandardelement.mock" ; export class TabMock implements Xrm . Controls . Tab { public sections : Xrm . Collection . ItemCollection < Xrm . Controls . Section > ; public tabStateChangeHandlers : Xrm . Events . ContextSensitiveHandler [ ] ; private uiStandardElement : Xrm . Controls . UiStandardElement ; private uiFocusableElement : Xrm . Controls . UiFocusable ; private name : string ; private parent : Xrm . Ui ; private displayState : Xrm . DisplayState ; constructor ( components ) { this . uiStandardElement = components . uiStandardElement || new UiStandardElementMock ( new UiLabelElementMock ( components . name ) , new UiCanGetVisibleElementMock ( true ) ) ; this . uiFocusableElement = components . uiFocusableElement || new UiFocusableMock ( false ) ; this . name = components . name ; this . parent = components . parent ; this . displayState = components . displayState || "expanded" ; this . tabStateChangeHandlers = components . tabStateChangeHandlers || [ ] as Xrm . Events . ContextSensitiveHandler [ ] ; this . sections = components . sections || new ItemCollectionMock ( [ ] ) ; this . sections . forEach ( ( section , index ) => { const sectionMock = section as SectionMock ; if ( sectionMock ) { sectionMock . parent = this ; } } ) ; } public getDisplayState ( ) { return this . displayState ; } public getName ( ) { return this . name ; } public getParent ( ) { return this . parent ; } public setDisplayState ( displayState ) { this . displayState = displayState ; } public setVisible ( visible ) { return this . uiStandardElement . setVisible ( visible ) ; } public getVisible ( ) { return this . uiStandardElement . getVisible ( ) ; } public getLabel ( ) { return this . uiStandardElement . getLabel ( ) ; } public setLabel ( label ) { return this . uiStandardElement . setLabel ( label ) ; } public setFocus ( ) { return this . uiFocusableElement . setFocus ( ) ; } public addTabStateChange ( handler ) { this . tabStateChangeHandlers . push ( handler ) ; } public removeTabStateChange ( handler ) { const index = findIndex ( this . tabStateChangeHandlers , handler ) ; this . tabStateChangeHandlers . splice ( index , 1 ) ; } } export interface ITabComponents { uiStandardElement ? : Xrm . Controls . UiStandardElement ; uiFocusableElement ? : Xrm . Controls . UiFocusable ; name ? : string ; parent ? : Xrm . Ui ; displayState ? : Xrm . DisplayState ; sections ? : Xrm . Collection . ItemCollection < Xrm . Controls . Section > ; tabStateChangeHandlers ? : Xrm . Events . ContextSensitiveHandler [ ] ; }