Lai,Risheng
2023-11-02 30c02e0c981b16be0918483543f4b812956c45d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { DialogSOP } from '../../libappsop/dialogsop';
import { DropDownListSOP } from '../../libappsop/dropdownlistsop';
import { DropDownStringListSOP } from '../../libappsop/dropdownstringlistsop';
import { EditFieldSOP } from '../../libappsop/editfieldsop';
 
export interface DialogAccountFields {
  Name?: string;
  ParentAccountName?: string;
  AccountType?: string;
  ReportType?: string;
  Budget?: string;
  CostDriver?: string;
  Cost?: string;
  TimeUnit?: string;
  LengthOfTime?: string;
}
 
export class DialogAccount extends DialogSOP<DialogAccountFields> {
  public static readonly title = 'Accounts';
 
  public ddlParentAccount = new DropDownListSOP('DropDownListParentAccount');
  public efName = new EditFieldSOP('EditFieldName');
  public ddlAccountType = new DropDownListSOP('DropDownListAccountType');
  public efReportType = new EditFieldSOP('EditFieldReportType');
  public efBudget = new EditFieldSOP('EditFieldBudget');
  public ddlCostDriver = new DropDownStringListSOP('DropDownStringListDefaultCostDriver');
  public efCost = new EditFieldSOP('EditFieldCost');
  public ddlTimeUnit = new DropDownStringListSOP('DropDownStringListTimeUnit');
  public efLengthOfTime = new EditFieldSOP('EditFieldLengthOfTime');
 
  public constructor() {
    super('DialogCreateEditAccountStructure');
 
    // Set UI element mapping to pair the UI name to the UI element for use in DialogSOP to find the UI object to set value or verify value
    // This prevents each new Dialog to duplicate code just to set/verify UI element value
    this._uiMap.set('Name', this.efName);
    this._uiMap.set('ParentAccountName', this.ddlParentAccount);
    this._uiMap.set('AccountType', this.ddlAccountType);
    this._uiMap.set('ReportType', this.efReportType);
    this._uiMap.set('Budget', this.efBudget);
    this._uiMap.set('CostDriver', this.ddlCostDriver);
    this._uiMap.set('Cost', this.efCost);
    this._uiMap.set('TimeUnit', this.ddlTimeUnit);
    this._uiMap.set('LengthOfTime', this.efLengthOfTime);
  }
 
  public async createEditAccount(name?: string, costDriver?: string, cost?: string, timeUnit?: string, lengthOfTime?: string): Promise<boolean> {
    if (name && !(await this.efName.isDisabled())) {
      await this.efName.sendInput(name);
    }
 
    if (costDriver && (await this.ddlCostDriver.getSelectedString()) !== costDriver) {
      await this.ddlCostDriver.selectItem(costDriver);
    }
 
    // Wait until the Cost field is present which will appear only after selecting Cost Driver
    if (cost) {
      await this.efCost.waitUntilPresent();
      await this.efCost.sendInput(cost);
    }
 
    if (timeUnit && (await this.ddlTimeUnit.isVisible())) {
      await this.ddlTimeUnit.selectItem(timeUnit);
    }
    if (lengthOfTime) {
      await this.efLengthOfTime.sendInput(lengthOfTime);
    }
 
    return this.clickOK();
  }
 
  /**
   * Get precondition feedback text on the OK button
   *
   * @returns Precondition feedback text in string
   */
  public async getOKButtonTooltip(): Promise<string> {
    return this.btnOk.getTooltip();
  }
}