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
import { KeyboardKey } from '../../e2elib/lib/src/helper/enumhelper';
import { QUtils } from '../../e2elib/lib/src/main/qutils.class';
import { Form } from '../../e2elib/lib/src/pageobjects/form.component';
import { DialogTimeCapacity } from '../dialogs/dialog.timecapacity';
import { LogMessage } from '../../libappbase/logmessage';
import { GanttChartSOP } from '../../libappsop/ganttchartsop';
import { DialogCapacityPlanningEditCalendar } from '../dialogs/dialog.capacityplanningeditcalendar';
 
export class FormCapacityPlanning extends Form {
  public ganttChartCapacityPlanning = new GanttChartCapacityPlanning();
 
  public constructor() {
    super('FormCapacityPlanning');
  }
}
 
export class GanttChartCapacityPlanning extends GanttChartSOP {
  public static readonly title = 'Capacity planning';
  public static readonly contextMenuRowName = 'gcContextMenuCapacityPlanningRow';
  public static readonly contextMenuName = 'gcContextMenuCapacityPlanning';
 
  public dlgTimeCapacity = new DialogTimeCapacity();
  public dlgCapacityPlanningEditCalendar = new DialogCapacityPlanningEditCalendar();
 
  public constructor() {
    super(FormCapacityPlanning.name, 'GanttChartCapacityPlanning', GanttChartCapacityPlanning.contextMenuName);
  }
 
  /**
   * Scroll to the desired column by pressing RIGHT key until the desired column appears
   *
   * @param rightKeyCount Number of times to press RIGHT key.
   */
  public async pressKeyboardRightKey(rightKeyCount: number): Promise<void> {
    for (let index = 0; index < rightKeyCount; index++) {
      await QUtils.keyBoardAction([KeyboardKey.RIGHT]);
    }
  }
 
  /**
   * Right click and select edit Time Capacity of selected gantt chart row
   *
   * @param gcrowTitle Row title of the gantt chart to edit.
   * @param efficiency efficiency value to edit
   */
  public async editRowTimeCapacity(gcrowTitle: string, efficiency: string): Promise<void> {
    const gcrow = await this.getRowsByTitle(gcrowTitle);
 
    // Right click on the node and select edit
    await this.rightClickRowAndSelectMenu(gcrow[0], ganttChartCapacityPlanningContextMenuItem.EditRow);
 
    // Edit efficiency
    await this.dlgTimeCapacity.waitUntilPresent();
    await this.dlgTimeCapacity.updateDialogValues({ Efficiency: efficiency });
    await this.dlgTimeCapacity.clickOK();
  }
 
  /**
   * Verify the gantt chart node of selected gantt chart row between dates is not empty or undefined
   *
   * @param gcrowTitle Row title of the gantt chart to check.
   * @param startDate Start Date of gantt chart to check, eg: 1-Jan-2021
   * @param endDate End Date of gantt chart to check, eg: 1-Jan-2021
   */
  public async verifyGanttChartHasValue(gcrowTitle: string, startDate: string, endDate: string): Promise<void> {
    await this.waitGanttChartInitailise();
    const actualValue = await this.getGanttChartNodeValue(gcrowTitle, startDate, endDate);
    const isGanttChartValueExist = actualValue !== undefined && actualValue !== '';
    expect(isGanttChartValueExist).toBe(true, `Gantt chart value of row ${gcrowTitle} between ${startDate} to ${endDate} is undefined or empty.`);
  }
 
  /**
   * Verify the gantt chart node of selected gantt chart row between dates contains pass in value
   *
   * @param gcrowTitle Row title of the gantt chart to check.
   * @param startDate Start Date of gantt chart to check, eg: 1-Jan-2021
   * @param endDate End Date of gantt chart to check, eg: 1-Jan-2021
   * @param gcNodeValue Gantt chart node value to check
   */
  public async verifyGanttChartValue(gcrowTitle: string, startDate: string, endDate: string, gcNodeValue: string): Promise<void> {
    await this.waitGanttChartInitailise();
    const actualValue = await this.getGanttChartNodeValue(gcrowTitle, startDate, endDate);
 
    expect(actualValue).toBe(gcNodeValue, LogMessage.value_notMatched(gcNodeValue, actualValue));
  }
 
  /**
   * Get the gantt chart node value
   *
   * @param gcrowTitle Row title of the gantt chart to get.
   * @param startDate Start Date of gantt chart to get, eg: 1-Jan-2021
   * @param endDate End Date of gantt chart to get, eg: 1-Jan-2021
   * @param returnNumberOnly Default false to return the node text as it is (with %).
   *
   * @returns Gantt chart node value string
   */
  public async getGanttChartNodeValue(gcrowTitle: string, startDate: string, endDate: string, returnNumberOnly: boolean = false): Promise<string> {
    await this.waitGanttChartInitailise();
    const gcNode = await this.getNodesBetweenDates(gcrowTitle, new Date(startDate), new Date(endDate), false);
    let nodeValue = await gcNode[0].getLeftNodeText();
    nodeValue = nodeValue.replace('<br>', ''); // Need remove HTML breakline at the end of the left node text
 
    if (returnNumberOnly) {
      nodeValue = nodeValue.replace('%', '');
    }
 
    return nodeValue;
  }
 
  /**
   * Convert the pass in Gantt chart value based on efficiency
   *
   * @param gcValueToConvert Gantt chart value to convert
   * @param efficiency Efficiency to change
   */
  public convertGanttChartValueWithEfficiency(gcValueToConvert: string, efficiency: string): string {
    const surfix = '%<br>';
    const gcValueRemoveSurfix = gcValueToConvert.replace(surfix, '');
    const convertedValue = parseInt(gcValueRemoveSurfix, 10) / parseFloat(efficiency);
    return `${Math.round(convertedValue)}${surfix}`;
  }
 
  /**
   * Calculates the average of node values in a gantt chart within the start and end date
   *
   * @param gcRowsTitle Rows that are used to calculate the average value
   * @param startDates Start date array in the gantt chart. Each start element's end date corresponds to matching element position in endDates array.
   * @param endDates End date array in the gantt chart
   */
  public async getRowNodesAverageValue(gcRowsTitle: string[], startDates: string[], endDates: string[]): Promise<string> {
    expect(startDates.length).toBe(endDates.length, `Cannot proceed get nodes average for "${gcRowsTitle.join(', ')}". Number of start dates does not match number of end dates provided.`);
 
    let totalPercentage = 0;
    // Loop each row then sum up nodes matching the start and end dates
    for (const gcrowTitle of gcRowsTitle) {
      for (let dateIndex = 0; dateIndex < startDates.length; dateIndex++) {
        const nodeValue = await this.getGanttChartNodeValue(gcrowTitle, startDates[dateIndex], endDates[dateIndex], true);
        totalPercentage += Number(nodeValue);
      }
    }
 
    const totalNodes = gcRowsTitle.length * startDates.length;
    return String(totalPercentage / totalNodes);
  }
}
 
const ganttChartCapacityPlanningContextMenuItem = {
  EditCalendar: { ContextMenu: GanttChartCapacityPlanning.contextMenuName, Name: 'MenuEditCalendar', Label: 'Edit calendar' },
  EditCalendarRow: { ContextMenu: GanttChartCapacityPlanning.contextMenuRowName, Name: 'MenuEditCalendarRow', Label: 'Edit calendar' },
  EditRow: { ContextMenu: GanttChartCapacityPlanning.contextMenuRowName, Name: 'MenuEditRow', Label: 'Edit' },
};
 
export { ganttChartCapacityPlanningContextMenuItem as GanttChartCapacityPlanningContextMenuItem };
 
/**
 * Tooltips for Gantt Chart Capacity Planning
 */
export const ganttChartPlanningToolTip = {
  editCalendarDisabledNonTimeCapacity: (): string => 'Only applicable to unit capacity type time',
};
 
// Step description to re-use in spec file to prevent scriptor re-write each time
const stepCapacityPlanning = {
  calcAverageCapacityPercentage: (entities: string[], startDate: any, endDate: any): string => `Get average Percentage of unit capacity from ${startDate} to ${endDate} for entities "${entities.join(', ')}".`,
};
 
export { stepCapacityPlanning as StepCapacityPlanning };