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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import { Form } from '../../../e2elib/lib/src/pageobjects/form.component';
import { ListRow } from '../../../e2elib/lib/src/pageobjects/list/listrow.component';
import { DialogBookmark } from '../../dialogs/dialog.bookmark';
import { Button } from '../../../e2elib/lib/src/pageobjects/button/button.component';
import { ListBase } from '../../../libappbase/listbase';
import { ListSOP } from '../../../libappsop/listsop';
import { DialogDummy } from '../../dialogs/dialog.dummy';
import { ButtonSOP } from '../../../libappsop/buttonsop';
import { DataHierarchy, DataHierarchyProvider } from '../../../libappsop/datahierarchy';
import { PanelPeriod } from './panel.period';
 
export class FormNavigationPanel extends Form {
  public static readonly btnAddBookmark = 'Bookmark current selection';
 
  // Buttons
  public btnBookmark = new ButtonSOP('ButtonNavBookmark');
  public btnEntity = new ButtonSOP('ButtonNavEntity');
  public btnProduct = new ButtonSOP('ButtonNavProduct');
  public btnSalesSegment = new ButtonSOP('ButtonNavSalesSegment');
  public btnHome = new ButtonSOP('ButtonNavHome');
  public btnPeriod = new ButtonSOP('ButtonNavPeriod');
  public btnAddBookmark = new ButtonSOP('ButtonNavAddBookmark');
 
  // Lists
  public listBookmark = new ListBookmark();
  public listEntity = new ListEntity();
  public listProduct = new ListProduct();
  public listSalesSegment = new ListSalesSegment();
 
  // Panels
  public pnlPeriod = new PanelPeriod();
 
  public constructor() {
    super('FormNavigationPanel');
  }
 
  /**
   * Open navigation form and filter by stocking point
   *
   * @param name Display name of the stocking point
   * @param parentNames Display name of all parent stocking points
   * @returns Boolean to indicate if the entity is checked
   */
  public async filterByEntity(name: string, parentNames?: string[]): Promise<boolean> {
    await this.openNavigationPanel();
    await this.toggleEntityList();
    const row = await this.listEntity.getEntityRowByName(name, parentNames);
    await row.checkboxClick();
    return row.isChecked();
  }
 
  /**
   * Open navigation form and filter by product
   *
   * @param name Name of the product
   * @param parentNames Name of all parent rows
   * @returns Boolean to indicate if the product is checked
   */
  public async filterByProduct(name: ListProductColumn, parentNames: ListProductColumn[]): Promise<void> {
    await this.openNavigationPanel();
    await this.toggleProductList();
    const row = await this.listProduct.getRow(name, parentNames);
    await row.checkboxClick();
  }
 
  /**
   * Open navigation panel if it is collapse / minimize
   * And wait until navigation panel is opened and stable
   */
  public async openNavigationPanel(): Promise<void> {
    // Check if navigation panel form is close
    if (await this.isOpen(false)) {
      await this.restore();
    }
    await this.waitUntilPresent();
  }
 
  /**
   * To reset data selection in navigation panel and hide all navigation lists
   */
  public async reset(): Promise<void> {
    await this.resetNaviToRoot();
 
    // Hide all the lists
    await this.toggleBookmarkList(false);
    await this.toggleEntityList(false);
    await this.toggleProductList(false);
  }
 
  /**
   * Reset navigation panel filter if there is any
   */
  public async resetNaviToRoot(): Promise<void> {
    await this.btnHome.click();
  }
 
  /**
   * Open or hide Bookmark list in navigation panel
   *
   * @param toOpen Boolean indicating whether to open/hide Bookmark list in navigation panel, default is true
   */
  public async toggleBookmarkList(toOpen: boolean = true): Promise<void> {
    return this.toggleList(this.listBookmark, this.btnBookmark, toOpen);
  }
 
  /**
   * Open or hide Entity list in navigation panel
   *
   * @param toOpen Boolean indicating whether to open/hide Entity list in navigation panel, default is true
   */
 
  public async toggleEntityList(toOpen: boolean = true): Promise<void> {
    return this.toggleList(this.listEntity, this.btnEntity, toOpen);
  }
 
  /**
   * Open or hide Product list in navigation panel
   *
   * @param toOpen Boolean indicating whether to open/hide Product list in navigation panel, default is true
   */
  public async toggleProductList(toOpen: boolean = true): Promise<void> {
    return this.toggleList(this.listProduct, this.btnProduct, toOpen);
  }
 
  /**
   * Open or hide SalesSegment list in navigation panel
   *
   * @param toOpen Boolean indicating whether to open/hide Product list in navigation panel, default is true
   */
  public async toggleSalesSegmentList(toOpen: boolean = true): Promise<void> {
    return this.toggleList(this.listSalesSegment, this.btnSalesSegment, toOpen);
  }
 
  /**
   * Open or hide the Period panel in Navigation panel.
   *
   * @param toOpen Boolean indicating whether to open/hide Period panel. Default is true
   */
  public async togglePeriod(toOpen: boolean = true): Promise<void> {
    if ((await this.pnlPeriod.isVisible()) !== toOpen) {
      await this.btnPeriod.click();
      await this.pnlPeriod.waitUntilPresent();
    }
  }
 
  /**
   * Show or hide a list in navigation panel.
   *
   * @param list List to be shown/hidden in navigation panel
   * @param button Button that show/hide the given list in navigation panel
   * @param toShow Indicates to show/hide the given list in navigation panel
   */
  private async toggleList(list: ListBase, button: Button, toShow: boolean = true): Promise<void> {
    if (toShow !== (await list.isVisible())) {
      await button.click();
      await list.waitUntilPresent();
    }
  }
}
 
export class ListBookmark extends ListSOP<DialogBookmark, ListBookmarkColumn> {
  public static title = 'Bookmarks';
 
  public constructor() {
    super('ListBookmark', new DialogBookmark());
 
    // Set primary key column name(s), to display in error message when assert fails
    this.rowPrimaryColumnNames = { Name: '' };
  }
}
 
export class ListEntity extends ListSOP<DialogDummy, ListEntityColumn> {
  public static title = 'Stocking points and units';
 
  public constructor() {
    super('ListEntity', new DialogDummy());
  }
 
  /**
   * Get entity row by pass-in entity DisplayName and parent entity DisplayName(s)
   *
   * @param name target entity DisplayName
   * @param parentNames all parent row entity DisplayName of target entity
   * @returns row of entity
   */
  public async getEntityRowByName(name: string, parentNames?: string[]): Promise<ListRow> {
    return this.getRowByCellValue(ListEntityColumnName.DisplayName, name, parentNames);
  }
 
  /**
   * Toggle Entity Row's checkbox on/off
   *
   * @param expectedState true = ON / false = OFF
   * @param displayName target entity display name
   * @param parentNames target entity parent(s) display name
   * @returns Entity Row of pass-in displayName
   */
  public async toggleEntityRowCheckbox(expectedState: boolean, displayName: string, parentNames?: string[]): Promise<ListRow> {
    const row = await this.getEntityRowByName(displayName, parentNames);
    const currentState = await row.isChecked();
    if (currentState !== expectedState) {
      await row.checkboxClick();
    }
    return row;
  }
 
  // Overrides ListSOP
  public getHierarchy(hierarchyProvider: DataHierarchyProvider, name: DataHierarchy): [ListEntityColumn, ListEntityColumn[] | undefined] {
    const [targetRowName, parentRowNames] = hierarchyProvider.getHierarchy(name);
 
    const thisProduct: ListEntityColumn = { DisplayName: targetRowName.Name };
    // Only if ondraw image defined
    if (targetRowName.OndrawImageName) {
      thisProduct.OndrawImageName = targetRowName.OndrawImageName;
    }
 
    const parents: ListEntityColumn[] = [];
    for (const p of parentRowNames) {
      const parentObj: ListEntityColumn = { DisplayName: p.Name };
      // Only if ondraw image defined
      if (p.OndrawImageName) {
        parentObj.OndrawImageName = p.OndrawImageName;
      }
 
      parents.push(parentObj);
    }
 
    return [thisProduct, parents.length > 0 ? parents : undefined];
  }
}
 
export class ListProduct extends ListSOP<DialogDummy, ListProductColumn> {
  public static title = 'Products';
 
  public constructor() {
    super('ListProduct', new DialogDummy());
  }
 
  // Overrides ListSOP
  public getHierarchy(hierarchyProvider: DataHierarchyProvider, name: DataHierarchy): [ListProductColumn, ListProductColumn[] | undefined] {
    const [targetRowName, parentRowNames] = hierarchyProvider.getHierarchy(name);
 
    const thisProduct: ListProductColumn = { Name: targetRowName.Name };
    const parents: ListProductColumn[] = [];
    for (const p of parentRowNames) {
      parents.push({ Name: p.Name });
    }
 
    return [thisProduct, parents.length > 0 ? parents : undefined];
  }
}
 
export class ListSalesSegment extends ListSOP<DialogDummy, ListSalesSegmentColumn> {
  public static title = 'Sales segmants';
 
  public constructor() {
    super('ListSalesSegment', new DialogDummy()); // Just read-only list, no context menu to create/edit/delete thus use dummy dialog
  }
 
  // Overrides ListSOP
  public getHierarchy(hierarchyProvider: DataHierarchyProvider, name: DataHierarchy): [ListSalesSegmentColumn, ListSalesSegmentColumn[] | undefined] {
    const [targetRowName, parentRowNames] = hierarchyProvider.getHierarchy(name);
 
    const thisSalesSegment: ListSalesSegmentColumn = { Name: targetRowName.Name };
    const parents: ListSalesSegmentColumn[] = [];
    for (const p of parentRowNames) {
      parents.push({ Name: p.Name });
    }
 
    return [thisSalesSegment, parents.length > 0 ? parents : undefined];
  }
}
 
export interface ListBookmarkColumn {
  Name?: string;
}
 
const listBookmarkContextMenuItem = {
  CreateFolder: { ContextMenu: 'listContextMenu445', Name: 'MenuCreateFolder', Label: 'Create folder' },
};
 
export { listBookmarkContextMenuItem as ListBookmarkContextMenuItem };
 
// List Entity columns (suffix New to be removed in future once the old enum ListEntityColumn removed after we extend from ListSOP)
export interface ListEntityColumn {
  OndrawImageName?: string;
  DisplayName: string;
}
 
// List Entity columns
export enum ListEntityColumnName {
  DisplayName = 'DisplayName',
}
 
// List Product columns
export interface ListProductColumn {
  Name?: string;
}
 
export interface ListSalesSegmentColumn {
  Name?: string;
}
 
// Step description to re-use in spec file to prevent scriptor re-write each time
const stepNavigationPanel = {
  checkProducts: (products: string[]): string => `In left Navigation panel, check product(s) ${products.join(', ')}.`,
  checkSalesSegments: (salesSegments: string[]): string => `In left Navigation panel, check sales segment(s) ${salesSegments.join(', ')}.`,
  checkStockingPoints: (stockingPoints: string[]): string => `In left Navigation panel, check stocking point(s) ${stockingPoints.join(', ')}.`,
  checkUnits: (units: string[]): string => `In left Navigation panel, check unit(s) ${units.join(', ')}.`,
  clickHomeResetToRoot: (): string => 'In left Navigation panel, click Home button to reset to Root.',
  openNavigationPanel: (): string => 'Open left docked Navigation panel form.',
  showEntitiesList: (): string => 'In left Navigation panel, show Stocking points and Units list by clicking Stocking points and Units button.',
  showPeriodPanel: (): string => 'In left Navigation panel, show Period Panel by clicking Period button.',
  showProductsList: (): string => 'In left Navigation panel, show Products list by clicking Products button.',
  showSalesSegmentsList: (): string => 'In left Navigation panel, show Sales Segments list by clicking Sales Segments button.',
  showBookmarkList: (): string => 'In left Navigation panel, show Bookmarks list by clicking Bookmarks button.',
  unCheckProducts: (products: string[]): string => `In left Navigation panel, uncheck product(s) ${products.join(', ')}.`,
  unCheckStockingPoints: (stockingpoints: string[]): string => `In left Navigation panel, uncheck stocking point(s) ${stockingpoints.join(', ')}.`,
  unCheckSalesSegments: (salesSegments: string[]): string => `In left Navigation panel, uncheck sales segment(s) ${salesSegments.join(', ')}.`,
  uncheckUnits: (units: string[]): string => `In left Navigation panel, uncheck unit(s) ${units.join(', ')}.`,
};
 
export { stepNavigationPanel as StepNavigationPanel };