renhao
2023-09-21 1aa9f2bb83dd9e4b7517f1cbf06b0db53979bb31
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import { Form } from '../../e2elib/lib/src/pageobjects/form.component';
import { ListBase } from '../../libappbase/listbase';
import { DialogStockingCost } from '../dialogs/dialog.stockingcost';
import { ListRow } from '../../e2elib/lib/src/pageobjects/list/listrow.component';
import { AppMP } from '../appmp';
import { CheckboxBase } from '../../libappbase/checkboxbase';
import { LogMessage } from '../../libappbase/logmessage';
import { ActionTriggerType } from '../../libappbase/utils';
import { QContextMenu } from '../../e2elib/lib/api/pageobjects/qcontextmenu.component';
import { ContextMenuSOP } from '../../libappsop/contextmenusop';
 
export class FormStockingCost extends Form {
  public lstStockingCost = new ListStockingCost();
  public cbFilterByAccount = new CheckboxBase('cbFilterByAccounts');
 
  public constructor() {
    super('FormStockingCosts');
  }
 
  /**
   * Open StockingPoint Dialog via "Copy" button in abp
   */
  public async openCopyStockingCostDialog(): Promise<DialogStockingCost> {
    await AppMP.getInstance().abpData.btnCopy.click();
    await this.lstStockingCost.dlgStockingCost.waitUntilPresent();
    return this.lstStockingCost.dlgStockingCost;
  }
}
 
export class ListStockingCost extends ListBase {
  private readonly _cmMenu = new QContextMenu('lsContextMenuAccCosts');
  public dlgStockingCost = new DialogStockingCost();
 
  public constructor() {
    super('lsAccountCosts');
  }
 
  /**
   * To open stocking cost dialog via context menu or action bar page to "Create" or "Edit" (if pass-in stockingCostRow)
   *
   * @param via Open the dialog via button or context menu.
   * @param stockingCostRow [Optional] Target stocking cost row to be edited.
   * @returns stocking cost dialog
   */
  public async openStockingCostDialog(via: ActionTriggerType, stockingCostRow?: ListRow, isCopy: boolean = false): Promise<DialogStockingCost> {
    switch (via) {
      case ActionTriggerType.Button:
        await this.focus();
        if (stockingCostRow) {
          await stockingCostRow.leftClick();
          if (isCopy) {
            await AppMP.getInstance().abpData.btnCopy.click();
          } else {
            await AppMP.getInstance().abpData.btnEdit.click();
          }
        } else {
          await AppMP.getInstance().abpData.btnCreate.click();
        }
        break;
      case ActionTriggerType.ContextMenu:
        if (stockingCostRow) {
          if (isCopy) {
            await stockingCostRow.rightClick(undefined, this._cmMenu, ListStockingCostContextMenuItem.Copy);
          } else {
            await stockingCostRow.rightClick(undefined, this._cmMenu, ListStockingCostContextMenuItem.Edit);
          }
        } else {
          await this.rightClick(undefined, this._cmMenu, ListStockingCostContextMenuItem.Create);
        }
        break;
      default:
        break;
    }
    await this.dlgStockingCost.waitForScreenUpdate();
    return this.dlgStockingCost;
  }
 
  /**
   * Open Edit Stocking Cost Dialog
   *
   * @returns stocking cost dialog
   */
  public async openEditStockingCostDialog(): Promise<DialogStockingCost> {
    await this.rightClick(undefined, this._cmMenu, ListStockingCostContextMenuItem.Edit);
    await this.dlgStockingCost.waitForScreenUpdate();
    return this.dlgStockingCost;
  }
 
  /**
   * Check stocking cost is existed by value from the list
   *
   * @param stockingPoint Stocking Point column value
   * @param account Account column value
   * @param costDriver Cost driver column value
   * @param cost Cost column value
   * @param uom UoM column value
   * @param start Start column value
   * @param end End column value
   * @returns boolean to indicate whether a the row is existed in the list
   */
  public async isStockingCostExisted(stockingPoint: string, account: string, costDriver: string, cost: string, uom: string, start: string, end: string): Promise<boolean> {
    const result = await this.getRowByValue([
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPoint },
      { columnID: ListStockingCostColumn.Account, value: account },
      { columnID: ListStockingCostColumn.CostDriver, value: costDriver },
      { columnID: ListStockingCostColumn.Cost, value: cost },
      { columnID: ListStockingCostColumn.UoM, value: uom },
      { columnID: ListStockingCostColumn.Start, value: start },
      { columnID: ListStockingCostColumn.End, value: end },
    ]).catch(() => {
      // do nothing as error is thrown due to no row is found
    });
    return result !== undefined;
  }
 
  /**
   * Returns tooltip of the menu item
   *
   * @param menuItemPath MenuItem name
   * @returns tooltip text of the menu item
   */
  public async getMenuItemTooltip(menuItemPath: string): Promise<string> {
    await this._cmMenu.waitForScreenUpdate();
    const tooltip = await this._cmMenu.getToolTip(menuItemPath);
    await this._cmMenu.dismiss();
    return tooltip;
  }
 
  /**
   * Check if the context menu item is disabled
   *
   * @param menuitem Name of target menu item
   * @returns An array of combination of boolean and string, where boolean indicate whether the menuItem is clickable and string inidcate the disabled tooltip
   */
  public async verifyIsMenuItemClickable(menuitem: string): Promise<[boolean, string]> {
    const [isMenuItemClickable, menuItemDisabledTooltip] = await ContextMenuSOP.verifyIsMenuItemClickable(this._cmMenu, menuitem);
    await this._cmMenu.dismiss();
    return [isMenuItemClickable, menuItemDisabledTooltip];
  }
 
  /**
   * Get stocking cost by value from the list
   *
   * @param stockingPoint Stocking Point column value
   * @param cost Cost column value
   */
  public async getStockingCost(stockingPoint: string, cost: string): Promise<ListRow> {
    return this.getRowByValue([
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPoint },
      { columnID: ListStockingCostColumn.Cost, value: cost },
    ]);
  }
 
  /**
   * Get all stocking costs with the account name
   *
   * @param accountName Account column value
   * @returns An array of ListRow that match the account name
   */
  public async getStockingCostsByAccount(accountName: string): Promise<ListRow[]> {
    const allRows = await this.getAllRows();
    const resultRows: ListRow[] = [];
    for (const row of allRows) {
      if ((await this.getCellValueFromRow(ListStockingCostColumn.Account, row)) === accountName) {
        resultRows.push(row);
      }
    }
    return resultRows;
  }
 
  /**
   * Delete stocking cost
   *
   * @param row Stocking Cost row
   */
  public async deleteStockingCost(row: ListRow): Promise<void> {
    return row.rightClick(undefined, this._cmMenu, ListStockingCostContextMenuItem.Delete);
  }
 
  public async openStockingCostDialogViaAbp(): Promise<DialogStockingCost> {
    const appMP = AppMP.getInstance();
    const abpData = appMP.abpData;
 
    await this.leftClickOnWhiteSpace();
    await abpData.btnCreate.click();
    await this.dlgStockingCost.waitUntilPresent();
    expect(await this.dlgStockingCost.isVisible()).toBe(true, LogMessage.dialog_notVisible('Stocking Cost'));
 
    return this.dlgStockingCost;
  }
 
  /**
   * Click on "Edit" button on "Data" action bar page and wait for Stocking Cost dialog to appear
   *
   * @returns Stocking Cost dialog
   */
  public async startEditViaButton(): Promise<DialogStockingCost> {
    await AppMP.getInstance().abpData.btnEdit.click();
    await this.dlgStockingCost.waitForScreenUpdate();
    return this.dlgStockingCost;
  }
}
 
export enum ListStockingCostColumn {
  StockingPoint = 'Stocking Point',
  Account = 'Account',
  CostDriver = 'Cost driver',
  Cost = 'Cost',
  UoM = 'UoM',
  Start = 'Start',
  End = 'End',
}
 
export enum ListStockingCostContextMenuItem {
  Create = 'MenuCreate',
  Edit = 'MenuEdit',
  Copy = 'MenuCopy',
  Delete = 'MenuDelete',
}