| import { DialogBase } from '../../libappbase/dialogbase'; | 
| import { EditField } from '../../e2elib/lib/src/pageobjects/editfield.component'; | 
| import { Month } from '../../libappbase/timeutils'; | 
| import { QInputComponent } from '../../e2elib/lib/src/pageobjects/base/qinput.component'; | 
| import { CheckboxBase } from '../../libappbase/checkboxbase'; | 
| import { DateTimeSelectorSOP } from '../../libappsop/datetimeselectorsop'; | 
| import { DropDownListSOP } from '../../libappsop/dropdownlistsop'; | 
| import { DropDownStringListSOP } from '../../libappsop/dropdownstringlistsop'; | 
|   | 
| export class DialogUnitCost extends DialogBase { | 
|   public ddlAccount = new DropDownListSOP('DropDownListAccount'); | 
|   public ddlCostDriver = new DropDownStringListSOP('DropDownStringListCostDriver'); | 
|   public ddlUnit = new DropDownListSOP('DropDownListUnit'); | 
|   public dtsStart = new DateTimeSelectorSOP('DateSelectorCostStart'); | 
|   public ddlTimeUnit = new DropDownStringListSOP('DropDownStringListTimeUnit'); | 
|   public efLengthOfTime = new EditField('EditFieldLengthOfTime'); | 
|   public efCost = new EditField('EditFieldCost'); | 
|   public cbBatchEditTimeUnit = new CheckboxBase('CheckboxBatchEditTimeUnit'); | 
|   public cbBatchEditLengthOfTime = new CheckboxBase('CheckboxBatchEditLengthOfTime'); | 
|   public cbBatchEditCost = new CheckboxBase('CheckboxBatchEditCost'); | 
|   | 
|   public constructor() { | 
|     super('DialogCreateEditUnitCost', 'btnOk', 'btnCancel'); | 
|   } | 
|   | 
|   /** | 
|    * To pass-in boolean to toggle on "Batch Edit Cost" checkbox | 
|    * | 
|    * @param toBeToggleOn boolean to toggle on or off check box (true | false) | 
|    */ | 
|   public async toggleBatchEditCostCheckbox(toCheck: boolean): Promise<void> { | 
|     await this.cbBatchEditCost.toggle(toCheck); | 
|   } | 
|   | 
|   /** | 
|    * Update field value in the dialog | 
|    * | 
|    * @param account Account field value | 
|    * @param costDriver Cost driver field value | 
|    * @param unit Unit field value | 
|    * @param startDate Start field value | 
|    * @param timeUnit Time unit field value | 
|    * @param lengthOfTime Length of time field value | 
|    * @param cost Cost field value | 
|    */ | 
|   public async updateUnitCostValue(account?: string, costDriver?: string, unit?: string, startDate?: Date, timeUnit?: string, lengthOfTime?: number, cost?: number): Promise<void> { | 
|     if (account !== undefined) { | 
|       await this.ddlAccount.selectItemSOP(account); | 
|     } | 
|     if (costDriver !== undefined) { | 
|       await this.ddlCostDriver.selectItem(costDriver); | 
|     } | 
|     if (unit !== undefined) { | 
|       await this.ddlUnit.selectItemSOP(unit); | 
|     } | 
|     if (startDate !== undefined) { | 
|       await this.dtsStart.setDate(startDate); | 
|     } | 
|     if (timeUnit !== undefined) { | 
|       await this.ddlTimeUnit.selectItem(timeUnit); | 
|     } | 
|     if (lengthOfTime !== undefined) { | 
|       await this.efLengthOfTime.sendInput(lengthOfTime.toString()); | 
|     } | 
|     if (cost !== undefined) { | 
|       await this.efCost.sendInput(cost.toString()); | 
|     } | 
|   } | 
|   | 
|   /** | 
|    * Verify the field values in the dialog with expected value | 
|    * | 
|    * @param account Expected account field value | 
|    * @param costDriver Expected cost driver field value | 
|    * @param unit Expected unit field value | 
|    * @param startDate Expected start field value | 
|    * @param timeUnit Expected time unit field value | 
|    * @param lengthOfTime Expected length of time field value | 
|    * @param cost Expected cost field value | 
|    * @returns Feedback message of which field doesn't match with expected value, empty if all matched | 
|    */ | 
|   public async verifyDialogValue( | 
|     account?: string, | 
|     costDriver?: string, | 
|     unit?: string, | 
|     startDate?: Date, | 
|     timeUnit?: string, | 
|     lengthOfTime?: number, | 
|     cost?: number, | 
|   ): Promise<string[]> { | 
|     const feedbacks: string[] = []; | 
|     if (account !== undefined && account !== (await this.ddlAccount.getSelectedString())) { | 
|       feedbacks.push(`Account should be ${account}`); | 
|     } | 
|     if (costDriver !== undefined && costDriver !== (await this.ddlCostDriver.getSelectedString())) { | 
|       feedbacks.push(`Cost driver should be ${costDriver}`); | 
|     } | 
|     if (unit !== undefined && unit !== (await this.ddlUnit.getSelectedString())) { | 
|       feedbacks.push(`Unit should be ${unit}`); | 
|     } | 
|     if (startDate !== undefined) { | 
|       const monthString = startDate.toLocaleString(undefined, { month: 'short' }); | 
|       const isDayNotMatch = startDate.getDate() !== Number(await this.dtsStart.getDay()); | 
|       const isMonthNotMatch = monthString !== (await this.dtsStart.getMonth()); | 
|       const isYearNotMatch = startDate.getFullYear() !== Number(await this.dtsStart.getYear()); | 
|       if (isDayNotMatch || isMonthNotMatch || isYearNotMatch) { | 
|         feedbacks.push(`Start should be ${startDate.getDate()}-${monthString}-${startDate.getFullYear()}`); | 
|       } | 
|     } | 
|     if (timeUnit !== undefined && timeUnit !== (await this.ddlTimeUnit.getSelectedString())) { | 
|       feedbacks.push(`Time unit should be ${timeUnit}`); | 
|     } | 
|     if (lengthOfTime !== undefined && lengthOfTime.toString() !== (await this.efLengthOfTime.getText())) { | 
|       feedbacks.push(`Length of time should be ${lengthOfTime}`); | 
|     } | 
|     if (cost !== undefined && cost.toString() !== (await this.efCost.getText())) { | 
|       feedbacks.push(`Cost should be ${cost}`); | 
|     } | 
|     return feedbacks; | 
|   } | 
|   | 
|   /** | 
|    * Get precondition feedback text on the OK button | 
|    * | 
|    * @returns Precondition feedback text in string | 
|    */ | 
|   public async getOKButtonTooltip(): Promise<string> { | 
|     return this.btnOk.getTooltip(); | 
|   } | 
|   | 
|   /** | 
|    * Verify that DropDown has the expected number of elements | 
|    * | 
|    * @param drpd DropDown to be checked | 
|    * @param expectedCount Expected number of elements inside drpd | 
|    * | 
|    * @returns boolean to indicate whether the number elements inside drpd is the same expected | 
|    */ | 
|   public async verifyDropDownCount(drpd: DropDownListSOP | DropDownStringListSOP, expectedCount: number): Promise<boolean> { | 
|     const count = await drpd.getNumberOfElements(); | 
|     return count === expectedCount; | 
|   } | 
|   | 
|   /** | 
|    * | 
|    * Verify that DropDown contains certain values | 
|    * | 
|    * @param drpd DropDown to be checked | 
|    * @param values Values that are expected to be present inside drpd | 
|    * | 
|    * @returns boolean to indicate whether all the values passed are present in drpd | 
|    */ | 
|   public async verifyDropDownContainValues(drpd: DropDownListSOP | DropDownStringListSOP, values: string[]): Promise<boolean> { | 
|     let isSuccess = true; | 
|   | 
|     for (const value of values) { | 
|       try { | 
|         if (drpd instanceof DropDownListSOP) { | 
|           await drpd.selectItemSOP(value); | 
|         } else { | 
|           await drpd.selectItem(value); | 
|         } | 
|       } catch { | 
|         isSuccess = false; | 
|         break; | 
|       } | 
|     } | 
|     return isSuccess; | 
|   } | 
|   | 
|   /** | 
|    * Verify that fields are disabled and 3 additional checkboxes for TimeUnit, Length of Time and Cost are present | 
|    * | 
|    * @returns feedback text if any field is not disabled or checkbox is not present or checked | 
|    */ | 
|   public async verifyBatchEditFieldAccess(): Promise<string[]> { | 
|     // for input components such as dropdown, date time selector, edit field etc. | 
|     const getFeedbacksIfNotDisabled = async (...inputComponents: QInputComponent[]): Promise<string[]> => { | 
|       const feedbacks: string[] = []; | 
|       for (const component of inputComponents) { | 
|         const isDisabled = await component.isDisabled(); | 
|         if (!isDisabled) { | 
|           const label = await component.getComponentLabel(); | 
|           feedbacks.push(`${label.trim()} field should be disabled.`); | 
|         } | 
|       } | 
|       return feedbacks; | 
|     }; | 
|   | 
|     const feedbackTexts = await getFeedbacksIfNotDisabled(this.ddlAccount, this.ddlCostDriver, this.ddlUnit, this.dtsStart, this.ddlTimeUnit, this.efLengthOfTime, this.efCost); | 
|   | 
|     for (const cb of [this.cbBatchEditTimeUnit, this.cbBatchEditLengthOfTime, this.cbBatchEditCost]) { | 
|       const isChecked = await cb.isChecked(); | 
|       const isVisibleAndNotChecked = (await cb.isVisible()) && !isChecked; | 
|       if (!isVisibleAndNotChecked) { | 
|         feedbackTexts.push(`"${cb.componentName}" checkbox should be visible and unchecked.`); | 
|       } | 
|     } | 
|     return feedbackTexts; | 
|   } | 
|   | 
|   /** | 
|    * Get the Dialog values | 
|    * | 
|    * @returns UnitCostDialogValues | 
|    */ | 
|   public async getDialogValues(): Promise<UnitCostDialogValues> { | 
|     const account = await this.ddlAccount.getSelectedString(); | 
|     const costDriver = await this.ddlCostDriver.getSelectedString(); | 
|     const unit = await this.ddlUnit.getSelectedString(); | 
|     // Get the date | 
|     const day = await this.dtsStart.getDay(); | 
|     const month = await this.dtsStart.getMonth(); | 
|     const year = await this.dtsStart.getYear(); | 
|     const startDate = new Date(); | 
|     startDate.setFullYear(Number(year), Month[month], Number(day)); | 
|   | 
|     const timeUnit = await this.ddlTimeUnit.getSelectedString(); | 
|     const lengthOfTime = await this.efLengthOfTime.getText(); | 
|     const cost = await this.efCost.getText(); | 
|   | 
|     return { account, costDriver, unit, startDate, timeUnit, lengthOfTime, cost }; | 
|   } | 
| } | 
|   | 
| export interface UnitCostDialogValues { | 
|   account: string; | 
|   costDriver: string; | 
|   unit: string; | 
|   startDate: Date; | 
|   timeUnit: string; | 
|   lengthOfTime: string; | 
|   cost: string; | 
| } |