import * as playwright from "playwright" ; import { EnsureXrmGetter } from "./Global" ; import { XrmUiTest } from "./XrmUITest" ; /**
 * Scheme to describe a form reference
 * Either by name or by id
 */ export interface FormIdentifier { /**
     * The name of the form
     */ byName ? : string ; /**
     * The id of the form
     */ byId ? : string ; } /**
 * Scheme to describe items of form selector
 */ export interface FormSelectorItem { /**
     * Id of the form
     */ id ? : string ; /**
     * Label of the form
     */ label ? : string ; } /**
 * Module for interacting with D365 Forms
 */ export class Form { private _page : playwright . Page ; constructor ( private xrmUiTest ) { this . _page = xrmUiTest . page ; this . xrmUiTest = xrmUiTest ; } returns deprecated reset = async ( ) => { return this . noSubmit ( ) ; } ; returns noSubmit = async ( ) => { await EnsureXrmGetter ( this . _page ) ; return this . _page . evaluate ( ( ) => { const xrm = window . oss_FindXrm ( ) ; xrm . Page . getAttribute ( ) . forEach ( a => a . setSubmitMode ( "never" ) ) ; } ) ; } ; returns getCurrentFormSelectorItem = async ( ) : Promise < FormSelectorItem > => { await EnsureXrmGetter ( this . _page ) ; return this . _page . evaluate ( ( ) => { const xrm = window . oss_FindXrm ( ) ; const form = xrm . Page . ui . formSelector . getCurrentItem ( ) ; return { id : form . getId ( ) , label : form . getLabel ( ) } ; } ) ; } ; returns getAvailableFormSelectorItems = async ( ) : Promise < Array < FormSelectorItem > > => { await EnsureXrmGetter ( this . _page ) ; return this . _page . evaluate ( ( ) => { const xrm = window . oss_FindXrm ( ) ; return xrm . Page . ui . formSelector . items . get ( ) . map ( i => ( { id : i . getId ( ) , label : i . getLabel ( ) } ) ) ; } ) ; } ; param identifier returns switch = async ( identifier ) => { await EnsureXrmGetter ( this . _page ) ; if ( identifier . byId ) { return Promise . all ( [ this . _page . evaluate ( ( i ) => { const xrm = window . oss_FindXrm ( ) ; ( xrm . Page . ui . formSelector . items . get ( i ) as any ) . navigate ( ) ; } , identifier . byId ) , this . xrmUiTest . waitForIdleness ( ) ] ) ; } else if ( identifier . byName ) { return Promise . all ( [ this . _page . evaluate ( ( i ) => { const xrm = window . oss_FindXrm ( ) ; ( xrm . Page . ui . formSelector . items as any ) . getByFilter ( ( f ) => f . _label === i ) . navigate ( ) ; } , identifier . byName ) , this . xrmUiTest . waitForIdleness ( ) ] ) ; } else { throw new Error ( "Choose to search by id or name" ) ; } } ; }