Search in sources :

Example 1 with CopyOverwritePromptPage

use of org.xwiki.test.ui.po.CopyOverwritePromptPage in project xwiki-platform by xwiki.

the class CopyPageTest method testCopyOverwritePage.

@Test
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
public void testCopyOverwritePage() throws Exception {
    String sourceSpaceName = getTestClassName();
    String sourcePageName = getTestMethodName();
    String targetSpaceName = getTestClassName() + "Copy";
    String targetPageName = getTestMethodName() + "Copy";
    // Delete page that may already exist
    getUtil().rest().deletePage(sourceSpaceName, sourcePageName);
    getUtil().rest().deletePage(targetSpaceName, targetPageName);
    // Create a new page that will be overwritten.
    getUtil().rest().savePage(new LocalDocumentReference(targetSpaceName, targetPageName), OVERWRITTEN_PAGE_CONTENT, targetPageName);
    // Create a new page that will be copied.
    ViewPage viewPage = getUtil().createPage(sourceSpaceName, sourcePageName, PAGE_CONTENT, sourcePageName);
    // Click on Copy from the Page top menu.
    viewPage.copy();
    CopyPage copyPage = new CopyPage();
    // Fill the target destination the page to be copied to.
    DocumentPicker documentPicker = copyPage.getDocumentPicker();
    documentPicker.setTitle(targetPageName);
    documentPicker.browseDocuments();
    DocumentPickerModal documentPickerModal = new DocumentPickerModal();
    documentPickerModal.waitForDocumentSelected(sourceSpaceName, "WebHome").selectDocument(targetSpaceName, "WebHome");
    documentPicker.waitForLocation(Arrays.asList("", targetSpaceName, targetPageName));
    Assert.assertEquals(targetSpaceName, copyPage.getTargetSpaceName());
    // Click copy button
    CopyOverwritePromptPage copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
    // Check overwrite warning
    Assert.assertEquals(OVERWRITE_PROMPT1 + targetSpaceName + '.' + targetPageName + OVERWRITE_PROMPT2, copyOverwritePrompt.getWarningMessage());
    // Cancel the copy
    viewPage = copyOverwritePrompt.clickCancelButton();
    // Verify that we have been sent back to the original page
    Assert.assertEquals(sourcePageName, viewPage.getDocumentTitle());
    // Click on Copy from the Page top menu.
    viewPage.copy();
    copyPage = new CopyPage();
    // Fill the target destination the page to be copied to.
    copyPage.getDocumentPicker().toggleLocationAdvancedEdit().setParent(targetSpaceName).setName(targetPageName);
    // Click copy button
    copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
    // Click change target
    copyOverwritePrompt.clickChangeTargetButton();
    copyPage = new CopyPage();
    // Check the source document
    Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), copyPage.getSourceLocation().getPath());
    Assert.assertEquals(sourceSpaceName, copyPage.getSourceSpaceName());
    Assert.assertEquals(sourcePageName, copyPage.getSourcePageName());
    // Check the default target document.
    documentPicker = copyPage.getDocumentPicker();
    Assert.assertEquals(sourcePageName, documentPicker.getTitle());
    Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), documentPicker.getLocation().getPath());
    Assert.assertEquals(sourceSpaceName, copyPage.getTargetSpaceName());
    Assert.assertEquals(sourcePageName, copyPage.getTargetPageName());
    // Fill the target destination the page to be copied to.
    documentPicker.setTitle("My copy").toggleLocationAdvancedEdit().setParent(targetSpaceName).setName(targetPageName);
    // Copy and confirm overwrite
    copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
    CopyOrRenameStatusPage copyStatusPage = copyOverwritePrompt.clickCopyButton().waitUntilFinished();
    // Check successful copy confirmation
    Assert.assertEquals(COPY_SUCCESSFUL, copyStatusPage.getInfoMessage());
    viewPage = copyStatusPage.gotoNewPage();
    // Verify that the title of the copy has been updated (independent from the name of the copy).
    Assert.assertEquals("My copy", viewPage.getDocumentTitle());
    Assert.assertEquals(PAGE_CONTENT, viewPage.getContent());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) CopyOrRenameStatusPage(org.xwiki.test.ui.po.CopyOrRenameStatusPage) CopyPage(org.xwiki.index.test.po.CopyPage) DocumentPickerModal(org.xwiki.index.tree.test.po.DocumentPickerModal) CopyOverwritePromptPage(org.xwiki.test.ui.po.CopyOverwritePromptPage) ViewPage(org.xwiki.test.ui.po.ViewPage) DocumentPicker(org.xwiki.test.ui.po.DocumentPicker) Test(org.junit.Test) IgnoreBrowser(org.xwiki.test.ui.browser.IgnoreBrowser)

Aggregations

Test (org.junit.Test)1 CopyPage (org.xwiki.index.test.po.CopyPage)1 DocumentPickerModal (org.xwiki.index.tree.test.po.DocumentPickerModal)1 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)1 IgnoreBrowser (org.xwiki.test.ui.browser.IgnoreBrowser)1 CopyOrRenameStatusPage (org.xwiki.test.ui.po.CopyOrRenameStatusPage)1 CopyOverwritePromptPage (org.xwiki.test.ui.po.CopyOverwritePromptPage)1 DocumentPicker (org.xwiki.test.ui.po.DocumentPicker)1 ViewPage (org.xwiki.test.ui.po.ViewPage)1