| import { DialogGoal } from './dialog.goal'; | 
| import { DialogSOP } from '../../libappsop/dialogsop'; | 
| import { EditFieldSOP } from '../../libappsop/editfieldsop'; | 
| import { ListSOP } from '../../libappsop/listsop'; | 
| import { PanelBase } from '../../libappbase/panelbase'; | 
| import { CheckboxSOP } from '../../libappsop/checkboxsop'; | 
| import { DialogDummy } from './dialog.dummy'; | 
| import { Image } from '../../e2elib/lib/src/pageobjects/image.component'; | 
|   | 
| export interface DialogStrategyFields { | 
|   Name?: string; | 
|   NumPeriodsForAverageDemand?: string; | 
|   NumPeriodsForSmartPlan?: string; | 
|   UseSlidingWindow?: string; | 
|   NrOfPeriodsInWindow?: string; | 
|   NrOfPeriodsPerSlide?: string; | 
|   EnableCampaignOptimizer?: string; | 
|   MaxNrOfElementsInCampaignCombi?: string; | 
|   UseMetaOptimizer?: string; | 
|   MetaOverrideFirstFocusLevel?: string; | 
|   MetaFirstFocusLevel?: string; | 
|   MetaOverrideLastFocusLevel?: string; | 
|   MetaLastFocusLevel?: string; | 
|   MetaMaxTimeAllIterations?: string; | 
|   MetaWeightCollapsedSlackLevel?: string; | 
|   UseShiftPatternOptimization?: string; | 
| } | 
|   | 
| export enum DialogStrategyWarningImage { | 
|   Warning = 'WARNING', | 
| } | 
|   | 
| export interface ListActiveGoalsColumn { | 
|   KPI?: string; | 
|   Level?: string; | 
|   Weight?: string; | 
| } | 
|   | 
| export enum ListActiveGoalsContextMenuItemOLD { | 
|   MenuEditKPIWeight = 'MenuEditKPIWeight', | 
|   MenuIncreaseWeight = 'MenuIncreaseWeight', | 
| } | 
|   | 
| const listActiveGoalsContextMenuItem = { | 
|   Edit: { ContextMenu: 'listContextMenuGeneral', Name: 'MenuEditKPIWeight', Label: 'Edit' }, | 
|   IncreaseWeight: { ContextMenu: 'listContextMenuGeneral', Name: 'MenuIncreaseWeight', Label: 'Increase weight' }, | 
|   DecreaseWeight: { ContextMenu: 'listContextMenuGeneral', Name: 'MenuDecreaseWeight', Label: 'Decrease weight' }, | 
|   Deactivate: { ContextMenu: 'listContextMenuGeneral', Name: 'MenuDeactivateKPIWeight', Label: 'Deactivate' }, | 
|   DecreaseLevel: { ContextMenu: 'listContextMenuGeneral', Name: 'MenuDecreasePriority', Label: 'Decrease level' }, | 
|   IncreaseLevel: { ContextMenu: 'listContextMenuGeneral', Name: 'MenuIncreasePriority', Label: 'Increase level' }, | 
| }; | 
|   | 
| export { listActiveGoalsContextMenuItem as ListActiveGoalsContextMenuItem }; | 
|   | 
| export class DialogStrategy extends DialogSOP<DialogStrategyFields> { | 
|   public static readonly title = 'Optimizer Strategy'; | 
|   | 
|   private readonly _efName = new EditFieldSOP('EditFieldName'); | 
|   private readonly _efNumPeriodsAverageDemand = new EditFieldSOP('EditFieldAvgDemand'); | 
|   private readonly _efNumPeriodsSmartPlan = new EditFieldSOP('EditFieldNrOfPeriodsSmartPlan'); | 
|   private readonly _efNrOfPeriodsInWindow = new EditFieldSOP('EditFieldNrOfPeriodsInWindow'); | 
|   private readonly _efNrOfPeriodsPerSlide = new EditFieldSOP('EditFieldNrOfPeriodsPerSlide'); | 
|   private readonly _cbUseSlidingWindow = new CheckboxSOP('CheckboxUseSlidingWindowsApproach'); | 
|   // Meta optimizer fields | 
|   private readonly _cbUseMetaOpt = new CheckboxSOP('CheckboxUseMetaOptimizer'); | 
|   private readonly _cbMetaOverrideFirstFocusLevel = new CheckboxSOP('CheckboxOverrideFirstFocusLevel'); | 
|   private readonly _efMetaFirstFocusLevel = new EditFieldSOP('EditFieldMetaFirstFocusLevel'); | 
|   private readonly _cbMetaOverrideLastFocusLevel = new CheckboxSOP('CheckboxOverrideLastFocusLevel'); | 
|   private readonly _efMetaLastFocusLevel = new EditFieldSOP('EditFieldMetaLastFocusLevel'); | 
|   private readonly _efMetaMaxTimeAllIterations = new EditFieldSOP('EditFieldMaxiTimeForAllIteration'); | 
|   private readonly _efMetaWeightCollapsedSlackLevel = new EditFieldSOP('EditFieldMetaCollapseLevel'); | 
|   private readonly _cbUseShiftPatternOptimization = new CheckboxSOP('CheckboxUseShiftPatternOptimization'); | 
|   | 
|   // Warning image when goal configuration violated (if certain goals defined on certain levels, to warn user) | 
|   private readonly _warningImage = new Image('ImageOptimizerUnbounded'); | 
|   | 
|   public listActiveGoals = new ListActiveGoals(); | 
|   public listInactiveGoals = new ListInactiveGoals(); | 
|   | 
|   // Advanced tab | 
|   private readonly _cbUseCampaignSequencingOptimizer = new CheckboxSOP('CheckboxUseCampaignSequencingOptimizer'); | 
|   private readonly _efMaxNrOfElemInCampaignCombi = new EditFieldSOP('EditFieldMaxNrOfElementsInCampaignCombi'); | 
|   public readonly panelAdvanced = new PanelBase('PanelAdvanced'); | 
|   public readonly panelSettings = new PanelBase('PanelSettings'); | 
|   | 
|   public constructor() { | 
|     super('DialogCreateEditStrategy'); | 
|   | 
|     // Set UI element mapping to pair the UI name to the UI element for use in DialogSOP to find the UI object to set value or verify value | 
|     // This prevents each new Dialog to duplicate code just to set/verify UI element value | 
|     this._uiMap.set('Name', this._efName); | 
|     this._uiMap.set('NumPeriodsForAverageDemand', this._efNumPeriodsAverageDemand); | 
|     this._uiMap.set('NumPeriodsForSmartPlan', this._efNumPeriodsSmartPlan); | 
|     this._uiMap.set('UseSlidingWindow', this._cbUseSlidingWindow); | 
|     this._uiMap.set('NrOfPeriodsInWindow', this._efNrOfPeriodsInWindow); | 
|     this._uiMap.set('NrOfPeriodsPerSlide', this._efNrOfPeriodsPerSlide); | 
|     this._uiMap.set('EnableCampaignOptimizer', this._cbUseCampaignSequencingOptimizer); | 
|     this._uiMap.set('MaxNrOfElementsInCampaignCombi', this._efMaxNrOfElemInCampaignCombi); | 
|     // Meta optimizer fields | 
|     this._uiMap.set('UseMetaOptimizer', this._cbUseMetaOpt); | 
|     this._uiMap.set('MetaOverrideFirstFocusLevel', this._cbMetaOverrideFirstFocusLevel); | 
|     this._uiMap.set('MetaFirstFocusLevel', this._efMetaFirstFocusLevel); | 
|     this._uiMap.set('MetaOverrideLastFocusLevel', this._cbMetaOverrideLastFocusLevel); | 
|     this._uiMap.set('MetaLastFocusLevel', this._efMetaLastFocusLevel); | 
|     this._uiMap.set('MetaMaxTimeAllIterations', this._efMetaMaxTimeAllIterations); | 
|     this._uiMap.set('MetaWeightCollapsedSlackLevel', this._efMetaWeightCollapsedSlackLevel); | 
|     this._uiMap.set('UseShiftPatternOptimization', this._cbUseShiftPatternOptimization); | 
|   } | 
|   | 
|   public async verifyHasWarningImage(expectedHasWarning: boolean, warningImageName?: DialogStrategyWarningImage): Promise<void> { | 
|     const isShown = await this._warningImage.isVisible(); | 
|   | 
|     expect(isShown).toBe(expectedHasWarning, 'Verify strategy warning image shown.'); | 
|   | 
|     if (expectedHasWarning && warningImageName) { | 
|       const actualImageName = await this._warningImage.getName(); | 
|       expect(actualImageName).toBe(warningImageName, 'Verify correct strategy warning image shown.'); | 
|     } | 
|   } | 
| } | 
|   | 
| export class ListActiveGoals extends ListSOP<DialogGoal, ListActiveGoalsColumn> { | 
|   public static readonly title = 'Active goals'; | 
|   public readonly name = 'Active goals'; | 
|   public constructor() { | 
|     super('ListActiveGoals', new DialogGoal()); | 
|   } | 
|   | 
|   public async getActiveGoals(): Promise<any[]> { | 
|     const goals = new Array(); | 
|     const rows = await this.getAllRows(); | 
|     for (const row of rows) { | 
|       const goal = await (await row.getCell('KPI')).getValue(); | 
|       const level = await (await row.getCell('Level')).getValue(); | 
|       const weight = await (await row.getCell('Weight')).getValue(); | 
|   | 
|       // Push to return array | 
|       goals.push({ goal, level, weight }); | 
|     } | 
|   | 
|     // Sort rows for caller to compare if 2 strategy has matching goals | 
|     // Just arbitary string sorting, no need accurate by goal/KPI level | 
|     goals.sort((a: any, b: any) => { | 
|       const jsonA = JSON.stringify(a); | 
|       const jsonB = JSON.stringify(b); | 
|       // TypeScript sort requires return -1 if 1st value smaller, return 1 if greater and 0 if equal | 
|       return jsonA < jsonB ? -1 : jsonA > jsonB ? 1 : 0; | 
|     }); | 
|   | 
|     return goals; | 
|   } | 
|   | 
|   /** | 
|    * Perform quick update and verify active goal weightage is edited. | 
|    * | 
|    * @param kpi KPI Name for active goal | 
|    * @param weight Weight for active goal | 
|    */ | 
|   public async updateActiveGoalWeight(kpi: string, weight: string): Promise<void> { | 
|     const selectRow = await this.getRow({ KPI: kpi }); | 
|     const [dlgGoal] = await this.selectContextMenu(listActiveGoalsContextMenuItem.Edit, selectRow); | 
|     await dlgGoal.updateDialogValues({ Weight: weight }); | 
|     await dlgGoal.clickOK(); | 
|     await this.verifyRowValues(selectRow, { Weight: weight }); | 
|   } | 
| } | 
|   | 
| export interface ListInactiveGoalsColumn { | 
|   Goal?: string; | 
| } | 
|   | 
| export class ListInactiveGoals extends ListSOP<DialogDummy, ListInactiveGoalsColumn> { | 
|   public static readonly title = 'Inactive goals'; | 
|   public constructor() { | 
|     super('ListInactiveGoals', new DialogDummy()); | 
|   } | 
| } | 
|   | 
| /** | 
|  * Tooltips for info | 
|  */ | 
| // Break line string for tooltip (<br>) | 
| const br = '<br>'; | 
| export const campaignOptimizerTooltip = { | 
|   checkBox_enableCampaignOptimizer: `When enabled, the optimizer is allowed to replan the sequence and the quantities of the campaigns based on the constraints of campaign types and transition types.${br}When disabled, the optimizer is only allowed to replan the quantities of the campaigns based on the constraints of the campaigns created manually.`, | 
|   editField_maxNrOfElementsInCampaignCombi: 'Limit on the number of campaign and transition changes per combi.', | 
| }; | 
|   | 
| /** | 
|  * Tooltips for precondition | 
|  */ | 
| export const btnOkTooltip = { | 
|   maxNrOfElementsInCampaignCombi_isNumberNegative: (input: string): string => `Maximum number of elements in campaign combi (${input}) must be greater than or equal to 1.`, | 
|   maxNrOfElementsInCampaignCombi_isInputInvalid: (): string => 'Invalid input for Maximum number of elements in campaign combi', | 
|   numPeriodsForAverageDemand_Invalid: (input: string): string => `The default number of periods for average demand (${input}) should be greater than zero.`, | 
|   numPeriodsForSmartPlan_Invalid: (input: string): string => `Number of smart plan periods (${input}) must be greater than 0.`, | 
|   numPeriodsForSlidingWindow_Invalid: (input: string): string => `The number of periods in the sliding window (${input}) should be at least 1.`, | 
|   // Meta optimizer related tooltip | 
|   metaFirstFocusLevel_Invalid: (input: string): string => `First focus level (${input}) must be greater than or equal to 0.`, | 
|   metaLastFocusLevel_Invalid: (input: string): string => `Last focus level (${input}) must be greater than or equal to 1.`, | 
| }; | 
|   | 
| // Step description to re-use in spec file to prevent scriptor re-write each time | 
| const stepDialogStrategy = { | 
|   verifyHasWarningImage: (expectedHasWarning: boolean, expectedWarningImageName: string = ''): string => `In dialog ${DialogStrategy.title}, verify warning image is visible = ${expectedHasWarning} and warning image = ${expectedWarningImageName}.`, | 
| }; | 
|   | 
| export { stepDialogStrategy as StepDialogStrategy }; |