Skip to content

Commit

Permalink
XWIKI-22659: createinline template error when clicking on a link to m…
Browse files Browse the repository at this point in the history
…issing top level page

  * Compute proper reference in case of top level page
  * Provide a new integration test covering the bug
  * Change a bit existing PO for CreatePagePage to allow using it also
    for the modal
  • Loading branch information
surli committed Nov 18, 2024
1 parent 4eb3bb0 commit c2eec29
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.xwiki.test.ui.TestUtils;
import org.xwiki.test.ui.po.CreatePagePage;
import org.xwiki.test.ui.po.DocumentDoesNotExistPage;
import org.xwiki.test.ui.po.PageTypePicker;
import org.xwiki.test.ui.po.ViewPage;
import org.xwiki.test.ui.po.editor.EditPage;
import org.xwiki.test.ui.po.editor.WikiEditPage;
Expand Down Expand Up @@ -116,10 +115,9 @@ void createPagesFromTemplate(TestUtils setup, TestReference testReference) throw
// Verify that clicking on the wanted link pops up a box to choose the template.
EntityReference wantedLinkReference =
setup.resolveDocumentReference(testSpace + "." + TEMPLATE_NAME + "Instance" + ".NewPage");
vp.clickWantedLink(wantedLinkReference, true);
PageTypePicker pageTypePicker = new PageTypePicker();
assertEquals(availableTemplateSize, pageTypePicker.countAvailableTemplates());
assertTrue(pageTypePicker.getAvailableTemplates().contains(templateProviderFullName));
createPagePage = vp.clickWantedLink(wantedLinkReference);
assertEquals(availableTemplateSize, createPagePage.getAvailableTemplateSize());
assertTrue(createPagePage.getAvailableTemplates().contains(templateProviderFullName));

// Step 3: Create a new page when located on a non-existing page

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import org.xwiki.test.ui.po.CreatePagePage;
import org.xwiki.test.ui.po.ViewPage;
import org.xwiki.test.ui.po.editor.EditPage;
import org.xwiki.test.ui.po.editor.WikiEditPage;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Tests basic page and space creation.
Expand Down Expand Up @@ -200,5 +202,21 @@ void createPageWithDefaultTitleWithVelocity(TestUtils setup, TestReference refer
assertEquals("${escapetool.h}if()", editPage.getDocumentTitle());
}

@Test
@Order(4)
void createTopLevelPageFromWantedLink(TestUtils setup, TestReference reference) throws Exception
{
DocumentReference topLevelDoc = new DocumentReference("xwiki", "TopLevelWantedLink", "WebHome");
setup.rest().delete(topLevelDoc);
ViewPage page = setup.createPage(reference, "[[TopLevelWantedLink>>xwiki:TopLevelWantedLink.WebHome]]");
CreatePagePage createPagePage = page.clickWantedLink(topLevelDoc);
createPagePage.clickCreate();
WikiEditPage editPage = new WikiEditPage();
editPage.sendKeys("Some new content");
page = editPage.clickSaveAndView();
assertEquals("Some new content", page.getContent());
assertTrue(page.getBreadcrumb().hasPathElement("TopLevelWantedLink", true, true));
}

// TODO: Add a test for the input validation.
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @version $Id$
* @since 3.2M3
*/
public class CreatePagePage extends ViewPage
public class CreatePagePage extends BaseElement
{
private static final By errorMessageLocator = By.className("errormessage");

Expand All @@ -53,7 +53,7 @@ public class CreatePagePage extends ViewPage
@FindBy(id = "terminal")
private WebElement isTerminalCheckbox;

@FindBy(css = "form#create input[type='submit']")
@FindBy(css = "form#create input[type='submit'],form#create button[type='submit']")
private WebElement createButton;

public static CreatePagePage gotoPage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.xwiki.test.ui.po;

import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;

import org.openqa.selenium.By;
Expand Down Expand Up @@ -135,12 +136,17 @@ public void clickWantedLink(String spaceName, String pageName, boolean waitForTe
clickWantedLink(new DocumentReference("xwiki", spaceName, pageName), waitForTemplateDisplay);
}

public CreatePagePage clickWantedLink(EntityReference reference)
{
return clickWantedLink(reference, true).get();
}

/**
* Clicks on a wanted link in the page.
*
* @since 7.2M2
*/
public void clickWantedLink(EntityReference reference, boolean waitForTemplateDisplay)
public Optional<CreatePagePage> clickWantedLink(EntityReference reference, boolean waitForTemplateDisplay)
{
WebElement brokenLink = getDriver().findElement(
By.xpath("//span[@class='wikicreatelink']/a[contains(@href,'/create/" + getUtil().getURLFragment(reference)
Expand All @@ -152,7 +158,9 @@ public void clickWantedLink(EntityReference reference, boolean waitForTemplateDi
// will all have been displayed.
getDriver().waitUntilElementIsVisible(
By.xpath("//div[@class='modal-dialog']//form[@id='create']//button[@type='submit']"));
return Optional.of(new CreatePagePage());
}
return Optional.empty();
}

public BreadcrumbElement getBreadcrumb()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,12 @@
<span class='label'>$escapetool.xml($services.localization.render('core.create.pageTitle'))</span>
</dt>
<dl>
#set ($targetDocumentReference = $services.model.createDocumentReference($name, $spaceReference))
## We are creating a top level space.
#if ("$!spaceReference" == '' && $isSpace)
#set ($targetDocumentReference = $services.model.createDocumentReference('WebHome', $name))
#else
#set ($targetDocumentReference = $services.model.createDocumentReference($name, $spaceReference))
#end
#hierarchy($targetDocumentReference)
</dl>
#end
Expand Down

0 comments on commit c2eec29

Please sign in to comment.