Skip to content

Commit

Permalink
adding test for 'expand/collapse' org
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Sep 22, 2020
1 parent e532b14 commit d86a36a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 26 deletions.
Expand Up @@ -220,7 +220,7 @@ public void mod10test04FinishingManagerMapping() {
OrgRootTab rootTab = basicPage.orgStructure()
.selectTabWithRootOrg("ExAmPLE, Inc. - Functional Structure");
Assert.assertTrue(rootTab.getOrgHierarchyPanel()
.expandAllOrgs()
.expandOrg("Technology Division")
.selectOrgInTree("IT Administration Department")
.and()
.getManagerPanel()
Expand Down
Expand Up @@ -7,11 +7,14 @@
package com.evolveum.midpoint.testing.schrodinger.scenarios;

import com.evolveum.midpoint.schrodinger.page.configuration.ImportObjectPage;
import com.evolveum.midpoint.schrodinger.page.org.OrgTreePage;
import com.evolveum.midpoint.schrodinger.page.resource.ListResourcesPage;
import com.evolveum.midpoint.schrodinger.page.user.ListUsersPage;
import com.evolveum.midpoint.schrodinger.page.user.UserPage;
import com.evolveum.midpoint.schrodinger.util.ConstantsUtil;
import com.evolveum.midpoint.testing.schrodinger.AbstractSchrodingerTest;
import com.evolveum.midpoint.web.page.admin.users.PageOrgTree;

import org.apache.commons.io.FileUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -67,7 +70,7 @@ public void importOrgStructure() throws IOException {
);
}

@Test (dependsOnMethods ={IMPORT_ORG_STRUCT_DEPENDENCY})
// @Test (dependsOnMethods ={IMPORT_ORG_STRUCT_DEPENDENCY})
public void assignOrgUnit(){
ListUsersPage users = basicPage.listUsers();
UserPage userPage = users
Expand Down Expand Up @@ -98,7 +101,7 @@ public void assignOrgUnit(){
;
}

@Test (dependsOnMethods ={ORG_UNIT_ACCOUNT_INDUCEMENT_DEPENDENCY})
// @Test (dependsOnMethods ={ORG_UNIT_ACCOUNT_INDUCEMENT_DEPENDENCY})
public void unassignOrgUnit(){
ListUsersPage users = basicPage.listUsers();
UserPage userPage = users
Expand All @@ -120,7 +123,7 @@ public void unassignOrgUnit(){
.isSuccess();
}

@Test (dependsOnMethods ={ASSIGN_ORG_UNIT_DEPENDENCY})
// @Test (dependsOnMethods ={ASSIGN_ORG_UNIT_DEPENDENCY})
public void orgUnitAccountInducement(){
importObject(CSV_RESOURCE_ADVANCED_SYNC,true);
importObject(ORG_ACCOUNT_INDUCEMENT_FILE);
Expand Down Expand Up @@ -159,6 +162,22 @@ public void orgUnitAccountInducement(){
.isSuccess();
}

@Test (dependsOnMethods ={IMPORT_ORG_STRUCT_DEPENDENCY})
public void expandCollapseAllTests(){
OrgTreePage orgPage = basicPage.orgStructure();
Assert.assertTrue(orgPage.selectTabWithRootOrg("Governor Office")
.getOrgHierarchyPanel()
.showTreeNodeDropDownMenu("Ministry of Offense")
.expandAll()
.containsChildOrg("Swashbuckler Section", "Ministry of Health"));

Assert.assertFalse(orgPage.selectTabWithRootOrg("Governor Office")
.getOrgHierarchyPanel()
.showTreeNodeDropDownMenu("Ministry of Offense")
.collapseAll()
.containsChildOrg("Swashbuckler Section", false, "Ministry of Health"));
}

public void changeResourceFilePath(){
ListResourcesPage listResourcesPage = basicPage.listResources();

Expand Down
Expand Up @@ -4,4 +4,4 @@ base_url=http://localhost:8180/midpoint
webdriver=CHROME
webdriverLocation=/opt/chromedriver
# By default if no value is specified for headless start then the value is: false
headlessStart=true
headlessStart=false
Expand Up @@ -91,6 +91,17 @@
<locality>Mêlée Island</locality>
</org>

<org oid="00000000-8888-6666-0000-100000000007">
<name>F0007</name>
<parentOrgRef oid="00000000-8888-6666-0000-100000000005" type="c:OrgType"/>
<assignment id="1">
<targetRef oid="00000000-8888-6666-0000-100000000005" type="c:OrgType"/>
</assignment>
<displayName>Ministry of Health</displayName>
<identifier>0007</identifier>
<orgType>functional</orgType>
</org>

<!-- Project organizational structure -->

<org oid="00000000-8888-6666-0000-200000000000">
Expand Down
Expand Up @@ -34,43 +34,43 @@ public OrgHierarchyPanel(T parent, SelenideElement parentElement) {
public OrgHierarchyPanel<T> selectOrgInTree(String orgName) {
boolean exist = getParentElement().$(Schrodinger.byElementValue("span", "class", "tree-label", orgName)).exists();
if (!exist) {
expandAllIfNeeded();
expandAllIfNeeded(orgName);
}
getParentElement().$(Schrodinger.byElementValue("span", "class", "tree-label", orgName))
.waitUntil(Condition.appear, MidPoint.TIMEOUT_DEFAULT_2_S).click();
Selenide.sleep(MidPoint.TIMEOUT_DEFAULT_2_S);
return this;
}

private void expandAllIfNeeded() {
private void expandAllIfNeeded(String orgName) {
boolean existExpandButton = getParentElement().$(By.cssSelector(".tree-junction-collapsed")).exists();
if (existExpandButton) {
expandAllOrgs();
}
showTreeNodeDropDownMenu(orgName).expandAll();
Selenide.sleep(MidPoint.TIMEOUT_DEFAULT_2_S);
}

public OrgHierarchyPanel<T> expandAllOrgs() {
clickOnTreeMenu();
getParentElement().$(Schrodinger.byDataResourceKey("schrodinger", "TreeTablePanel.expandAll")).parent()
.waitUntil(Condition.appear, MidPoint.TIMEOUT_DEFAULT_2_S).click();
return this;
}

private void clickOnTreeMenu() {
getParentElement().$(Schrodinger.byDataId("div", "treeMenu")).click();
}

public boolean containsChildOrg(String parentOrg, String... expectedChild){
expandAllIfNeeded();
public boolean containsChildOrg(String parentOrg, Boolean expandParent, String... expectedChild){
if (expandParent) {
expandAllIfNeeded(parentOrg);
}
SelenideElement parentNode = getParentOrgNode(parentOrg);
SelenideElement subtree = parentNode.$x(".//div[@"+Schrodinger.DATA_S_ID+"='subtree']");
ElementsCollection childsLabels = subtree.$$x(".//span[@"+Schrodinger.DATA_S_ID+"='label']");
List<String> childs = new ArrayList<String>();
for (SelenideElement childLabel : childsLabels) {
childs.add(childLabel.getText());
ElementsCollection childLabels = subtree.$$x(".//span[@"+Schrodinger.DATA_S_ID+"='label']");
List<String> child = new ArrayList<String>();
if (!subtree.exists()) {
return false;
}
for (SelenideElement childLabel : childLabels) {
child.add(childLabel.getText());
}
return childs.containsAll(Arrays.asList(expectedChild));
return child.containsAll(Arrays.asList(expectedChild));
}

public boolean containsChildOrg(String parentOrg, String... expectedChild){
return containsChildOrg(parentOrg, true, expectedChild);
}

private SelenideElement getParentOrgNode (String parentOrg) {
Expand All @@ -89,13 +89,13 @@ public OrgHierarchyPanel<T> expandOrg(String orgName) {
return this;
}

public OrgTreeNodeDropDown showTreeNodeDropDownMenu(String orgName) {
public OrgTreeNodeDropDown<OrgHierarchyPanel> showTreeNodeDropDownMenu(String orgName) {
SelenideElement parentNode = getParentOrgNode(orgName);
SelenideElement node = parentNode.$x(".//div[@"+Schrodinger.DATA_S_ID+"='node']");
SelenideElement menuButton = node.$x(".//span[@" + Schrodinger.DATA_S_ID + "='menu']");
menuButton.waitUntil(Condition.appear, MidPoint.TIMEOUT_DEFAULT_2_S).click();
SelenideElement menu = menuButton.$x(".//ul[@" + Schrodinger.DATA_S_ID + "='dropDownMenu']").waitUntil(Condition.appear, MidPoint.TIMEOUT_DEFAULT_2_S);

return new OrgTreeNodeDropDown(this, menu);
return new OrgTreeNodeDropDown<OrgHierarchyPanel>(this, menu);
}
}
Expand Up @@ -31,4 +31,18 @@ public OrgPage edit(){
Selenide.sleep(MidPoint.TIMEOUT_DEFAULT_2_S);
return new OrgPage();
}

public T expandAll(){
getParentElement().$x(".//schrodinger[@"+ Schrodinger.DATA_S_RESOURCE_KEY +"='TreeTablePanel.expandAll']").parent()
.waitUntil(Condition.appear, MidPoint.TIMEOUT_DEFAULT_2_S).click();
Selenide.sleep(MidPoint.TIMEOUT_SHORT_4_S);
return getParent();
}

public T collapseAll(){
getParentElement().$x(".//schrodinger[@"+ Schrodinger.DATA_S_RESOURCE_KEY +"='TreeTablePanel.collapseAll']").parent()
.waitUntil(Condition.appear, MidPoint.TIMEOUT_DEFAULT_2_S).click();
Selenide.sleep(MidPoint.TIMEOUT_SHORT_4_S);
return getParent();
}
}

0 comments on commit d86a36a

Please sign in to comment.