import { lmt } from '../Helpers/readI18NProp'; import { logger } from '../Logger/logger'; import { CommonKeyword } from './commonKeyword'; import { DewElement } from './element'; import { TextField } from './textfield'; // import { Wait } from './dewWait'; /** * Information Card class */ export class InfoCard { /** * Fuction is use to check information card functionality * * ```js * * InfoCard.checkinfoCardFunctionality("//div"); * * ``` * @param {*} locator located by Xpath|CSS * */ static async checkinfoCardFunctionality(locator: string) { try { columnConfiguration(locator); const selectedColumn: string[] = await fetchColumName(); this.searchAndSelectCheckBox(selectedColumn); this.verfiyColumnInInfoCard(locator, selectedColumn); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while checking infocard functionality`); throw error; } } /** * Fuction is use to select Column in Information card * * ```js * * InfoCard.selectColumnInInfoCard("//div","Project Name"); * * ``` * @param {*} locator located by Xpath|CSS * @param {String} columnName Column Name * */ static async selectColumnInInfoCard(locator: string, columnName: string[]) { try { columnConfiguration(locator); this.searchAndSelectCheckBox(columnName); this.verfiyColumnInInfoCard(locator, columnName); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while selecting column in infocard`); throw error; } } /** * Search and Select checkbox in information card popup * * ```js * InfoCard.searchAndSelectCheckBox("Project Name") * ``` * * @param {String} selectedColumn Column Name */ static async searchAndSelectCheckBox(selectedColumn: string[]) { try { for (const columnName of selectedColumn) { await TextField.enterTextUsingLocator(`.//input[contains(@aria-label,'header filter search')]`, columnName); await CommonKeyword.clickElement(`.//dew-modal-body//div/dew-checkbox[label[text()[normalize-space()='${columnName}']]]`); await DewElement.verifyIfISeeCheckboxIsChecked(columnName); } await CommonKeyword.click(`//dew-modal-footer//button[@aria-label='Apply' and not(@disabled)]`); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while selecting checkbox in inforcard`); throw error; } } /** * Function to verify column in information card * * ```js * InfoCard.verfiyColumnInInfoCard("//div","Project Name") * ``` * * @param {*} locator located by xpath|CSS * @param {*} verfiyColumn Column name */ static async verfiyColumnInInfoCard(locator: string, verfiyColumn: string[]) { try { await CommonKeyword.moveCursorTo(locator); await DewElement.verifyIfISeeElement(`.//ngb-tooltip-window[contains(@class,'tooltip show')]`); for (const columnName of verfiyColumn) { await DewElement.verifyIfISeeText(columnName); } } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while verfying column in infocarrd`); throw error; } } } /** * To configure column * @param {*} locator */ async function columnConfiguration(locator: string) { try { await CommonKeyword.moveCursorTo(locator); await DewElement.verifyIfISeeElement(`.//ngb-tooltip-window[contains(@class,'tooltip show')]`); // await Wait.waitForDefaultTimeout(5); await CommonKeyword.clickElement(`.//i[contains(@class,'icon-settings')]`); await DewElement.verifyIfISeeText(`Column Configuration`); await CommonKeyword.clickElement(`.//dew-checkbox[label[text()[normalize-space()='${await lmt.getLabel(`SelectAll`)}']]]`); await CommonKeyword.clickElement(`.//dew-checkbox[label[text()[normalize-space()='${await lmt.getLabel(`SelectAll`)}']]]`); await DewElement.verifyIfISeeText(await lmt.getLabel(`Select_at_least`)); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while configuring column in infocard`); throw error; } } /** * To fetch Column Name */ async function fetchColumName() { try { const availableColumnName = await DewElement.grabTextFrom(`.//dew-modal-body//div/dew-checkbox/label`); const selectedColumn = []; while (selectedColumn.length < 6) { const randomColumn = availableColumnName[Math.floor(Math.random() * availableColumnName.length)]; if (selectedColumn.indexOf(randomColumn) === -1) { selectedColumn.push(randomColumn); } } return selectedColumn; } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while fetching column name from infocard`); throw error; } }