import { Form } from '../../e2elib/lib/src/pageobjects/form.component';
|
import { DialogScenario } from '../dialogs/dialog.scenario';
|
import { ListRow } from '../../e2elib/lib/src/pageobjects/list/listrow.component';
|
import { ListSOP } from '../../libappsop/listsop';
|
import { ContextMenuItemSOP } from '../../libappsop/contextmenusop';
|
import { browser } from '../../e2elib/node_modules/protractor/built';
|
import { Timeout } from '../appmp';
|
|
export class FormScenario extends Form {
|
public lstScenario = new ListScenario();
|
|
public constructor() {
|
super('FormScenarioManager');
|
}
|
}
|
|
export class ListScenario extends ListSOP<DialogScenario, ListScenarioColumn> {
|
public constructor() {
|
super('ListScenario', new DialogScenario());
|
|
// Set primary key column name(s), to display in error message when assert fails
|
this.rowPrimaryColumnNames = { Name: '' };
|
}
|
|
/**
|
* Click Create scenario menu to bring up Scenario dialog.
|
* Set the scenario name and click OK.
|
* Verify scenario created before returning to caller.
|
*
|
* @param name Scenario name
|
*/
|
public async createEmptyScenario(name: string): Promise<void> {
|
const [dlg] = await this.selectContextMenu(listScenarioContextMenuItem.CreateScenario);
|
await dlg.updateDialogValues({ Name: name });
|
await dlg.clickOK();
|
|
await this.verifyRowExists({ Name: name });
|
|
// Focus on the new scenario to be sure (some tests that creates empty scenario one after another has problem focusing on the correct scenario to click context menu)
|
await this.selectRow({ Name: name }, [{ Name: ScenarioManager.AllScenarios }]);
|
}
|
|
/**
|
* Delete all scenarios in given folder
|
*
|
* @param folderName target folder name
|
* @param excludePrefix Ignored if empty. Define a prefix to exclude scenarios from being deleted (e.g if scenario needed for few tests).
|
* @example await deleteAllScenarios('Recycle bin')
|
*/
|
public async deleteAllScenarios(folderName: string, excludePrefix: string = ''): Promise<void> {
|
const folderRow = await this.getRowByValue([{ columnID: 'Name', value: folderName }]);
|
await folderRow.expandRow();
|
await this.waitForScreenUpdate();
|
|
const childRowCount = await folderRow.getChildRowCount();
|
let currentChildRowIndex = 0;
|
for (let count = 0; count < childRowCount; count++) {
|
const row = await folderRow.getChildRow(currentChildRowIndex);
|
if (row !== undefined && row !== null) {
|
let canDelete = excludePrefix === '';
|
// If exclude prefix defined, ensure the current scenario/folder name doesn't start with excludePrefix string
|
if (!canDelete) {
|
const cellValue = await (await row.getCell(this.extractColumnName({ Name: '' }))).getValue();
|
canDelete = !cellValue.startsWith(excludePrefix);
|
}
|
|
if (canDelete) {
|
await this.deleteScenario(row);
|
} else {
|
currentChildRowIndex++;
|
}
|
}
|
}
|
}
|
|
/**
|
* Delete scenario via "Delete" context menu
|
*
|
* @param row target scneario row
|
*/
|
public async deleteScenario(row: ListRow): Promise<void> {
|
await this.selectContextMenu(listScenarioContextMenuItem.Delete, row);
|
}
|
|
/**
|
* Delete scenario from All scenarios and move to Recycle bin.
|
*
|
* @param name Scenario to delete.
|
*/
|
public async deleteScenarioToRecycleBin(name: string): Promise<void> {
|
const row = await this.getRow({ Name: name }, [{ Name: ScenarioManager.AllScenarios }]);
|
await this.deleteScenario(row);
|
}
|
|
/**
|
* Restore item from Recycle bin back to All scenarios folder.
|
*
|
* @param name Item to restore.
|
*/
|
public async restoreItemFromRecycleBin(name: string): Promise<void> {
|
const row = await this.getRow({ Name: name }, [{ Name: ScenarioManager.RecycleBin }]);
|
await this.selectContextMenu(listScenarioContextMenuItem.Restore, row);
|
}
|
/**
|
* Expand parent folder (if provided) to get the scenario, right click scenario and select context menu.
|
*
|
* @param scenarioName Scenario name to apply the action
|
* @param menuName context menu to click
|
* @param parents Optional. If omitted assume scenario directly under All scenarios.
|
*/
|
public async expandFolderAndSelectMenu(scenarioName: string, menuName: ContextMenuItemSOP, parents?: ListScenarioColumn[], timeout?: Timeout.Medium): Promise<void> {
|
await browser.wait(
|
async () => {
|
try {
|
const effectiveParents: ListScenarioColumn[] | undefined = parents ? parents : [{ Name: ScenarioManager.AllScenarios }];
|
// Expand root folder if collapsed
|
if (effectiveParents.length > 0) {
|
await this.expandRow(effectiveParents[0]);
|
}
|
const row = await this.selectRow({ Name: scenarioName }, effectiveParents);
|
await this.selectContextMenu(menuName, row);
|
return true;
|
} catch (e) {
|
return false;
|
}
|
},
|
timeout,
|
'Timeout exceeded to expand folder and select context menu.',
|
);
|
}
|
}
|
|
// List Scenario columns
|
export interface ListScenarioColumn {
|
Name: string;
|
}
|
|
// List scenario context menu items
|
const listScenarioContextMenuItem = {
|
CreateScenario: { ContextMenu: 'listContextMenuScenarioFolder', Name: 'MenuCreateScenario', Label: 'Create scenario' },
|
Delete: { ContextMenu: 'listContextMenuScenarioFolder', Name: 'MenuDelete', Label: 'Delete' },
|
Select: { ContextMenu: 'listContextMenuScenarioFolder', Name: 'MenuSelectScenario', Label: 'Select' },
|
Restore: { ContextMenu: 'listContextMenuScenarioFolder', Name: 'MenuRestoreItem', Label: 'Restore item' },
|
Load: { ContextMenu: 'listContextMenuScenarioFolder', Name: 'MenuLoadScenario', Label: 'Load' },
|
CopyScenario: { ContextMenu: 'listContextMenuScenarioFolder', Name: 'MenuCopyScenario', Label: 'Copy Scenario' },
|
};
|
|
export { listScenarioContextMenuItem as ListScenarioContextMenuItem };
|
|
// List Scenario row ondraw image names
|
export enum ListScenarioOnDrawImage {
|
ActiveScenario = 'CHECK2',
|
}
|
|
// Default scenario manager folders
|
export enum ScenarioManager {
|
AllScenarios = 'All scenarios',
|
RecycleBin = 'Recycle bin',
|
}
|
|
const stepScenario = {
|
createEmptyScenario: (scenarioName: string): string =>
|
`In list Scenario manager, right click menu '${listScenarioContextMenuItem.CreateScenario.Label}'. Set scenario name = ${scenarioName} and click OK to create scenario.`,
|
deleteScenarioToRecycleBin: (scenarioName: string): string => `In list Scenario manager, delete scenario '${scenarioName}' to move it to ${ScenarioManager.RecycleBin}.`,
|
restoreItemFromRecycleBin: (scenarioName: string): string => `In list Scenario manager, restore scenario '${scenarioName}' from ${ScenarioManager.RecycleBin}.`,
|
expandFolderAndSelectMenu: (scenarioName: string, menuName: ContextMenuItemSOP): string =>
|
`In list Scenario manager, expand folder, right click scenario '${scenarioName}' and select menu '${menuName.Label}'.`,
|
};
|
|
export { stepScenario as StepScenario };
|