Skip to content
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

Fix Wiki tests after TinyMCE upgrade #1731

Merged
merged 9 commits into from
Dec 1, 2023
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
11 changes: 11 additions & 0 deletions src/org/labkey/test/LabKeySiteWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,17 @@ public void stopImpersonating(boolean goHome)
goToHome();
}

/**
* Stop impersonating user
* @param goHome go to Server Home or return to page where impersonation started
*/
public void stopImpersonatingWithUnloadAlert(boolean goHome)
{
navBar().stopImpersonatingWithUnloadAlert();
if (goHome)
goToHome();
}

/**
* Impersonate a user and perform some action.
* Stops impersonating and returns to initial page when complete.
Expand Down
9 changes: 9 additions & 0 deletions src/org/labkey/test/components/html/SiteNavBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ public void stopImpersonating()
getWrapper().assertSignedInNotImpersonating();
}

public void stopImpersonatingWithUnloadAlert()
{
if (!getWrapper().isImpersonating())
throw new IllegalStateException("Not currently impersonating");

getWrapper().doAndAcceptUnloadAlert(()->getWrapper().clickAndWait(Locator.xpath("//a[@class='btn btn-primary' and text()='Stop impersonating']").findElement(getDriver()), 0));
getWrapper().assertSignedInNotImpersonating();
}

public boolean isInPageAdminMode()
{
return getWrapper().executeScript("return LABKEY.pageAdminMode;", Boolean.class);
Expand Down
1 change: 0 additions & 1 deletion src/org/labkey/test/tests/wiki/EmbeddedWebPartTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ private void embeddedQueryWebPartDoesNotRefreshOnChange()
//embed query part in wiki page
portalHelper.addWebPart("Wiki");
wikiHelper.createNewWikiPage();
click(Locator.linkContainingText("Source"));
setFormElement(Locator.name("name"), TRICKY_CHARACTERS + "wiki page");

wikiHelper.setWikiBody(TestFileUtils.getFileContents(TestFileUtils.getSampleData("api/EmbeddedQueryWebPart.html")));
Expand Down
4 changes: 2 additions & 2 deletions src/org/labkey/test/tests/wiki/WikiLongTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public void testSteps()
clickProject(PROJECT_NAME);
_permissionsHelper.enterPermissionsUI();
_permissionsHelper.setPermissions(USERS_GROUP, "Project Administrator");
clickButton("Save and Finish");
clickButtonContainingText("Save and Finish");

log("make sure the changes went through");
impersonate(USER1);
Expand Down Expand Up @@ -530,7 +530,7 @@ public void testSteps()
_wikiHelper.saveWikiPage(false);
waitForText("There was a problem while saving: Illegal attribute 'onclick' on element <a>");

stopImpersonating();
stopImpersonating(false);

log("delete wiki web part");
clickProject(PROJECT2_NAME);
Expand Down
25 changes: 14 additions & 11 deletions src/org/labkey/test/tests/wiki/WikiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ public void testSteps()
assertTextPresent(file.getName(), "Some HTML content");
final Locator.XPathLocator wikiTitleLink = Locator.linkContainingText("_Test Wiki").withAttribute("href");
assertElementPresent(wikiTitleLink);
impersonateRole("Reader");
assertElementNotPresent(wikiTitleLink);
stopImpersonating();

log("test search wiki");
searchFor(PROJECT_NAME, "Wiki", numberOfWikiCreated, WIKI_PAGE_TITLE);
Expand Down Expand Up @@ -160,9 +157,11 @@ public void testEmbeddedVideoInWiki()
{
String wikiName = "Wiki with video";
String wikiTitle = "Sample finder video";
String wikiContent = "Some random content start : Have fun watching video below\n" +
"{video:https://www.youtube.com/embed/JEE4807UHN4|height:350|width:500}\n" +
"Hope you fun watching the video..!\n";
String wikiContent = """
Some random content start : Have fun watching video below
{video:https://www.youtube.com/embed/JEE4807UHN4|height:350|width:500}
Hope you had fun watching the video..!
""";

goToProjectHome();
log("Creating the wiki with video");
Expand Down Expand Up @@ -232,7 +231,8 @@ protected void verifyWikiPagePresent()

protected void doTestInlineEditor()
{
Locator.XPathLocator inlineEditor = Locator.xpath("//div[@class='labkey-inline-editor']");
Locator.XPathLocator inlineEditor = Locator.xpath("//div[@class='labkey-inline-editor']")
.withDescendant(Locator.tagWithClassContaining("div", "tox-edit-area"));

log("** test inline wiki webpart editor");
goToProjectHome();
Expand Down Expand Up @@ -279,10 +279,13 @@ protected void doTestInlineEditor()

protected void setInlineEditorContent(String editorId, String content)
{
executeScript("if (!tinyMCE) {throw 'tinyMCE API is not available'}" +
"editor = tinyMCE.getInstanceById(arguments[0]);" +
"if (!editor) {throw 'No tinyMCE instance: ' + arguments[0];}" +
"editor.setContent(arguments[1]);", editorId, content);
executeScript("if (!tinymce) {throw 'tinymce API is not available'}" +
"editor = tinymce.get(arguments[0]);" +
"if (!editor) {throw 'No tinymce instance: ' + arguments[0];}" +
"editor.setContent(arguments[1]);" +
"editor.setDirty(true);" // Explicitly setDirty as the setContent doesn't by default
, editorId, content);
log(String.format("Content [%1$s] set on editor: %2$s", content, editorId));
}

@Override
Expand Down
12 changes: 10 additions & 2 deletions src/org/labkey/test/util/WikiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ public void switchWikiToSourceView()
{
if (_test.isElementPresent(Locator.css("#wiki-tab-source.labkey-tab-inactive")))
{
_test.click(Locator.css("#wiki-tab-source > a"));
Locator tab = Locator.css("#wiki-tab-source > a");
_test.waitForElementToBeVisible(tab);
_test.click(tab);
_test.waitForElement(Locator.css("#wiki-tab-source.labkey-tab-active"));
}
}
Expand All @@ -280,7 +282,13 @@ public void switchWikiToVisualView()
{
if (_test.isElementPresent(Locator.css("#wiki-tab-visual.labkey-tab-inactive")))
{
_test.click(Locator.css("#wiki-tab-visual > a"));
Locator tab = Locator.css("#wiki-tab-visual > a");
_test.waitForElementToBeVisible(tab);
_test.click(tab);

Locator yesButton = Locator.tagWithText("span","Yes");
_test.waitForElementToBeVisible(yesButton);
_test.waitAndClick(yesButton);
labkey-ians marked this conversation as resolved.
Show resolved Hide resolved
_test.waitForElement(Locator.css("#wiki-tab-visual.labkey-tab-active"));
}
}
Expand Down