Skip to content
Merged
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
70 changes: 70 additions & 0 deletions src/org/labkey/test/pages/admin/FolderAliasesPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2017-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.test.pages.admin;

import org.apache.commons.lang3.StringUtils;
import org.labkey.test.Locator;
import org.labkey.test.pages.LabKeyPage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.Arrays;
import java.util.List;

public class FolderAliasesPage extends LabKeyPage<FolderAliasesPage.ElementCache>
{
public FolderAliasesPage(WebDriver driver)
{
super(driver);
}

public List<String> getAliases()
{
String aliases = getFormElement(elementCache().aliases);
return Arrays.asList(aliases.split("\\R"));
}

public FolderAliasesPage setAliases(List<String> aliases)
{
setFormElement(elementCache().aliases, StringUtils.join(aliases, "\n"));
return this;
}

public FolderManagementPage clickSave()
{
elementCache().saveBtn.click();
return new FolderManagementPage(getDriver());
}
public FolderManagementPage clickCancel()
{
elementCache().cancelBtn.click();
return new FolderManagementPage(getDriver());
}

@Override
protected ElementCache newElementCache()
{
return new ElementCache();
}

protected class ElementCache extends LabKeyPage<?>.ElementCache
{
WebElement aliases = Locator.textarea("aliases").findWhenNeeded(this);

WebElement saveBtn = Locator.lkButton("Save Aliases").refindWhenNeeded(this);
WebElement cancelBtn = Locator.button("Cancel").refindWhenNeeded(this);
}
}
6 changes: 6 additions & 0 deletions src/org/labkey/test/pages/admin/FolderManagementPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ protected ElementCache newElementCache()
return new ElementCache();
}

public FolderAliasesPage goToAliases()
{
beginAt(WebTestHelper.buildRelativeUrl("admin", getCurrentContainerPath(), "folderAliases"));
return new FolderAliasesPage(getDriver());
}

protected class ElementCache extends LabKeyPage.ElementCache
{
private final Map<String, WebElement> tabs = new HashMap<>();
Expand Down
67 changes: 67 additions & 0 deletions src/org/labkey/test/tests/FolderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.labkey.test.categories.Hosting;
import org.labkey.test.components.ext4.Window;
import org.labkey.test.pages.FolderManagementFolderTree;
import org.labkey.test.pages.admin.FolderAliasesPage;
import org.labkey.test.pages.admin.FolderManagementPage;
import org.labkey.test.pages.admin.ReorderFoldersPage;
import org.labkey.test.pages.list.BeginPage;
Expand All @@ -44,9 +45,11 @@
import org.labkey.test.util.LoggedParam;
import org.labkey.test.util.PasswordUtil;
import org.labkey.test.util.PortalHelper;
import org.labkey.test.util.WikiHelper;
import org.labkey.test.util.WorkbookHelper;
import org.openqa.selenium.WebElement;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -99,6 +102,70 @@ public static void testSetup()
init.moveTestProjectToTop();
}

@Test
public void testAliases()
{
String firstContent = "This is the first folder";
String secondContent = "This is the second folder";
String originalName1 = "OriginalName1" + TRICKY_CHARACTERS_FOR_PROJECT_NAMES;
String originalName2 = "OriginalName2" + TRICKY_CHARACTERS_FOR_PROJECT_NAMES;
String newName = "NewName" + TRICKY_CHARACTERS_FOR_PROJECT_NAMES;
String additionalAlias = "AdditionalAlias" + TRICKY_CHARACTERS_FOR_PROJECT_NAMES;

// Create folders and give them a wiki as content so we can be sure we land in the right spot when following an alias
_containerHelper.createSubfolder(getProjectName(), originalName1);
createWikiAndAddToPortal(firstContent, originalName1);
_containerHelper.createSubfolder(getProjectName(), originalName2);
createWikiAndAddToPortal(secondContent, originalName2);

_containerHelper.renameFolder(getProjectName(), originalName1, newName, true);
navigateToFolder(getProjectName(), newName);
assertTextPresent(firstContent);

// Ensure the alias was created and works
beginAt(WebTestHelper.buildURL("project", getProjectName() + "/" + originalName1 , "begin"));
assertTextPresent(firstContent);
FolderAliasesPage aliasesPage = goToFolderManagement().goToAliases();
List<String> aliases = new ArrayList<>(aliasesPage.getAliases());
// Ensure it's being saved as lower case
assertEquals(Arrays.asList(("/" + getProjectName() + "/" + originalName1).toLowerCase()), aliases);
aliases.add("/" + getProjectName() + "/" + additionalAlias);
aliasesPage.setAliases(aliases);
aliasesPage.clickSave();

beginAt(WebTestHelper.buildURL("project", getProjectName() + "/" + originalName1 , "begin"));
assertTextPresent(firstContent);
beginAt(WebTestHelper.buildURL("project", getProjectName() + "/" + additionalAlias , "begin"));
assertTextPresent(firstContent);

// Steal the alias in another folder
navigateToFolder(getProjectName(), originalName2);
assertTextPresent(secondContent);
aliasesPage = goToFolderManagement().goToAliases();
aliasesPage.setAliases(Arrays.asList("/" + getProjectName() + "/" + additionalAlias));
aliasesPage.clickSave();
beginAt(WebTestHelper.buildURL("project", getProjectName() + "/" + additionalAlias , "begin"));
assertTextPresent(secondContent);
}

private void createWikiAndAddToPortal(String body, String folderName)
{
navigateToFolder(getProjectName(), folderName);
WikiHelper wikiHelper = new WikiHelper(this);
wikiHelper.createNewWikiPage("HTML");
String pageName = "ReferencePoint";
wikiHelper.setWikiName(pageName);
wikiHelper.setWikiTitle(pageName);
wikiHelper.setWikiBody(body);
wikiHelper.saveWikiPage();

navigateToFolder(getProjectName(), folderName);
PortalHelper portalHelper = new PortalHelper(this);
portalHelper.addBodyWebPart("Wiki");
wikiHelper.clickChooseAPage();
wikiHelper.saveChosenPage();
}

@LogMethod
private void moveTestProjectToTop() // todo: use FolderManagementPage, ReorderFoldersPage
{
Expand Down
6 changes: 2 additions & 4 deletions src/org/labkey/test/tests/wiki/WikiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ public void testUpdateWikiWithHostileNameAndTitle() throws Exception
var createResponse = createCmd.execute(cn, getProjectName());
var createResponseJson = new JSONObject(createResponse.getParsedData());
var wikiProps = createResponseJson.getJSONObject("wikiProps");
SearchAdminAPIHelper.waitForIndexer();

// now, update the wiki with hostile inputs, expecting error/failure
var updateJson = new JSONObject();
Expand Down Expand Up @@ -372,7 +371,6 @@ public void testRenameWebPartWiki() throws Exception
createJson.put("pageVersionId", -1);
createCmd.setJsonObject(createJson);
createCmd.execute(cn, SUBFOLDER_PATH);
SearchAdminAPIHelper.waitForIndexer();

// give the folder a wikiWebPart
goToProjectFolder(PROJECT_NAME, SUBFOLDER_NAME);
Expand All @@ -383,13 +381,13 @@ public void testRenameWebPartWiki() throws Exception
.descendant(Locator.tagWithText("p", "content for wiki webpart rename"));

// configure the webPart to use the wiki created above
waitAndClickAndWait(Locator.linkWithText("Choose an existing page to display"));
wikiHelper.clickChooseAPage();
var selectedPageOption = getSelectedOptionText(Locator.name("name"));
checker().withScreenshot("unexpected_selected_page")
.wrapAssertion(()-> Assertions.assertThat(selectedPageOption)
.as("expect our wiki to be selected")
.startsWith(wikiName));
waitAndClickAndWait(Locator.id("btnSubmit"));
wikiHelper.saveChosenPage();

// verify the webpart's content is our expected content
checker().withScreenshot("unexpected_wiki_content")
Expand Down
13 changes: 13 additions & 0 deletions src/org/labkey/test/util/WikiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ private void setWikiSourceTab(String srcFragment)
_test.setFormElement(Locator.name("body"), srcFragment);
}

/** For customizing wiki web parts */
public void clickChooseAPage()
{
_test.waitAndClickAndWait(Locator.linkWithText("Choose an existing page to display"));
}

/** For customizing wiki web parts */
public void saveChosenPage()
{
_test.waitAndClickAndWait(Locator.id("btnSubmit"));
}


public void saveWikiPage()
{
saveWikiPage(true);
Expand Down