haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { DialogBase } from '../../libappbase/dialogbase';
import { EditField } from '../../e2elib/lib/src/pageobjects/editfield.component';
import { compareDateFromDateTimeSelector } from '../../libappbase/timeutils';
import { DateTimeSelectorSOP } from '../../libappsop/datetimeselectorsop';
import { DropDownListSOP } from '../../libappsop/dropdownlistsop';
import { DropDownStringListSOP } from '../../libappsop/dropdownstringlistsop';
 
export class DialogOperationCost extends DialogBase {
  public ddlAccount = new DropDownListSOP('DropDownListAccount');
  public ddlCostDriver = new DropDownStringListSOP('DropDownStringListCostDriver');
  public ddlOperation = new DropDownListSOP('DropDownListOperation');
  public dtsStart = new DateTimeSelectorSOP('DateSelectorCostStart');
  public efCost = new EditField('EditFieldCost');
 
  public constructor() {
    super('DialogCreateEditOperationCost', 'btnOk', 'btnCancel');
  }
 
  /**
   * Update field value in the dialog
   *
   * @param account Account field value
   * @param costDriver Cost driver field value
   * @param operation Operation field value
   * @param startDate Start field value
   * @param cost Cost field value
   */
  public async updateDialog(account?: string, costDriver?: string, operation?: string, startDate?: Date, cost?: number): Promise<void> {
    if (account !== undefined) {
      await this.ddlAccount.selectItemSOP(account);
    }
    if (costDriver !== undefined) {
      await this.ddlCostDriver.selectItem(costDriver);
    }
    if (operation !== undefined) {
      await this.ddlOperation.selectItemSOP(operation);
    }
    if (startDate !== undefined) {
      await this.dtsStart.setDate(startDate);
    }
    if (cost !== undefined) {
      await this.efCost.sendInput(cost.toString());
    }
  }
 
  /**
   * Verify the field values in the dialog is expected, pass in undefined if the verification of certain field is not needed
   *
   * @param account Account field value
   * @param costDriver Cost driver field value
   * @param operation Operation field value
   * @param startDate Start date field value
   * @param cost Cost field value
   */
  public async verifyDialogValue(account?: string, costDriver?: string, operation?: string, startDate?: Date, cost?: number): Promise<string[]> {
    const feedbacks: string[] = [];
    let actual = '';
    const pushFeedback = (dialogField: string, expectedValue: string, actualValue: string): void => {
      if (expectedValue !== actual) {
        feedbacks.push(`${dialogField} should be ${expectedValue}, but actual value is "${actualValue}"`);
      }
    };
    if (account) {
      actual = await this.ddlAccount.getSelectedString();
      pushFeedback('Account', account, actual);
    }
    if (costDriver) {
      actual = await this.ddlCostDriver.getSelectedString();
      pushFeedback('Cost driver', costDriver, actual);
    }
    if (operation) {
      actual = await this.ddlOperation.getSelectedString();
      pushFeedback('Operation', operation, actual);
    }
    if (startDate) {
      const [isMatch, feedback] = await compareDateFromDateTimeSelector(startDate, this.dtsStart, true);
      if (!isMatch) {
        feedbacks.push(feedback);
      }
    }
    if (cost !== undefined && cost.toString() !== (await this.efCost.getText())) {
      actual = await this.efCost.getText();
      pushFeedback('Cost', cost.toString(), actual);
    }
    return feedbacks;
  }
 
  /**
   * Get precondition feedback text on the OK button
   *
   * @returns feedback text in string
   */
  public async getDialogFeedback(): Promise<string> {
    return this.btnOk.getTooltip();
  }
 
  /**
   * OK button is enabled, click on it to close dialog.
   *
   * @returns True = button is enabled; False = button is disabled.
   */
  public async closeDialog(): Promise<boolean> {
    const canClickOK = await this.clickOK();
    return canClickOK;
  }
}