yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
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 = '&lt;br&gt;';
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 };