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