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
/**
 * @file        S&OP WebMessageBox component to wrap common methods the team encounter during development
 * @description WebMessageBox class extending libappbase's WebMessageBox.
 * All S&OP page objects inherit from our own class (inheriting e2e/libappbase), but we can propose common methods to them.
 * @author      Kong Ching Shien (ckg6@3ds.com)
 * @copyright   Dassault Systèmes
 */
import { Button } from '../e2elib/lib/src/pageobjects/button/button.component';
import { WebMessageBox } from '../libappbase/webmessagebox';
 
export enum WebMessageButton {
  Yes = 'Yes',
  No = 'No',
  OK = 'OK',
}
 
export class WebMessageBoxSOP extends WebMessageBox {
  private readonly _btnOk = new Button('btnAction9');
 
  /**
   * Click OK button to dismiss message box and wait till hidden.
   */
  public async selectOk(): Promise<void> {
    await this._btnOk.click();
    await this.waitUntilHidden();
  }
 
  /**
   * Verify web message text and click button to dismiss.
   *
   * @param message Text to verify.
   * @param clickButton Button to click to dismiss message box.
   */
  public async verifyMessageAndDismiss(message: string, clickButton: WebMessageButton): Promise<void> {
    await this.waitUntilPresent();
    expect(await this.getMessage()).toBe(message, 'Verify web message box text');
 
    switch (clickButton) {
      case WebMessageButton.Yes:
        await this.selectYes();
        break;
      case WebMessageButton.No:
        await this.selectNo();
        break;
      case WebMessageButton.OK:
        await this.selectOk();
        break;
      default:
          break;
    }
  }
}
 
const stepWebMessageBox = {
  clickButton: (buttonName: string): string => `In message box, click ${buttonName}.`,
  verifyMessageAndDismiss: (message: string, buttonName: string = 'OK'): string => `In message box, verify message "${message}" and click ${buttonName} to dismiss dialog.`,
};
 
export { stepWebMessageBox as StepWebMessageBox };