/* eslint-disable linebreak-style */ import 'codeceptjs'; import { DewElement } from "./element"; import { TextFilter } from "./textFilter"; import { logger } from "../Logger/logger"; import { CommonKeyword } from './commonKeyword'; import { TextField } from './textfield'; // import { Wait } from './dewWait'; import { DewLoader } from './dewLoader'; /** * Filter Class */ export class Filter { /** * Click on Filter Button in Listing grid and search for the column name * * ```js * Filter.applyFilter("Status"); * * ``` * * @param {*} columnName Column Name to filter */ static async applyFilter(columnName: string) { try { await CommonKeyword.clickElement(`.//dew-filter-pipe-line//button[contains(@class,'filter')]`); await CommonKeyword.clickElement(`.//div[@class[normalize-space()='modal-content']]//div[contains(@class,'search-box')]/input`); await TextField.enterTextUsingLocator(`.//div[@class[normalize-space()='modal-content']]//div[contains(@class,'search-box')]/input`, columnName); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while searching column name in filter`); throw error; } } /** * This function apply text filter in Grid Filter Popup * * ```js * Filter.applyTextFiler("Status","Active"); * ``` * @param {String} columnName Column Name to apply filter * @param {String} dataToFilter Data to filter */ static async applyTextFiler(columnName: string, dataToFilter: string) { await TextFilter.filterByText(columnName, dataToFilter); } /** * This function click on clearAll button in filter popup to clear the filters applied * * ```js * Filter.clearAllFilters(); * ``` */ static async clearAllFilters() { try { await CommonKeyword.clickElement(`.//dew-filter-pipe-line//button[contains(@class,'filter')]`); await DewLoader.waitForSpinner(); /* await Wait.waitForDefaultTimeout(4); await Wait.waitForElement(`.//dew-modal[contains(@class,'show')]//button[@type='button'][@aria-label='Clear All'][not(@disabled='')]`) */ const flag = await DewElement.getListOfElements(`.//dew-modal[contains(@class,'show')]//button[@type='button'][@aria-label='Clear All'][not(@disabled='')]`); logger.info(flag.length); if (flag.length == 1) { await CommonKeyword.clickElement(`.//dew-modal[contains(@class,'show')]//button[@type='button'][@aria-label='Clear All'][not(@disabled='')]`); } else { await CommonKeyword.clickElement(`.//dew-modal[contains(@class,'show')]//button[@aria-label='close-modal']`); } } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while clearing all filter`); throw error; } } }