/**
|
* @file S&OP EditField component to wrap common methods the team encounter during development
|
* @description EditField class extending e2elib's EditField.
|
* 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 { QUtils } from '../e2elib/lib/src/main/qutils.class';
|
import { EditField } from '../e2elib/lib/src/pageobjects/editfield.component';
|
import { ElementFinder } from '../e2elib/node_modules/protractor/built';
|
import { UIActionSOP } from './objectsop';
|
|
export class EditFieldSOP extends EditField implements UIActionSOP {
|
public constructor(componentPath: string, isCustomPath?: boolean, elementObj?: ElementFinder, private readonly overridenLabel?: string) {
|
super(componentPath, isCustomPath, elementObj);
|
}
|
|
public async clickActionLinkText(expectedActionLinkText: string): Promise<void> {
|
const isActionLinkMatch = await this.hasActionLink() && await this.getActionLinkText() === expectedActionLinkText;
|
expect(isActionLinkMatch).toBe(true, `Unable to proceed click action link for editfield ${await this.getComponentLabel()}. Expecting action link text '${expectedActionLinkText}'.`);
|
|
if (isActionLinkMatch) {
|
await this.clickActionLink();
|
}
|
}
|
|
public async getValueString(): Promise<string> {
|
return this.getText();
|
}
|
|
public async setValue(value: string): Promise<void> {
|
// Wait present before typing value into edit field (e.g Account dialog cost field only appear after selecting cost driver)
|
await this.waitUntilPresent();
|
if (await this.isDisabled() && await this.hasActionLink()) {
|
await this.clickActionLink();
|
}
|
await this.sendInput(value);
|
}
|
|
public async toggleValue(): Promise<void> {
|
// Wait present before typing value into edit field (e.g Account dialog cost field only appear after selecting cost driver)
|
await this.waitUntilPresent();
|
const previousValue = await this.getText();
|
const convertNumPreviousValue = Number(previousValue); // returns NaN if not a number
|
|
// If text is string, change value by appending character
|
if (isNaN(convertNumPreviousValue)) {
|
await this.sendInput(`${previousValue }X`);
|
} else {
|
// If text is number, change value by incrementing
|
const newValueStr = (convertNumPreviousValue + 1).toString();
|
await this.sendInput(newValueStr);
|
}
|
}
|
|
public async verifyBatchEditEnabled(expectedEnable: boolean, expectedActionLinkText: string): Promise<void> {
|
const isBatchEditEnableDisableOK = await this.hasActionLink() &&
|
await this.getActionLinkText() === expectedActionLinkText &&
|
!await this.isDisabled() === expectedEnable;
|
expect(isBatchEditEnableDisableOK).toBe(true, `Verify editfield ${await this.getComponentLabel()} supports batch edit (expected enable = ${expectedEnable} & action link = ${expectedActionLinkText}).`);
|
}
|
|
public async verifyHasMaskError(expectedValue: boolean): Promise<void> {
|
// Implements UIActionSOP
|
const actualHasMaskError = await this.hasMaskError(expectedValue);
|
expect(actualHasMaskError).toBe(expectedValue, `Verify has mask error for editfield ${await this.getEffectiveComponentLabel()}.`);
|
}
|
|
public async verifyTooltip(expectedValue: string): Promise<void> {
|
const tooltip = await QUtils.getTooltip(this.tooltipLabelElement, true, true, true);
|
expect(tooltip).toBe(expectedValue, `Hover ${await this.getEffectiveComponentLabel()} to verify tooltip.`);
|
}
|
|
public async verifyEnabled(expectedEnable: boolean): Promise<void> {
|
expect(!await this.isDisabled()).toBe(expectedEnable, `Verify enable state for editfield ${await this.getEffectiveComponentLabel()}.`);
|
}
|
|
public async verifyValue(expectedValue: string): Promise<void> {
|
expect(await this.getText()).toBe(expectedValue, `Verify value for editfield ${await this.getEffectiveComponentLabel()}.`);
|
}
|
|
public async verifyVisible(expectedValue: string): Promise<void> {
|
expect(await this.isVisible()).toBe(expectedValue.toLowerCase() === 'true', `Verify visible state for editfield ${await this.getEffectiveComponentLabel()}.`);
|
}
|
|
/**
|
* Return the label if defined, else use the name provided by scriptor.
|
* Sometimes, designer didn't define a label for edit field as it's used in combination with some other UI component that has label (side by side).
|
*
|
* @returns The effective label to use.
|
*/
|
private async getEffectiveComponentLabel(): Promise<string> {
|
let uiLabel = await this.getComponentLabel();
|
if (uiLabel === '') {
|
uiLabel = this.overridenLabel as string;
|
}
|
|
return uiLabel;
|
}
|
}
|