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
/**
 * @file        S&OP Panel component to wrap common methods the team encounter during development
 * @description Panel class extending e2elib's PanelBase.
 * All S&OP page objects inherit from our own class (inheriting e2e/libappbase), but we can propose common methods to them.
 * @author      Clarence (clarence.chan@3ds.com)
 * @copyright   Dassault Systèmes
 */
import { PanelBase } from '../libappbase/panelbase';
 
export class PanelSOP extends PanelBase {
  public constructor(componentPath: string) {
    super(componentPath);
  }
 
  /**
   * Ensure only 1 collapsible panel is expanded.
   *
   * @param panel The panel to be expanded. For the rest, if it's expanded, click to collapse.
   */
  public async showOnlyPanel(panel: PanelSOP): Promise<void> {
    // Get all property name and check whether it is PanelSOP type
    const allPropertyName = Object.getOwnPropertyNames(this);
    for (const propertyName of allPropertyName) {
      const property = Object.getOwnPropertyDescriptor(this, propertyName);
      if (property!.value instanceof PanelSOP) {
        const childComponent = property!.value;
        // Ensure only target panel is expanded (for the rest, if it's expanded, click to collapse)
        const canClick = (panel === childComponent) !== (await childComponent.isShown());
 
        if (canClick) {
          await childComponent.clickPanel();
        }
      }
    }
  }
 
  public async verifyTitle(expectedTitle: string): Promise<void> {
    expect(await this.getTitle()).toBe(expectedTitle, `Verify panel ${await this.getComponentLabel()} title value.`);
  }
}
 
// Step description to re-use in spec file to prevent scriptor re-write each time
const stepPanel = {
  showOnlyPanel: (panelName: string): string => `Collapse all panels and ensure only panel ${panelName} is expanded.`,
  verifyTitle: (panelName: string, expectedTitle: string): string => `In panel '${panelName}, verify title = '${expectedTitle}'.'`,
};
 
export { stepPanel as StepPanel };