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().clickAddExtensionsSection();
SearchResultsPane searchResults =
adminPage.getSearchBar().clickAdvancedSearch().search(extensionId, newVersion);
ExtensionPane extensionPane = searchResults.getExtension(0);
extensionPane = extensionPane.upgrade().confirm();
// Check the merge conflict UI.
Assert.assertEquals("loading", extensionPane.getStatus());
Assert.assertNull(extensionPane.getStatusMessage());
ProgressBarPane progressBar = extensionPane.getProgressBar();
Assert.assertEquals(83, progressBar.getPercent());
Assert.assertEquals("Conflict between [@@ -1,1 +1,1 @@] and [@@ -1,1 +1,1 @@]", progressBar.getMessage());
ExtensionProgressPane progressPane = extensionPane.openProgressSection();
WebElement jobLogLabel = progressPane.getJobLogLabel();
Assert.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);
Assert.assertEquals("loading", lastLogItem.getLevel());
Assert.assertEquals(progressBar.getMessage(), lastLogItem.getMessage());
MergeConflictPane mergeConflictPane = progressPane.getMergeConflict();
ChangesPane changesPane = mergeConflictPane.getChanges();
Assert.assertFalse(changesPane.getContentChanges().isEmpty());
Assert.assertEquals("@@ -1,1 +1,1 @@\n-<del>Test</del> macro.\n+<ins>A</ins> <ins>cool </ins>macro.",
changesPane.getObjectChanges("XWiki.WikiMacroClass", 0, "Macro description"));
mergeConflictPane.getFromVersionSelect().selectByVisibleText("Previous version");
mergeConflictPane.getToVersionSelect().selectByVisibleText("Current version");
mergeConflictPane = mergeConflictPane.clickShowChanges();
changesPane = mergeConflictPane.getChanges();
StringBuilder expectedDiff = new StringBuilder();
expectedDiff.append("@@ -1,9 +1,9 @@\n");
expectedDiff.append("-= Usage =\n");
expectedDiff.append("+=<ins>=</ins> Usage =<ins>=</ins>\n");
expectedDiff.append(" \n");
expectedDiff.append("-{{code}}\n");
expectedDiff.append("+{{code<ins> language=\"none\"</ins>}}\n");
expectedDiff.append(" {{alice/}}\n");
expectedDiff.append(" {{/code}}\n");
expectedDiff.append(" \n");
expectedDiff.append("-= <del>Res</del>u<del>l</del>t =\n");
expectedDiff.append("+=<ins>=</ins> <ins>O</ins>ut<ins>put</ins> =<ins>=</ins>\n");
expectedDiff.append(" \n");
expectedDiff.append(" {{alice/}}");
Assert.assertEquals(expectedDiff.toString(), changesPane.getContentChanges());
Assert.assertEquals(1, changesPane.getObjectChangeSummaries().size());
Assert.assertEquals(
"@@ -1,1 +1,1 @@\n-Alice says hello!\n+<ins>{{info}}</ins>Alice says hello!<ins>{{/info}}</ins>",
changesPane.getObjectChanges("XWiki.WikiMacroClass", 0, "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();
Assert.assertEquals("installed", extensionPane.getStatus());
Assert.assertNull(extensionPane.getProgressBar());
upgradeLog = extensionPane.openProgressSection().getJobLog();
lastLogItem = upgradeLog.get(upgradeLog.size() - 1);