Skip to content

fix_smartInbox_ActionsRules #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 110 additions & 24 deletions pages/smartInbox.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,70 @@
import selectors from "#selectors/smartInbox";
export class SmartInbox {

/**
* Searches for a task by name in the smart inbox
* @param {string} taskName - The name of the task to search for
*/
searchTask(taskName){
cy.xpath('//tbody//tr').should('be.visible');
cy.xpath(selectors.tableRow).should('be.visible');
cy.get(selectors.searchTask).type(taskName);
cy.get(selectors.pressSelectOptionSaveSearch).type('{enter}');
cy.get(selectors.loadingSpinnerTask).should('be.visible');
cy.get(selectors.loadingSpinnerTask).should('not.be.visible');
cy.xpath("//table//td//*[contains(text(),'"+taskName+"')]").should('be.visible');
cy.xpath(selectors.tableCell + "//*[contains(text(),'"+taskName+"')]").should('be.visible');
}
/**
* Marks a task as priority in the smart inbox
* @param {string} taskName - The name of the task to mark as priority
* @param {number} priorityCol - The column number for priority (default: 2)
*/
taskAsPriority(taskName, priorityCol = 2){
cy.xpath("//*[@data-cy='tasks-table']//*[contains(text(),'"+taskName+"')]").should('be.visible');
cy.xpath(selectors.tasksTable + "//*[contains(text(),'"+taskName+"')]").should('be.visible');
cy.xpath('(//tbody//td["'+ priorityCol +'"]//img)[1]').should('be.visible').click();
cy.get(selectors.loadingSpinnerTask).should('be.visible');
cy.get(selectors.loadingSpinnerTask).should('not.be.visible');
cy.get('[alt="priority"]').should('be.visible');
cy.get(selectors.priorityImage).should('be.visible');
}

/**
* Clicks the clear task button in the smart inbox
*/
pressClearTaskButton() {
cy.xpath(selectors.clearDraftBtn)
.as("clearTaskBtn")
.should("be.visible");
cy.get("@clearTaskBtn").click();
}

/**
* Marks a task as priority by clicking on the specified row and column
* @param {number} row - The row number (default: 0)
* @param {number} col - The column number (default: 2)
*/
markPriorityTask(row = 0, col = 2) {
cy.get("tbody tr").eq(row).find("td span").as("result");
cy.get(selectors.tableBodyRow).eq(row).find(selectors.tableCellSpan).as("result");
cy.get("@result").should("be.visible");
cy.get("@result").eq(col).click();
cy.get('[class="jumbotron jumbotron-fluid"]').should("be.visible");
cy.get(selectors.jumbotron).should("be.visible");
cy.get("@result").find("img").should("have.attr", "alt", "priority");
}

/**
* Unmarks a task's priority by clicking on the specified row and column
* @param {number} row - The row number (default: 0)
* @param {number} col - The column number (default: 2)
*/
unmarkPriorityTask(row = 0, col = 2) {
cy.get("tbody tr").eq(row).find("td span").as("result");
cy.get(selectors.tableBodyRow).eq(row).find(selectors.tableCellSpan).as("result");
cy.get("@result").should("be.visible");
cy.get("@result").eq(col).click();
cy.get('[class="jumbotron jumbotron-fluid"]').should("be.visible");
cy.get(selectors.jumbotron).should("be.visible");
cy.get("@result").find("img").should("have.attr", "alt", "no-priority");
}

/**
* Clicks the inbox rules button and verifies the rules table is visible
*/
pressInboxRulesBtn() {
cy.get(selectors.inboxRulesBtn)
.as("inboxRulesBtn")
Expand All @@ -48,69 +73,91 @@ export class SmartInbox {
cy.get(selectors.inboxRuleTable).should("be.visible");
}

/**
* Clicks the rules tab and verifies the rules table is visible
*/
pressRulesTab() {
cy.xpath(selectors.rulesTab).as("rulesTab").should("be.visible");
cy.get("@rulesTab").click();
cy.get(selectors.inboxRuleTable).should("be.visible");
}

/**
* Clicks the execution log tab and verifies the rules table is visible
*/
pressExecutionLogTab() {
cy.xpath(selectors.executionLogTab).as("logTab").should("be.visible");
cy.get("@logTab").click();
cy.get(selectors.inboxRuleTable).should("be.visible");
}

/**
* Clicks the create rule button and verifies the new rule title is visible
*/
pressCreateRule() {
cy.xpath(selectors.createRuleBtn)
.as("createRuleBtn")
.should("be.visible");
cy.get("@createRuleBtn").click();
cy.get('[id="inbox-rules"] h4').should("have.text", "New Inbox Rule");
cy.get(selectors.newInboxRuleTitle).should("have.text", "New Inbox Rule");
}

/**
* Clicks a button at the specified index
* @param {number} nro - The index of the button to click
*/
pressBtn(nro){
cy.get(selectors.optionNroBtn).as("btn").should("be.visible");
cy.get("@btn").eq(nro).click();
}

/**
* Selects an option from the save search dropdown
* @param {string} option - The option text to select
*/
pressSelectOptionSaveSearch(option) {
cy.get(selectors.optionSaveSearch).contains(option).click();
//cy.get(selectors.pagination).should("be.visible");
}

/**
* Writes a name in the rule name field
* @param {string} name - The name to write in the rule name field
*/
writeRuleName(name) {
cy.get(selectors.ruleNameField).clear().type(name);
cy.get(selectors.ruleNameField).should("have.value", name);
}

/**
* Writes a deactivation date in the date field
* @param {string} dateVar - The date to write in the deactivation date field
*/
writeDesactivationDate(dateVar) {
cy.get(selectors.desactivationDateField).clear().type(dateVar);
cy.get(selectors.desactivationDateField).should("have.value", dateVar);
}

/**
* Clicks the save button in the smart inbox rule configuration
*/
saveBtnSmartInbox() {
cy.get(selectors.saveBtnRuleConfiguration).click();
}

/**
* Clicks the cancel button in the smart inbox rule configuration
*/
cancelBtnSmartInbox() {
cy.get(selectors.saveBtnRuleConfiguration).click();
}

/**
* Waits for and verifies the success message when creating a rule
* @param {string} ruleName - The name of the rule that was created
*/
waitMessageSuccessCreateRuleInbox(ruleName) {
//cy.get(selectors.messageCreateRule).as("message").should("be.visible");
//cy.get("@message").should("have.text", ruleName);
cy.log(ruleName);
cy.get(selectors.modalCreateRule).within(() => {
cy.get("img").should(
"have.attr",
"src",
"/img/check-circle-lg.svg"
);
cy.get("img").should(
"have.attr",
"alt",
"Rule successfully created"
);
cy.get("b").should("have.text", "Rule successfully created");
cy.get("span").should(
"have.text",
Expand All @@ -119,13 +166,21 @@ export class SmartInbox {
});
}

/**
* Performs an action on the first inbox rule in the table
* @param {string} action - The action to perform (e.g., "Delete")
*/
actionInboxRule(action) {
cy.get(selectors.rowTableInboxRule).first().trigger("mouseover");
cy.get(
selectors.actionInboxRule.replace("selectOption", action)
).click();
}

/**
* Confirms an action on an inbox rule
* @param {string} action - The action to confirm (e.g., "Delete")
*/
confirmActionInboxRule(action) {
let nro;
if (action == "Delete") {
Expand All @@ -136,12 +191,21 @@ export class SmartInbox {
cy.get(selectors.confirmActionInboxRule).eq(nro).click();
}

/**
* Searches for an inbox rule by name
* @param {string} name - The name of the rule to search for
*/
searchInboxRule(name) {
cy.get(selectors.searchInboxRule).as("search").should("be.visible");
cy.get("@search").clear().type(name, { delay: 400 });
cy.get("@search").should("have.value", name);
}

/**
* Searches for an inbox rule and performs an action if found
* @param {string} inboxRuleName - The name of the rule to search for
* @param {string} action - The action to perform if the rule is found
*/
searchInboxRuleAndAction(inboxRuleName, action) {
this.searchInboxRule(inboxRuleName);
cy.get(selectors.totalPaginationInboxRule)
Expand All @@ -156,14 +220,18 @@ export class SmartInbox {
});
}

/**
* Deletes a rule using the API
* @param {string} ruleId - The ID of the rule to delete
* @returns {Promise} A promise that resolves with the deleted rule data
*/
deleteRuleAPI(ruleId) {
if (ruleId !== undefined) {
return cy.window().then((win) => {
return win.ProcessMaker.apiClient
.delete("tasks/rules/" + ruleId)
.then((response) => {
console.log("delete Rule");
// return cy.wrap(response.data.data);
return response.data.data;
});
});
Expand All @@ -172,6 +240,11 @@ export class SmartInbox {
}
}

/**
* Gets a rule by name using the API
* @param {string} ruleName - The name of the rule to find
* @returns {Promise} A promise that resolves with the found rule
*/
getRuleByNameAPI(ruleName) {
return cy.window().then((win) => {
return win.ProcessMaker.apiClient
Expand All @@ -189,14 +262,21 @@ export class SmartInbox {
});
}

/**
* Verifies if a rule exists and creates it if it doesn't
* @param {string} inboxName - The name of the inbox rule
* @param {string} message - The success message to verify
* @param {string} saveSearchName - The name of the save search to use
*/
verifyIfExistRule(inboxName, message, saveSearchName) {
this.searchInboxRule(inboxName);
cy.get(selectors.totalPaginationInboxRule)
.eq(1)
.scrollIntoView()
.invoke("text")
.then(($el) => {
if ($el.trim() == "0 items") {
const count = parseInt($el.trim());
if (count === 0) {
this.pressCreateRule();
this.pressBtn(2);
this.pressSelectOptionSaveSearch(saveSearchName);
Expand All @@ -209,11 +289,17 @@ export class SmartInbox {
});
}

/**
* Clicks the clear draft task button
*/
pressClearDraftTask() {
cy.xpath(selectors.clearDraftBtn).should("be.visible");
cy.xpath(selectors.clearDraftBtn).click();
}

/**
* Closes the modal that appears after successfully creating a rule
*/
closeModalSuccessfullyCreated() {
cy.get(selectors.closeBtnModalCreateRule).click();
}
Expand Down
9 changes: 9 additions & 0 deletions selectors/smartInbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ export default {
actionInboxRule: 'div[data-cy="inboxRulesRowButtons0"] button img[alt="selectOption"]',
confirmActionInboxRule: 'div[class="popover-body"] div[class="col"] button',
clearDraftBtn: '//div[@id="details"]//button[contains(text(),"Clear Draft")]',
tasksTable: '//*[@data-cy="tasks-table"]',
tableRow: '//tbody//tr',
tableCell: '//table//td',
jumbotron: '[class="jumbotron jumbotron-fluid"]',
priorityImage: '[alt="priority"]',
noPriorityImage: '[alt="no-priority"]',
newInboxRuleTitle: '[id="inbox-rules"] h4',
tableBodyRow: 'tbody tr',
tableCellSpan: 'td span'
};