import { DewLoader } from "./dewLoader"; import { logger } from "../Logger/logger"; import { lmt } from '../Helpers/readI18NProp'; import { CommonKeyword } from './commonKeyword'; import { DewElement } from './element'; import { Wait } from './dewWait'; import { TextField } from './textfield'; /** * Radio Button class */ export class DewViewActions { /** * To navigate to View * * ```js * * DewViewActions.navigateToView("Test57") * ``` * * @param {String} view name * @param {string} mainView * */ static async navigateToView(view: string, mainView?: string) { try { // await Wait.waitForDefaultTimeout(5); await DewLoader.waitToProcess(); await CommonKeyword.clickElement(`.//div[contains(@class,'dropdown current-view')]`); if (await DewElement.checkIfElementVisible(`.//span[@class='view-name'][@title='${view}']`)) { await CommonKeyword.clickElement(`.//span[@class='view-name'][@title='${view}']`); } else { if (mainView !== undefined) { await CommonKeyword.clickElement(`.//a[contains(@class,'view-title')]/span/strong[text()[normalize-space()='${mainView}']]`); await CommonKeyword.clickElement(`.//div[contains(@class,'dropdown current-view')]`); await CommonKeyword.clickElement(`.//span[@class='view-name'][@title='${view}']`); } } if (DewElement.verifyIfISeeElement(`.//p[contains(@title,'${view}')]`)) { logger.info(view + ` selected successfully`); } } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while navigating to view`); throw error; } } /** * To take action on View * * ```js * * DewViewActions.takeAction("Test57","Delete") * ``` * * @param {String} view name * @param {String} action * @return {String} */ static async takeAction(view: string, action: string) { try { let temp = view; this.navigateToView(view); await CommonKeyword.clickElement(`.//dew-listing-views//button[@class='btn filter is-fab']`); await Wait.waitUntilVisibilityOfElement(`.//div[contains(@class,'dropdown-content')]`); switch (action) { case await lmt.getLabel(`DuplicateView`): await CommonKeyword.clickElement(`.//div[text()='${await lmt.getLabel(`DuplicateView`)}']`); if (DewElement.verifyIfISeeElement(`.//div[contains(@class,'modal-header')]//*[contains(text(),'${await lmt.getLabel(`SaveDuplicateView`)}')]`)) { const copiedView = view + `_copy`; await TextField.enterTextUsingLocator(`.//input[@placeholder='${await lmt.getLabel(`DuplicateView`)}']`, copiedView); await CommonKeyword.clickElement(`.//div[h5[contains(text(),'${await lmt.getLabel(`SaveDuplicateView`)}')]]/following-sibling::div//span[text()='${await lmt.getLabel(`Save`)}']`); DewLoader.waitToProcess(); if (DewElement.verifyIfISeeElement(`.//p[contains(@title,'${copiedView}')]`)) { logger.info(`View is copied successfully`); temp = copiedView; } } break; case await lmt.getLabel(`RenameView`): await CommonKeyword.clickElement(`.//div[text()='${await lmt.getLabel(`RenameView`)}']`); if (DewElement.verifyIfISeeElement(`.//div[contains(@class,'modal-header')]//*[contains(text(),'${await lmt.getLabel(`RenameView`)}')]`)) { const newView = `view` + generateRandomNumber(); await TextField.enterTextUsingLocator(`.//input[@placeholder='${await lmt.getLabel(`NewView`)}']`, newView); await CommonKeyword.clickElement(`.//div[h5[contains(text(),'${await lmt.getLabel(`RenameView`)}')]]/following-sibling::div//span[text()='${await lmt.getLabel(`Save`)}']`); DewLoader.waitToProcess(); if (DewElement.verifyIfISeeElement(`.//p[contains(@title,'${newView}')]`)) { logger.info(`View is renamed successfully`); temp = newView; } } break; case await lmt.getLabel(`DeleteView`): await CommonKeyword.clickElement(`.//div[text()='${await lmt.getLabel(`DeleteView`)}']`); if (DewElement.verifyIfISeeElement(`.//div[contains(@class,'confirm-panel')]`)) { await CommonKeyword.clickElement(`.//button[@aria-label='${await lmt.getLabel(`Delete`)}']`); DewLoader.waitToProcess(); if (DewElement.verifyIfIDontSeeElement(view)) { logger.info(` View is deleted successfully`); } } break; case await lmt.getLabel(`SetasDefault`): await CommonKeyword.clickElement(`.//div[text()='${await lmt.getLabel(`SetasDefault`)}']`); await DewLoader.waitToProcess(); // await Wait.waitForDefaultTimeout(5); await CommonKeyword.clickElement(`.//div[contains(@class,'dropdown current-view')]`); if (DewElement.verifyIfISeeElement(`.//a[span[@title='${view}']]//dew-icon[@icon='pin-selected']`)) { logger.info(`View is set to Default`); } await CommonKeyword.clickElement(`.//div[contains(@class,'dropdown current-view')]`); break; } return temp; } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while perfroming action on view`); throw error; } } } /** * Generates Random number * @return {int} */ function generateRandomNumber() { return Math.floor(Math.random() * 9000000); }