import { lmt } from '../Helpers/readI18NProp'; import { logger } from "../Logger/logger"; import { CommonKeyword } from "./commonKeyword"; import { DateFilter } from "./dateFilter"; import { DewCheckbox } from "./dewCheckbox"; import { DewLoader } from "./dewLoader"; import { DewElement } from "./element"; import { RangeFilter } from "./rangeFilter"; import { TextField } from "./textfield"; import { TextFilter } from "./textFilter"; // import { Wait } from './dewWait'; /** * Header Filter class */ export class HeaderFilter { /** * To apply Text filter for a column header in Grid listing page * * ```js * HeaderFilter.applyTextFilterOnColumn("Request Number","REQ_123"); * ``` * * @param {String} columnName Name of the column * @param {String} dataForFilter data to filter by * */ static async applyTextFilterOnColumn(columnName: string, dataForFilter: string) { try { await CommonKeyword.clickElement(`//span[contains(@class,'text-subhead') and text()[normalize-space()='${columnName}']]/ancestor::dew-col[contains(@class,'align-items')]//dew-icon[contains(@class,'icon-filter')]`); await DewLoader.waitForSpinner(); // await Wait.waitForDefaultTimeout(6); await within(`dew-popover-body`, async () => { await TextFilter.filterByText(columnName, dataForFilter); }); // Verification const numOfElements = await DewElement.getNumberOfElementsPresentInDom(`//div[b[text()[normalize-space()='${columnName}:']] and text()[normalize-space()='${dataForFilter}']] | //div[@class='tagText']/div[text()[normalize-space()='${dataForFilter}']]`); if (numOfElements >= 1) { logger.info(`Filter Applied`); } else { logger.info(`Filter Not Applied`); } } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while applying filter on grid column`); throw error; } } /** * To apply checkbox filter over a column header in Grid listing * * ```js * HeaderFilter.applyCheckboxFilter("Status","Active"); To apply filter on single data * * HeaderFilter.applyCheckboxFilter("Status","Active","On Hold","Published"); To apply filter on multiple data * @param {String} columnName Name of the column * @param {...String} data data to filter by */ static async applyCheckboxFilter(columnName: string, ...data: string[]) { try { await CommonKeyword.clickElement(`.//span[contains(@class,'text-subhead') and text()[normalize-space()='${columnName}']]/ancestor::dew-col[contains(@class,'align-items')]//dew-icon[contains(@class,'icon-filter')]`); await within(`.//dew-popover-body`, async () => { for (const element of data) { await DewCheckbox.selectCheckbox(element); } }); await CommonKeyword.clickElement(`.//div[contains(@class,'filter-action')]//button[@aria-label='${await lmt.getLabel(`Apply`)}']`); // Verification for (const dataCheck of data) { const numOfElements: any = await DewElement.verifyIfISeeElement(`.//div[b[text()[normalize-space()='${columnName}:']] and text()[normalize-space()='${dataCheck}']] | //div[@class='tagText']/div[text()[normalize-space()='${dataCheck}']]`); if (numOfElements >= 1) { logger.info(`Filter Applied for ` + dataCheck); } else { logger.info(`Filter Not Applied for ` + dataCheck); } } } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while applying filter on grid column`); throw error; } } /** * To apply Date filter over a column header in Grid listing * * ```js * HeaderFilter.applyDateFilter("Date","Create Date","23/1/2020") To apply filter by create Date * * HeaderFilter.applyDateFilter("Date","Date Within","Last Month") To apply filter by Date Within * * HeaderFilter.applyDateFilter("Date","Date Period","23/1/2020","23/2/2020") To apply filter by Date Period * ``` * @param {String} columnName Column Name to apply filter * @param {String} filtertype Type for date filter to apply * @param {...String} filtervalue1 value to be filtered * @param {...String} filtervalue2 value to be filtered */ static async applyDateFilter(columnName: string, filtertype: string, filtervalue1: string, filtervalue2?: string) { try { await CommonKeyword.scrollPageToBottom(); await CommonKeyword.clickElement(`.//span[contains(@class,'text-subhead') and text()[normalize-space()='${columnName}']]/ancestor::dew-col[contains(@class,'align-items')]//dew-icon[contains(@class,'icon-filter')]`); await within(`dew-popover-body`, async () => { switch (filtertype) { case await lmt.getLabel(`Date`): case await lmt.getLabel(`Create Date`): await DateFilter.selectCreateDate(filtervalue1); break; case await lmt.getLabel(`Date Within`): await DateFilter.selectDateWithin(filtervalue1); break; case await lmt.getLabel(`Date Period`): if (filtervalue2) { await DateFilter.selectDatePeriod(filtervalue1, filtervalue2); } break; } }); await CommonKeyword.clickElement(`.//dew-date-filter//button[@aria-label='${await lmt.getLabel(`Apply`)}']`); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while applying filter on grid column`); throw error; } } /** * To select numeric range filter in listing Grid * * ```js * HeaderFilter.applyRangeFilter("Amount","10","100") * ``` * * @param {String} filterlabel Column Name in Listing Grid * @param {Number} fromRange Enter the start range value * @param {Number} toRange Enter to end range value */ static async applyRangeFilter(filterlabel: string, fromRange: number, toRange: number) { try { await CommonKeyword.clickElement(`.//span[contains(@class,'text-subhead') and text()[normalize-space()='${filterlabel}']]/ancestor::dew-col[contains(@class,'align-items')]//dew-icon[contains(@class,'icon-filter')]`); await within(`dew-popover-body`, async () => { await RangeFilter.selectNumericRangeFilter(filterlabel, fromRange, toRange); }); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while applying filter on grid column`); throw error; } } /** * This function is used to perform search in the listing grid * * ```js * HeaderFilter.applyGridSearch("Search","Project_123","Project Name"); * ``` * * @param {*} inputPlaceHolder searchbox placeholder * @param {*} dataToSearch value * @param {*} dataCategory type */ static async applyGridSearch(inputPlaceHolder: string, dataToSearch: string, dataCategory: string) { try { await TextField.enterTextUsingLocator(`//dew-listing-search//input[@placeholder[normalize-space()='${inputPlaceHolder}']]`, dataToSearch); await CommonKeyword.clickElement(`.//dew-listing-search//span[@title='${dataToSearch}']/following-sibling::span[@title[normalize-space()='${dataCategory}']]`); } catch (error) { logger.log(`Issue while performing operation in DDCC: Error while searching value in grid`); throw error; } } }