/**
|
* @file S&OP DropDownList component to wrap common methods the team encounter during development
|
* @description DropDownList class extending Abstraction API's QDropDownList.
|
* All S&OP page objects inherit from our own class (inheriting e2e/Abstraction API), but we can propose common methods to them.
|
* @author Clarence (clarence.chan@3ds.com)
|
* @copyright Dassault Systèmes
|
*/
|
import { QDropDownList } from '../e2elib/lib/api/pageobjects/qdropdownlist.component';
|
import { QUtils } from '../e2elib/lib/src/main/qutils.class';
|
import { UIActionSOP } from './objectsop';
|
import { browser } from '../e2elib/node_modules/protractor';
|
import { Timeout } from '../libmp/appmp';
|
|
export class DropDownListSOP extends QDropDownList implements UIActionSOP {
|
public constructor(componentPath: string) {
|
super(componentPath);
|
}
|
|
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 dropdownlist ${await this.getComponentLabel()}. Expecting action link text '${expectedActionLinkText}'.`,
|
);
|
|
if (isActionLinkMatch) {
|
await this.clickActionLink();
|
}
|
}
|
|
public async getValueString(): Promise<string> {
|
return this.getSelectedString();
|
}
|
|
/**
|
* Use browser wait to wait for dropdown to be selectable.
|
*
|
* @param selectionItem Items to select from dropdown.
|
* @param timeout Timeout in milliseconds to wait for dropdown to be selectable and select the item.
|
*/
|
public async selectItemSOP(selectionItem: string | number, timeout: number = Timeout.Medium): Promise<void> {
|
await browser.wait(
|
async () => {
|
try {
|
const selectedItem = await super.findAndSelectItem(selectionItem);
|
return selectedItem === selectionItem;
|
} catch {
|
return false;
|
}
|
},
|
timeout,
|
`Timeout waiting to select '${selectionItem}' in dropdownlist ${await this.getComponentLabel()}.`,
|
);
|
}
|
|
public async setValue(value: string): Promise<void> {
|
await this.selectItemSOP(value);
|
}
|
|
public async verifyAvailableValues(expectedValues: string[]): Promise<void> {
|
// Ensure dropdown contains exactly the size expected (for long list this might not accurate as some options are out of viewport/core tech design of dropdownlist/list)
|
expect(await this.getNumberOfElements()).toBe(
|
expectedValues.length,
|
`Expected dropdownlist ${await this.getComponentLabel()} to have exactly ${expectedValues.length} values.`,
|
);
|
|
// Don't use foreach loop as that's synchronous and doesn't support await
|
for (const val of expectedValues) {
|
await this.verifyHelperValueExist(val, true);
|
}
|
}
|
|
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 dropdownlist ${await this.getComponentLabel()} supports batch edit (expected enable = ${expectedEnable} & action link = ${expectedActionLinkText}).`,
|
);
|
}
|
|
public async verifyHasMaskError(expectedValue: boolean): Promise<void> {
|
// Implements UIActionSOP
|
await this.hasMaskError(expectedValue);
|
}
|
|
public async verifyTooltip(expectedValue: string): Promise<void> {
|
const tooltip = await QUtils.getTooltip(this.tooltipLabelElement, true, true, true);
|
expect(tooltip).toBe(expectedValue, `Hover ${await this.getComponentLabel()} to verify tooltip.`);
|
}
|
|
public async verifyEnabled(expectedEnable: boolean): Promise<void> {
|
expect(!(await this.isDisabled())).toBe(expectedEnable, `Verify enable state for dropdownlist ${await this.getComponentLabel()}.`);
|
}
|
|
public async verifyValue(expectedValue: string): Promise<void> {
|
expect(await this.getSelectedString()).toBe(expectedValue, `Verify value for dropdownlist ${await this.getComponentLabel()}.`);
|
}
|
|
public async verifyVisible(expectedValue: string): Promise<void> {
|
expect(await this.isVisible()).toBe(expectedValue.toLowerCase() === 'true', `Verify visible state for dropdownlist ${await this.getComponentLabel()}.`);
|
}
|
|
public async verifyValueExist(expectedValue: string): Promise<void> {
|
await this.verifyHelperValueExist(expectedValue, true);
|
}
|
|
public async verifyValueNotExist(expectedValue: string): Promise<void> {
|
await this.verifyHelperValueExist(expectedValue, false);
|
}
|
|
public async verifyNumAvailableValues(expectedNum: number): Promise<void> {
|
expect(await this.getNumberOfElements()).toBe(expectedNum, `Verify number of values in drop down list to be ${expectedNum}`);
|
}
|
|
private async verifyHelperValueExist(expectedValue: string, expectedExist: boolean): Promise<void> {
|
let isItemFound = true;
|
await this.selectItemSOP(expectedValue).catch(() => (isItemFound = false));
|
|
const msgFoundOrNot = expectedExist ? '' : 'not ';
|
expect(isItemFound).toBe(expectedExist, `Verify "${expectedValue}" should ${msgFoundOrNot}be found in dropdownlist ${await this.getComponentLabel()}.`);
|
}
|
}
|
|
const stepDropDownList = {
|
verifyNumAvailableValues: (title: string, expectedNum: number): string => `In the dropdownlist "${title}", verify that there are ${expectedNum} available options.`,
|
verifyValueExist: (title: string, expectedValue: string): string => `In the dropdownlist ${title}, verify that "${expectedValue}" is a valid option.`,
|
verifyAvailableValues: (title: string, expectedValues: string[]): string => `In the dropdownlist ${title}, verify that "${expectedValues}" are the only valid options.`,
|
};
|
export { stepDropDownList as StepDropDownList };
|