Search in sources :

Example 1 with ChangesPane

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

the class ExtensionIT method testUpgradeWithMergeConflict.

/**
 * Tests how an extension is upgraded when there is a merge conflict.
 */
@Test
public void testUpgradeWithMergeConflict() throws Exception {
    // Setup the extension.
    String extensionId = "alice-xar-extension";
    String oldVersion = "1.3";
    String newVersion = "2.1.4";
    TestExtension oldExtension = getRepositoryTestUtils().getTestExtension(new ExtensionId(extensionId, oldVersion), "xar");
    getRepositoryTestUtils().addExtension(oldExtension);
    TestExtension newExtension = getRepositoryTestUtils().getTestExtension(new ExtensionId(extensionId, newVersion), "xar");
    getRepositoryTestUtils().attachFile(newExtension);
    getRepositoryTestUtils().addVersionObject(newExtension, newVersion, "attach:" + newExtension.getFile().getName());
    // Make sure the old version is installed.
    getExtensionTestUtils().install(new ExtensionId(extensionId, oldVersion));
    // Edit the installed version so that we have a merge conflict.
    Map<String, String> queryParameters = new HashMap<String, String>();
    queryParameters.put("title", "Alice Extension");
    queryParameters.put("content", "== Usage ==\n\n{{code language=\"none\"}}\n" + "{{alice/}}\n{{/code}}\n\n== Output ==\n\n{{alice/}}");
    queryParameters.put("XWiki.WikiMacroClass_0_code", "{{info}}Alice says hello!{{/info}}");
    getUtil().gotoPage("ExtensionTest", "Alice", "save", queryParameters);
    // Initiate the upgrade process.
    ExtensionAdministrationPage adminPage = ExtensionAdministrationPage.gotoPage();
    SearchResultsPane searchResults = adminPage.getSearchBar().clickAdvancedSearch().search(extensionId, newVersion);
    ExtensionPane extensionPane = searchResults.getExtension(0);
    extensionPane = extensionPane.upgrade().confirm();
    // Check the merge conflict UI.
    assertEquals("loading", extensionPane.getStatus());
    assertNull(extensionPane.getStatusMessage());
    ProgressBarPane progressBar = extensionPane.getProgressBar();
    assertEquals(66, progressBar.getPercent());
    assertEquals("Conflict between [@@ -1,1 +1,1 @@] and [@@ -1,1 +1,1 @@]", progressBar.getMessage());
    ExtensionProgressPane progressPane = extensionPane.openProgressSection();
    WebElement jobLogLabel = progressPane.getJobLogLabel();
    assertEquals("INSTALL LOG".toLowerCase(), jobLogLabel.getText().toLowerCase());
    // The job log is collapsed when the job is waiting for user input so we need to expand it before asserting its
    // content (otherwise #getText() returns the empty string because the text is not visible).
    jobLogLabel.click();
    List<LogItemPane> upgradeLog = progressPane.getJobLog();
    LogItemPane lastLogItem = upgradeLog.get(upgradeLog.size() - 1);
    assertEquals("loading", lastLogItem.getLevel());
    assertEquals(progressBar.getMessage(), lastLogItem.getMessage());
    MergeConflictPane mergeConflictPane = progressPane.getMergeConflict();
    ChangesPane changesPane = mergeConflictPane.getChanges();
    assertEquals(Arrays.asList("Page properties", "XWiki.WikiMacroClass[0]"), changesPane.getChangedEntities());
    EntityDiff pagePropertiesDiff = changesPane.getEntityDiff("Page properties");
    assertEquals(Arrays.asList("Parent", "Content"), pagePropertiesDiff.getPropertyNames());
    assertFalse(pagePropertiesDiff.getDiff("Content").isEmpty());
    EntityDiff macroDiff = changesPane.getEntityDiff("XWiki.WikiMacroClass[0]");
    assertEquals(Arrays.asList("Macro description"), macroDiff.getPropertyNames());
    assertEquals(Arrays.asList("@@ -1,1 +1,1 @@", "-<del>Test</del> macro.", "+<ins>A</ins> <ins>cool </ins>macro."), macroDiff.getDiff("Macro description"));
    mergeConflictPane.getFromVersionSelect().selectByVisibleText("Previous version");
    mergeConflictPane.getToVersionSelect().selectByVisibleText("Current version");
    mergeConflictPane = mergeConflictPane.clickShowChanges();
    changesPane = mergeConflictPane.getChanges();
    List<String> expectedDiff = new ArrayList<>();
    expectedDiff.add("@@ -1,9 +1,9 @@");
    expectedDiff.add("-= Usage =");
    expectedDiff.add("+=<ins>=</ins> Usage =<ins>=</ins>");
    expectedDiff.add(" ");
    expectedDiff.add("-{{code}}");
    expectedDiff.add("+{{code<ins> language=\"none\"</ins>}}");
    expectedDiff.add(" {{alice/}}");
    expectedDiff.add(" {{/code}}");
    expectedDiff.add(" ");
    expectedDiff.add("-= <del>Res</del>u<del>l</del>t =");
    expectedDiff.add("+=<ins>=</ins> <ins>O</ins>ut<ins>put</ins> =<ins>=</ins>");
    expectedDiff.add(" ");
    expectedDiff.add(" {{alice/}}");
    assertEquals(expectedDiff, changesPane.getEntityDiff("Page properties").getDiff("Content"));
    assertEquals(1, changesPane.getDiffSummary().toggleObjectsDetails().getModifiedObjects().size());
    assertEquals(Arrays.asList("@@ -1,1 +1,1 @@", "-Alice says hello!", "+<ins>{{info}}</ins>Alice says hello!<ins>{{/info}}</ins>"), changesPane.getEntityDiff("XWiki.WikiMacroClass[0]").getDiff("Macro code"));
    // Finish the merge.
    mergeConflictPane.getVersionToKeepSelect().selectByValue("NEXT");
    // FIXME: We get the extension pane from the search results because it is reloaded when we compare the versions.
    extensionPane = searchResults.getExtension(0).confirm();
    assertEquals("installed", extensionPane.getStatus());
    assertNull(extensionPane.getProgressBar());
    upgradeLog = extensionPane.openProgressSection().getJobLog();
    lastLogItem = upgradeLog.get(upgradeLog.size() - 1);
    assertEquals("info", lastLogItem.getLevel());
    assertEquals("Finished job of type [install] with identifier " + "[extension/action/alice-xar-extension/wiki:xwiki]", lastLogItem.getMessage());
    // Check the merge result.
    ViewPage mergedPage = getUtil().gotoPage("ExtensionTest", "Alice");
    assertEquals("Alice Wiki Macro (upgraded)", mergedPage.getDocumentTitle());
}
Also used : ExtensionAdministrationPage(org.xwiki.extension.test.po.ExtensionAdministrationPage) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TestExtension(org.xwiki.repository.test.TestExtension) ExtensionId(org.xwiki.extension.ExtensionId) ViewPage(org.xwiki.test.ui.po.ViewPage) ExtensionPane(org.xwiki.extension.test.po.ExtensionPane) ProgressBarPane(org.xwiki.extension.test.po.ProgressBarPane) WebElement(org.openqa.selenium.WebElement) EntityDiff(org.xwiki.test.ui.po.diff.EntityDiff) LogItemPane(org.xwiki.extension.test.po.LogItemPane) MergeConflictPane(org.xwiki.extension.test.po.MergeConflictPane) ExtensionProgressPane(org.xwiki.extension.test.po.ExtensionProgressPane) SearchResultsPane(org.xwiki.extension.test.po.SearchResultsPane) ChangesPane(org.xwiki.test.ui.po.ChangesPane) Test(org.junit.Test)

Example 2 with ChangesPane

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

the class CompareVersionsTest method testAllChanges.

/**
 * Tests that all changes are displayed.
 */
@Test
public void testAllChanges() {
    HistoryPane historyTab = testPage.openHistoryDocExtraPane().showMinorEdits();
    String currentVersion = historyTab.getCurrentVersion();
    // TODO: If the document has many versions, like in this case, the versions are paginated and currently there's
    // no way to compare two versions from two different pagination pages using the UI. Thus we have to build the
    // URL and load the compare page manually. Update the code when we remove this UI limitation.
    // ChangesPane changesPane = historyTab.compare("1.1", currentVersion).getChangesPane();
    String queryString = String.format("viewer=changes&rev1=1.1&rev2=%s", currentVersion);
    getUtil().gotoPage(getTestClassName(), testPage.getMetaDataValue("page"), "view", queryString);
    ChangesPane changesPane = new ChangesPane();
    // Version summary.
    String today = new SimpleDateFormat("yyyy/MM/dd").format(new Date());
    assertTrue(changesPane.getFromVersionSummary().startsWith("From version 1.1\nedited by Administrator\non " + today));
    assertTrue(changesPane.getToVersionSummary().startsWith("To version " + currentVersion + "\nedited by Alice\non " + today));
    assertEquals("Change comment: Deleted object", changesPane.getChangeComment());
    // Diff summary.
    DocumentDiffSummary diffSummary = changesPane.getDiffSummary();
    assertThat(Arrays.asList("Page properties", "Attachments", "Objects", "Class properties"), containsInAnyOrder(diffSummary.getItems().toArray()));
    assertEquals("(5 modified, 0 added, 0 removed)", diffSummary.getPagePropertiesSummary());
    assertEquals("(0 modified, 1 added, 0 removed)", diffSummary.getAttachmentsSummary());
    assertEquals("(0 modified, 2 added, 0 removed)", diffSummary.getObjectsSummary());
    assertEquals("(0 modified, 1 added, 0 removed)", diffSummary.getClassPropertiesSummary());
    assertEquals(Arrays.asList("SmallAttachment.txt"), diffSummary.toggleAttachmentsDetails().getAddedAttachments());
    assertEquals(Arrays.asList("XWiki.JavaScriptExtension[0]", "XWiki.XWikiComments[0]"), diffSummary.toggleObjectsDetails().getAddedObjects());
    assertEquals(Arrays.asList("age"), diffSummary.toggleClassPropertiesDetails().getAddedClassProperties());
    // Diff details.
    assertThat(Arrays.asList("Page properties", "SmallAttachment.txt", "XWiki.JavaScriptExtension[0]", "XWiki.XWikiComments[0]", "age"), containsInAnyOrder(changesPane.getChangedEntities().toArray()));
    // Page properties changes.
    EntityDiff pageProperties = changesPane.getEntityDiff("Page properties");
    assertThat(Arrays.asList("Title", "Parent", "Author", "Tags", "Content"), containsInAnyOrder(pageProperties.getPropertyNames().toArray()));
    assertDiff(pageProperties.getDiff("Title"), "-<del>T</del>est", "+<ins>Compar</ins>e<ins> ver</ins>s<ins>ions </ins>t<ins>est</ins>");
    assertDiff(pageProperties.getDiff("Parent"), "+Sandbox.WebHome");
    assertDiff(pageProperties.getDiff("Author"), "-XWiki.A<del>dm</del>i<del>n</del>", "+XWiki.A<ins>l</ins>i<ins>ce</ins>");
    assertDiff(pageProperties.getDiff("Tags"), "+bar");
    assertDiff(pageProperties.getDiff("Content"), "@@ -1,3 +1,3 @@", " one", "-two", "-<del>th</del>r<del>ee</del>", "+<ins>**</ins>two<ins>**</ins>", "+<ins>fou</ins>r");
    // Attachment changes.
    EntityDiff attachmentDiff = changesPane.getEntityDiff("SmallAttachment.txt");
    assertThat(Arrays.asList("Author", "Size", "Content"), containsInAnyOrder(attachmentDiff.getPropertyNames().toArray()));
    assertDiff(attachmentDiff.getDiff("Author"), "+XWiki.Admin");
    assertDiff(attachmentDiff.getDiff("Size"), "+27 bytes");
    assertDiff(attachmentDiff.getDiff("Content"), "+This is a small attachment.");
    // Object changes.
    EntityDiff jsxDiff = changesPane.getEntityDiff("XWiki.JavaScriptExtension[0]");
    assertThat(Arrays.asList("Caching policy", "Name", "Use this extension", "Code"), containsInAnyOrder(jsxDiff.getPropertyNames().toArray()));
    assertDiff(jsxDiff.getDiff("Caching policy"), "+long");
    assertDiff(jsxDiff.getDiff("Name"), "+Code snippet");
    assertDiff(jsxDiff.getDiff("Use this extension"), "+onDemand");
    assertDiff(jsxDiff.getDiff("Code"), "+var tmp = alice;", "+alice = 2 * bob;", "+bob = tmp;");
    // Comment changes.
    EntityDiff commentDiff = changesPane.getEntityDiff("XWiki.XWikiComments[0]");
    assertThat(Arrays.asList("Author", "Date", "Comment"), containsInAnyOrder(commentDiff.getPropertyNames().toArray()));
    assertDiff(commentDiff.getDiff("Author"), "+XWiki.Alice");
    assertEquals(2, commentDiff.getDiff("Date").size());
    assertDiff(commentDiff.getDiff("Comment"), "+first line", "+line in between", "+second line");
    // Class property changes.
    EntityDiff ageDiff = changesPane.getEntityDiff("age");
    assertThat(Arrays.asList("Name", "Number", "Pretty Name", "Size", "Number Type"), containsInAnyOrder(ageDiff.getPropertyNames().toArray()));
    assertDiff(ageDiff.getDiff("Name"), "+age");
    assertDiff(ageDiff.getDiff("Number"), "+1");
    assertDiff(ageDiff.getDiff("Pretty Name"), "+age");
    assertDiff(ageDiff.getDiff("Size"), "+30");
    assertDiff(ageDiff.getDiff("Number Type"), "+integer");
}
Also used : DocumentDiffSummary(org.xwiki.test.ui.po.diff.DocumentDiffSummary) SimpleDateFormat(java.text.SimpleDateFormat) EntityDiff(org.xwiki.test.ui.po.diff.EntityDiff) HistoryPane(org.xwiki.test.ui.po.HistoryPane) ChangesPane(org.xwiki.test.ui.po.ChangesPane) Date(java.util.Date) Test(org.junit.Test)

Example 3 with ChangesPane

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

the class CompareVersionsTest method testUnifiedDiffShowsInlineChanges.

/**
 * Tests that the unified diff (for multi-line text) shows the inline changes.
 */
@Test
public void testUnifiedDiffShowsInlineChanges() {
    ChangesPane changesPane = testPage.openHistoryDocExtraPane().showMinorEdits().compare("2.2", "2.3").getChangesPane();
    EntityDiff jsxDiff = changesPane.getEntityDiff("XWiki.JavaScriptExtension[0]");
    assertDiff(jsxDiff.getDiff("Code"), "@@ -1,3 +1,3 @@", " var tmp = alice;", "-alice = bob;", "+alice = <ins>2 * </ins>bob;", " bob = tmp;");
}
Also used : EntityDiff(org.xwiki.test.ui.po.diff.EntityDiff) ChangesPane(org.xwiki.test.ui.po.ChangesPane) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 ChangesPane (org.xwiki.test.ui.po.ChangesPane)3 EntityDiff (org.xwiki.test.ui.po.diff.EntityDiff)3 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 WebElement (org.openqa.selenium.WebElement)1 ExtensionId (org.xwiki.extension.ExtensionId)1 ExtensionAdministrationPage (org.xwiki.extension.test.po.ExtensionAdministrationPage)1 ExtensionPane (org.xwiki.extension.test.po.ExtensionPane)1 ExtensionProgressPane (org.xwiki.extension.test.po.ExtensionProgressPane)1 LogItemPane (org.xwiki.extension.test.po.LogItemPane)1 MergeConflictPane (org.xwiki.extension.test.po.MergeConflictPane)1 ProgressBarPane (org.xwiki.extension.test.po.ProgressBarPane)1 SearchResultsPane (org.xwiki.extension.test.po.SearchResultsPane)1 TestExtension (org.xwiki.repository.test.TestExtension)1 HistoryPane (org.xwiki.test.ui.po.HistoryPane)1 ViewPage (org.xwiki.test.ui.po.ViewPage)1 DocumentDiffSummary (org.xwiki.test.ui.po.diff.DocumentDiffSummary)1