limj
2023-10-24 93652435728de839582440eefd5122c281181d35
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
import { Form } from '../../e2elib/lib/src/pageobjects/form.component';
import { ListRow } from '../../e2elib/lib/src/pageobjects/list/listrow.component';
import { DialogAccount } from '../dialogs/dialog.account';
import { ListSOP } from '../../libappsop/listsop';
 
export class FormAccount extends Form {
  public listAccount = new ListAccount();
 
  public constructor() {
    super('FormAccountStructure');
  }
}
 
export class ListAccount extends ListSOP<DialogAccount, ListAccountColumn> {
  public static readonly title = 'Accounts';
  public constructor() {
    super('ListAccountStructure', new DialogAccount());
 
    // Set primary key column name(s), to display in error message when assert fails
    this.rowPrimaryColumnNames = { Name: '' };
  }
 
  /**
   * Check if the account name exist in the rows
   *
   * @param accName Name column value
   * @param rows Array of ListRow to find from
   */
  public async isAccountExistInRows(accName: string, rows: ListRow[]): Promise<boolean> {
    for (const row of rows) {
      const rowName = await this.getCellValueFromRow(ListAccountStructureColumn.Name, row);
      if (rowName === accName) {
        return true;
      }
    }
    return false;
  }
 
  /**
   * Find account by cost driver
   *
   * @param costDriver Cost driver column value
   * @returns Return an array of ListRow
   */
  public async findAccountByCostDriver(costDriver: string): Promise<ListRow[]> {
    const results: ListRow[] = [];
    const rows = await this.getAllRows();
    for (const row of rows) {
      if ((await (await row.getCell(ListAccountStructureColumn.DefaultCostDriver)).getValue()) === costDriver) {
        results.push(row);
      }
    }
    return results;
  }
 
  /**
   * Create account by passing neccessary field values
   *
   * @param parentAccount Parent account field value
   * @param name Name field value
   * @param reportType Report type field value
   * @param budget Budget field value
   * @param costDriver Cost driver field value
   * @param cost Cost field value
   * @param timeUnit Time unit field value
   * @param lengthOfTime Length of time field value
   * @returns Boolean to indicate if it is successful
   */
  public async createAccount(
    parentAccount?: string,
    name?: string,
    reportType?: string,
    budget?: string,
    costDriver?: string,
    cost?: string,
    timeUnit?: string,
    lengthOfTime?: string,
  ): Promise<boolean> {
    const [dlg] = await this.selectContextMenu(listAccountContextMenuItem.Create);
 
    await dlg.updateDialogValues({
      ParentAccountName: parentAccount,
      Name: name,
      ReportType: reportType,
      Budget: budget,
      CostDriver: costDriver,
      Cost: cost,
      TimeUnit: timeUnit,
      LengthOfTime: lengthOfTime,
    });
    return dlg.clickOK();
  }
 
  /**
   * Check if the cost driver of the account matches with any of the cost drivers
   *
   * @param accName Name column value
   * @param costDrivers Cost driver column value
   */
  public async isAccountCostDriverMatch(accName: string, costDrivers: string[]): Promise<boolean> {
    const row = await this.getRowByValue([{ columnID: ListAccountStructureColumn.Name, value: accName }]);
    const rowCostDriver = await (await row.getCell(ListAccountStructureColumn.DefaultCostDriver)).getValue();
    return costDrivers.indexOf(rowCostDriver) > -1;
  }
 
  /**
   * Open account dialog via "Edit" context menu
   *
   * @returns account dialog
   */
  public async openAcountDialogViaEditContextMenu(listRow: ListRow): Promise<DialogAccount> {
    const [dlg] = await this.selectContextMenu(listAccountContextMenuItem.Edit, listRow);
    return dlg;
  }
}
 
export enum ListAccountStructureColumn {
  AccountType = 'Account type',
  ReportType = 'Report type',
  Name = 'Name',
  DefaultCostDriver = 'Default cost driver',
  DefaultCost = 'Default cost',
  TimeUnit = 'Time unit',
  Budget = 'Budget',
}
 
const listAccountContextMenuItem = {
  Create: { ContextMenu: 'listContextMenuAccount', Name: 'MenuCreate', Label: 'Create' },
  Edit: { ContextMenu: 'listContextMenuAccount', Name: 'MenuEdit', Label: 'Edit' },
};
 
export { listAccountContextMenuItem as ListAccountContextMenuItem };
 
// Transition to new S&OP page objects, so suffix with "2". Once done refactoring, will remove "2" as above column enum will be removed
export interface ListAccountColumn {
  Name?: string;
  'Account type'?: string;
  'Report type'?: string;
  'Default cost driver'?: string;
  'Default cost'?: string;
  'Time unit'?: string;
  Budget?: string;
}
 
export enum ListAccountTypeImage {
  Preferences = 'PREFERENCES',
}