Skip to content

Commit

Permalink
IVYPORTAL-18039 Write tests for highlighting menu with navigation
Browse files Browse the repository at this point in the history
- Added tests
  • Loading branch information
lttung-axonivy committed Dec 4, 2024
1 parent 4505aa9 commit f122eb3
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ public List<String> getTaskNoteAuthors() {
}

public void clickBackButton() {
$("[id$=':task-detail-title-form:back-to-previous-page']").scrollIntoView(false);
waitForElementClickableThenClick($("[id$=':task-detail-title-form:back-to-previous-page']"));
}

Expand All @@ -331,6 +332,11 @@ public TaskIFrameTemplatePage clickStartTask() {
return new TaskIFrameTemplatePage();
}

public CaseDetailsPage clickStartTaskWithoutDialog() {
$("[id$=':task-detail-start-command']").shouldBe(appear).click();
return new CaseDetailsPage();
}

public void changePriorityOfTask(int priorityValue) {
findElementByCssSelector("[id$=':general-information:priority-form:edit-priority-inplace_display']").click();
waitForElementDisplayed(By.cssSelector("[id$=':general-information:priority-form:priority-select-menu_label']"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.axonivy.portal.selenium.test;

import static com.codeborne.selenide.CollectionCondition.size;
import static com.codeborne.selenide.Condition.appear;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;

Expand All @@ -27,6 +28,14 @@
@IvyWebTest
public class MenuHighlightTest extends BaseTest {

private static final String MAIN_MENU_PROCESS = ".*main-menu_process_1";
private static final String DASHBOARD_PARENT_DASHBOARD_PATTERN = ".*DASHBOARD-parent-dashboard";
private static final String DEFAULT_CASE_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN =
".*default-case-list-dashboard-main-dashboard";
private static final String DASHBOARD_0_PARENT_DASHBOARD_PATTERN = ".*dashboard_0-parent-dashboard";
private static final String DEFAULT_TASK_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN =
".*default-task-list-dashboard-main-dashboard";

@Override
@BeforeEach
public void setup() {
Expand All @@ -36,82 +45,127 @@ public void setup() {
}

@Test
public void testHighlightTaskList() {
public void testHighlightDefaultMenus() {
assertMenuHighlighted(DASHBOARD_0_PARENT_DASHBOARD_PATTERN);
MainMenuPage menuPage = new MainMenuPage();
menuPage.selectProcessesMenu();
assertMenuHighlighted(MAIN_MENU_PROCESS);
menuPage.clickTaskMenu();
assertMenuHighlighted(DEFAULT_TASK_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
menuPage.selectCaseMenu();
assertMenuHighlighted(DEFAULT_CASE_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
menuPage.selectDashboardMenu();
assertMenuHighlighted(DASHBOARD_0_PARENT_DASHBOARD_PATTERN);
NavigationHelper.navigateToProcessList();
assertMenuHighlighted(MAIN_MENU_PROCESS);
NavigationHelper.navigateToTaskList();
assertMenuHighlighted(DEFAULT_TASK_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
NavigationHelper.navigateToCaseList();
assertMenuHighlighted(DEFAULT_CASE_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
createJSonFile("complex-dashboard.json", PortalVariable.DASHBOARD.key);
clickLogo();
assertMenuHighlighted(DASHBOARD_PARENT_DASHBOARD_PATTERN);
$("li[id$='1-sub-dashboard'].active-menuitem").shouldBe(Condition.appear);
}

@Test
public void testHighlightTaskListWithoutSubDashboards() {
executeHighlightMenuScenario();
assertMenuHighlighted(".*dashboard_0-parent-dashboard");
assertMenuHighlighted(DASHBOARD_0_PARENT_DASHBOARD_PATTERN);
}

@Test
public void testHighlightTaskListWithSubDashboards() {
createJSonFile("complex-dashboard.json", PortalVariable.DASHBOARD.key);
executeHighlightMenuScenario();
assertMenuHighlighted(DASHBOARD_PARENT_DASHBOARD_PATTERN);
}

@Test
public void testHighlightCaseList() {
new NewDashboardPage();
MainMenuPage menuPage = new MainMenuPage();
CaseWidgetNewDashBoardPage caseListPage = menuPage.selectCaseMenu();
assertMenuHighlighted(DEFAULT_CASE_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
CaseDetailsPage caseDetailsPage = caseListPage.openDetailsFirstCase();
assertMenuHighlighted(DEFAULT_CASE_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
caseDetailsPage.clickBackButton();
caseListPage = new CaseWidgetNewDashBoardPage();
assertMenuHighlighted(DEFAULT_CASE_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
}

@Test
public void tesChangingtHomepageInUserProfile() {
NewDashboardPage newDashboardPage = new NewDashboardPage();
newDashboardPage.waitForCaseWidgetLoaded();
newDashboardPage.waitForGrowlMessageDisappear();

UserProfilePage profilePage = newDashboardPage.openMyProfilePage();
profilePage.changeNewDashboardPageToCase();
profilePage.saveWithoutWaitingNavigation();
new CaseWidgetNewDashBoardPage();
MainMenuPage menuPage = new MainMenuPage();
menuPage.clickTaskMenu();
assertMenuHighlighted(DEFAULT_TASK_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
TopMenuTaskWidgetPage taskWidgetPage = new TopMenuTaskWidgetPage();
TaskIFrameTemplatePage taskTemplatePage = taskWidgetPage.startTaskIFrameByIndex(0);
getActiveMenuItems().shouldBe(size(0));
taskTemplatePage.clickOnCancelButton();
ElementsCollection menuItems = getActiveMenuItems();
menuItems.shouldBe(size(1));
redirectToRelativeLink(createAlphaCompanyUrl);
new CaseWidgetNewDashBoardPage();
assertMenuHighlighted(DEFAULT_CASE_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
menuPage.clickTaskMenu();
$("td.dashboard-tasks__state").shouldBe(Condition.text("Open"));
taskWidgetPage.startTask(0);
$("td.dashboard-tasks__state").shouldBe(Condition.text("Done"));
taskWidgetPage.getTheFirstTaskWidgetByColumn("State").shouldHave(Condition.text("Done"));
assertMenuHighlighted(DEFAULT_TASK_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
clickLogo();
assertMenuHighlighted(DEFAULT_CASE_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
}

private void executeHighlightMenuScenario() {
NavigationHelper.navigateToTaskList();
$("li[id$='default-task-list-dashboard-main-dashboard']").shouldHave(Condition.cssClass("active-menuitem"));
assertTaskListMenuHighlighted();
assertMenuHighlighted(DEFAULT_TASK_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
TopMenuTaskWidgetPage taskWidgetPage = new TopMenuTaskWidgetPage();
TaskIFrameTemplatePage taskTemplatePage = taskWidgetPage.startTaskIFrameByIndex(0);
getMenuItems().shouldBe(size(0));
getActiveMenuItems().shouldBe(size(0));
taskTemplatePage.clickOnCancelButton();
ElementsCollection menuItems = getMenuItems();
ElementsCollection menuItems = getActiveMenuItems();
menuItems.shouldBe(size(1));
taskWidgetPage = new TopMenuTaskWidgetPage();
TaskDetailsPage taskDetailsPage = taskWidgetPage.openDashboardTaskDetails("Categoried Leave Request");
assertTaskListMenuHighlighted();
assertMenuHighlighted(DEFAULT_TASK_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
taskDetailsPage.gotoBusinessCase();
CaseDetailsPage caseDetailsPage = new CaseDetailsPage();
assertTaskListMenuHighlighted();
assertMenuHighlighted(DEFAULT_TASK_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
caseDetailsPage.clickBackButton();
taskDetailsPage = new TaskDetailsPage();
assertTaskListMenuHighlighted();
$("[id$=':task-detail-title-form:back-to-previous-page']").scrollIntoView(false);
assertMenuHighlighted(DEFAULT_TASK_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
taskDetailsPage.clickBackButton();
taskWidgetPage = new TopMenuTaskWidgetPage();
assertTaskListMenuHighlighted();
$(".sidebar-logo").shouldBe(Condition.appear).click();
}

private void assertTaskListMenuHighlighted() {
assertMenuHighlighted(".*default-task-list-dashboard-main-dashboard");
assertMenuHighlighted(DEFAULT_TASK_LIST_DASHBOARD_MAIN_DASHBOARD_PATTERN);
redirectToRelativeLink(createAlphaCompanyUrl);
NavigationHelper.navigateToTaskList();
taskDetailsPage = taskWidgetPage.openDashboardTaskDetails("Alpha Company");
taskDetailsPage.clickStartTaskWithoutDialog();
getActiveMenuItems().shouldBe(size(0));
clickLogo();
}

private void assertMenuHighlighted(String highlightedMenuItemPattern) {
ElementsCollection menuItems = getMenuItems();
ElementsCollection menuItems = getActiveMenuItems();
menuItems.shouldBe(size(1));
menuItems.first().shouldHave(Condition.attributeMatching("id", highlightedMenuItemPattern));
}
private ElementsCollection getMenuItems() {
return $$("ul[id$=':main-menu'] > li.active-menuitem").filter(Condition.appear);
}

@Test
public void testHighlightDefaultMenu() {
showNewDashboard();
assertMenuHighlighted(".*dashboard_0-parent-dashboard");
MainMenuPage menuPage = new MainMenuPage();
menuPage.selectProcessesMenu();
assertMenuHighlighted(".*main-menu_process_1");
menuPage.selectTaskMenu();
assertTaskListMenuHighlighted();
menuPage.selectCaseMenu();
assertMenuHighlighted(".*default-case-list-dashboard-main-dashboard");
menuPage.selectDashboardMenu();
assertMenuHighlighted(".*dashboard_0-parent-dashboard");
}

@Test
public void testHighlightMenu() {
createJSonFile("complex-dashboard.json", PortalVariable.DASHBOARD.key);
executeHighlightMenuScenario();
assertMenuHighlighted(".*DASHBOARD-parent-dashboard");
private ElementsCollection getActiveMenuItems() {
return $$("ul[id$=':main-menu'] > li.active-menuitem").filter(appear);
}

@Test
public void tesChangingtHomepageInUserProfile() {
NewDashboardPage newDashboardPage = new NewDashboardPage();
newDashboardPage.waitForCaseWidgetLoaded();
newDashboardPage.waitForGrowlMessageDisappear();

UserProfilePage profilePage = newDashboardPage.openMyProfilePage();
profilePage.changeNewDashboardPageToCase();
profilePage.saveWithoutWaitingNavigation();
new CaseWidgetNewDashBoardPage();
private void clickLogo() {
$(".sidebar-logo").shouldBe(appear).click();
}
}

0 comments on commit f122eb3

Please sign in to comment.