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
import { Form } from '../../e2elib/lib/src/pageobjects/form.component';
import { PanelBase } from '../../libappbase/panelbase';
import { ListSOP } from '../../libappsop/listsop';
import { DialogDummy } from '../dialogs/dialog.dummy';
import { GaugeSOP } from '../../libappsop/gaugesop';
import { browser } from '../../e2elib/node_modules/protractor';
 
export class FormKPI extends Form {
  public static readonly title = 'KPI Dashboard';
 
  public panelKPIDashboard = new PanelKPIDashboard();
  public panelKPISelection = new PanelKPISelection();
 
  public constructor() {
    super('FormKPI');
  }
 
  public async openKPIDashboardPanel(): Promise<void> {
    await this.panelKPIDashboard.switchTo();
  }
 
  public async openKPISelectionPanel(): Promise<void> {
    await this.panelKPISelection.switchTo();
  }
}
 
export class PanelKPIDashboard extends PanelBase {
  public static readonly title = 'KPI Dashboard';
  public gaugeKPIDashboard = new GaugeKPIDashboard();
 
  public constructor() {
    super('PanelKPIDashboard');
  }
 
  /**
   * @override
   */
  public async switchTo(): Promise<void> {
    await super.switchTo();
    await this.gaugeKPIDashboard.waitUntilPresent();
  }
}
 
export class PanelKPISelection extends PanelBase {
  public static readonly title = 'KPI Selection';
  public lstKPISelection = new ListKPISelection();
 
  public constructor() {
    super('PanelKPISelection');
  }
 
  /**
   * @override
   */
  public async switchTo(): Promise<void> {
    await super.switchTo();
    await this.lstKPISelection.waitUntilPresent();
  }
}
 
export class ListKPISelection extends ListSOP<DialogDummy, ListKPISelectionColumn> {
  public static readonly title = 'KPI Selection';
  public constructor() {
    super('ListKPISelection', new DialogDummy());
  }
 
  /**
   * Deselect all KPI selection in the list
   */
  public async deselectAllKPI(): Promise<void> {
    await this.selectAllAndSelectContextMenu(listKPISelectionContextMenuItem.Deselect);
 
    // Select first row just to cancel out all rows selection (else subsequent test will not work)
    const firstRow = await this.getRowByIndex(0);
    await firstRow.leftClick();
  }
 
  /**
   * Selects the gauges that are inputted. Optionally define wait time upon selection to allow changes to be persisted to the back-end view.
   *
   * @param gaugeNames Gauges names that needs to be toggled
   * @param waitPersistInViewInMilliseconds (Optional) If test require to wait after selecting KPI, example to allow changs to be persisted to view
   */
  public async selectKPI(gaugeNames: string[], waitPersistInViewInMilliseconds?: number): Promise<void> {
    for (const gaugeName of gaugeNames) {
      const row = await this.getRow({ Name: gaugeName });
      await this.toggleRowCheckbox(row, true);
    }
 
    if (waitPersistInViewInMilliseconds) {
      await browser.sleep(waitPersistInViewInMilliseconds);
    }
  }
}
 
export class GaugeKPIDashboard extends GaugeSOP {
  public static readonly title = 'KPI Dashboard';
 
  public constructor() {
    super('GaugeKPIDashboard');
  }
}
 
// Interface for KPI-Value map
export interface GaugeIDValueMap {
  gaugeName: string;
  value: string;
}
 
// List KPI selection columns
export interface ListKPISelectionColumn {
  Name: string;
}
 
// List KPI selection context menu items
const listKPISelectionContextMenuItem = {
  Deselect: { ContextMenu: 'listContextMenuKPI', Name: 'MenuDeselect', Label: 'Deselect' },
  Select: { ContextMenu: 'listContextMenuKPI', Name: 'MenuSelect', Label: 'Select' },
};
 
export { listKPISelectionContextMenuItem as ListKPISelectionContextMenuItem };
 
const stepFormKPI = {
  deselectAllKPI: (): string => `In the List "${ListKPISelection.title}", deselect all rows.`,
  selectKPI: (gaugeNames: string[]): string => `In the List "${ListKPISelection.title}", select row "${gaugeNames}".`,
};
 
export { stepFormKPI as StepFormKPI };