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 };
|