use of org.xwiki.test.ui.po.diff.DocumentDiffSummary 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");
}
Aggregations