1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.ui; |
21 |
|
|
22 |
|
import java.text.SimpleDateFormat; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.Date; |
25 |
|
import java.util.HashMap; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Map; |
28 |
|
|
29 |
|
import org.junit.AfterClass; |
30 |
|
import org.junit.Before; |
31 |
|
import org.junit.Rule; |
32 |
|
import org.junit.Test; |
33 |
|
import org.xwiki.tag.test.po.AddTagsPane; |
34 |
|
import org.xwiki.tag.test.po.TaggablePage; |
35 |
|
import org.xwiki.test.ui.po.AttachmentsPane; |
36 |
|
import org.xwiki.test.ui.po.ChangesPane; |
37 |
|
import org.xwiki.test.ui.po.CommentsTab; |
38 |
|
import org.xwiki.test.ui.po.FormElement; |
39 |
|
import org.xwiki.test.ui.po.HistoryPane; |
40 |
|
import org.xwiki.test.ui.po.ViewPage; |
41 |
|
import org.xwiki.test.ui.po.diff.DocumentDiffSummary; |
42 |
|
import org.xwiki.test.ui.po.diff.EntityDiff; |
43 |
|
import org.xwiki.test.ui.po.editor.ClassEditPage; |
44 |
|
import org.xwiki.test.ui.po.editor.ObjectEditPage; |
45 |
|
import org.xwiki.test.ui.po.editor.WikiEditPage; |
46 |
|
|
47 |
|
import static org.junit.Assert.assertEquals; |
48 |
|
import static org.junit.Assert.assertTrue; |
49 |
|
import static org.junit.Assert.assertThat; |
50 |
|
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@version |
56 |
|
@since |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (125) |
Complexity: 9 |
Complexity Density: 0.08 |
|
58 |
|
public class CompareVersionsTest extends AbstractTest |
59 |
|
{ |
60 |
|
@Rule |
61 |
|
public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil()); |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
private ViewPage testPage; |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (57) |
Complexity: 2 |
Complexity Density: 0.04 |
|
68 |
3 |
@Before... |
69 |
|
public void setUp() throws Exception |
70 |
|
{ |
71 |
3 |
String pageName = "PageWithManyVersions"; |
72 |
|
|
73 |
|
|
74 |
3 |
testPage = getUtil().gotoPage(getTestClassName(), pageName); |
75 |
3 |
if (testPage.exists()) { |
76 |
|
|
77 |
|
|
78 |
2 |
testPage.waitForDocExtraPaneActive("comments"); |
79 |
|
|
80 |
|
|
81 |
2 |
return; |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
1 |
getUtil().setHierarchyMode("parentchild"); |
89 |
1 |
getDriver().navigate().refresh(); |
90 |
|
|
91 |
|
|
92 |
1 |
testPage = getUtil().createPage(getTestClassName(), pageName, "one\ntwo\nthree", "Test"); |
93 |
|
|
94 |
|
|
95 |
1 |
WikiEditPage wikiEditPage = testPage.editWiki(); |
96 |
1 |
wikiEditPage.setContent("one\n**two**\nfour"); |
97 |
1 |
wikiEditPage.setTitle("Compare verSions test"); |
98 |
1 |
wikiEditPage.setParent("Sandbox.WebHome"); |
99 |
1 |
wikiEditPage.setEditComment("Changed content and meta data."); |
100 |
1 |
wikiEditPage.clickSaveAndContinue(); |
101 |
1 |
wikiEditPage.setTitle("Compare versions test"); |
102 |
1 |
wikiEditPage.setMinorEdit(true); |
103 |
1 |
wikiEditPage.setEditComment("Fix typo in title."); |
104 |
1 |
wikiEditPage.clickSaveAndContinue(); |
105 |
|
|
106 |
|
|
107 |
1 |
ObjectEditPage objectEditPage = wikiEditPage.editObjects(); |
108 |
1 |
FormElement form = objectEditPage.addObject("XWiki.JavaScriptExtension"); |
109 |
1 |
Map<String, String> assignment = new HashMap<String, String>(); |
110 |
1 |
assignment.put("XWiki.JavaScriptExtension_0_name", "JavaScript code"); |
111 |
1 |
assignment.put("XWiki.JavaScriptExtension_0_code", "var tmp = alice;\nalice = bob;\nbob = tmp;"); |
112 |
1 |
assignment.put("XWiki.JavaScriptExtension_0_use", "onDemand"); |
113 |
1 |
form.fillFieldsByName(assignment); |
114 |
1 |
objectEditPage.clickSaveAndContinue(); |
115 |
1 |
assignment.put("XWiki.JavaScriptExtension_0_name", "Code snippet"); |
116 |
1 |
assignment.put("XWiki.JavaScriptExtension_0_code", "var tmp = alice;\nalice = 2 * bob;\nbob = tmp;"); |
117 |
1 |
form.fillFieldsByName(assignment); |
118 |
1 |
objectEditPage.clickSaveAndContinue(); |
119 |
|
|
120 |
|
|
121 |
1 |
ClassEditPage classEditPage = objectEditPage.editClass(); |
122 |
1 |
classEditPage.addProperty("age", "Number"); |
123 |
1 |
classEditPage.addProperty("color", "String"); |
124 |
1 |
classEditPage.getNumberClassEditElement("age").setNumberType("integer"); |
125 |
1 |
classEditPage.clickSaveAndContinue(); |
126 |
1 |
classEditPage.deleteProperty("color"); |
127 |
1 |
testPage = classEditPage.clickSaveAndView(); |
128 |
|
|
129 |
|
|
130 |
1 |
TaggablePage taggablePage = new TaggablePage(); |
131 |
1 |
AddTagsPane addTagsPane = taggablePage.addTags(); |
132 |
1 |
addTagsPane.setTags("foo,bar"); |
133 |
1 |
addTagsPane.add(); |
134 |
1 |
taggablePage.removeTag("foo"); |
135 |
|
|
136 |
|
|
137 |
1 |
AttachmentsPane attachmentsPane = testPage.openAttachmentsDocExtraPane(); |
138 |
|
|
139 |
1 |
for (String fileName : new String[] {"SmallAttachment.txt", "SmallAttachment2.txt", "SmallAttachment.txt"}) { |
140 |
3 |
attachmentsPane.setFileToUpload(this.getClass().getResource('/' + fileName).getPath()); |
141 |
3 |
attachmentsPane.waitForUploadToFinish(fileName); |
142 |
3 |
attachmentsPane.clickHideProgress(); |
143 |
|
} |
144 |
1 |
attachmentsPane.deleteAttachmentByFileByName("SmallAttachment2.txt"); |
145 |
|
|
146 |
|
|
147 |
1 |
getUtil().createUserAndLogin("Alice", "ecila"); |
148 |
1 |
testPage = getUtil().gotoPage(getTestClassName(), pageName); |
149 |
1 |
CommentsTab commentsTab = testPage.openCommentsDocExtraPane(); |
150 |
1 |
commentsTab.postComment("first line\nsecond line", true); |
151 |
1 |
commentsTab.editCommentByID(0, "first line\nline in between\nsecond line"); |
152 |
1 |
commentsTab.replyToCommentByID(0, "this is a reply"); |
153 |
1 |
commentsTab.deleteCommentByID(1); |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
156 |
1 |
@AfterClass... |
157 |
|
public static void tearDownClass() throws Exception |
158 |
|
{ |
159 |
|
|
160 |
1 |
getUtil().setHierarchyMode("reference"); |
161 |
1 |
getDriver().navigate().refresh(); |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (49) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
167 |
1 |
@Test... |
168 |
|
public void testAllChanges() |
169 |
|
{ |
170 |
1 |
HistoryPane historyTab = testPage.openHistoryDocExtraPane().showMinorEdits(); |
171 |
1 |
String currentVersion = historyTab.getCurrentVersion(); |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
1 |
String queryString = String.format("viewer=changes&rev1=1.1&rev2=%s", currentVersion); |
178 |
1 |
getUtil().gotoPage(getTestClassName(), testPage.getMetaDataValue("page"), "view", queryString); |
179 |
1 |
ChangesPane changesPane = new ChangesPane(); |
180 |
|
|
181 |
|
|
182 |
1 |
String today = new SimpleDateFormat("yyyy/MM/dd").format(new Date()); |
183 |
1 |
assertTrue(changesPane.getFromVersionSummary().startsWith( |
184 |
|
"From version 1.1\nedited by Administrator\non " + today)); |
185 |
1 |
assertTrue(changesPane.getToVersionSummary().startsWith( |
186 |
|
"To version " + currentVersion + "\nedited by Alice\non " + today)); |
187 |
1 |
assertEquals("Change comment: Deleted object", changesPane.getChangeComment()); |
188 |
|
|
189 |
|
|
190 |
1 |
DocumentDiffSummary diffSummary = changesPane.getDiffSummary(); |
191 |
1 |
assertThat(Arrays.asList("Page properties", "Attachments", "Objects", "Class properties"), |
192 |
|
containsInAnyOrder(diffSummary.getItems().toArray())); |
193 |
1 |
assertEquals("(5 modified, 0 added, 0 removed)", diffSummary.getPagePropertiesSummary()); |
194 |
1 |
assertEquals("(0 modified, 1 added, 0 removed)", diffSummary.getAttachmentsSummary()); |
195 |
1 |
assertEquals("(0 modified, 2 added, 0 removed)", diffSummary.getObjectsSummary()); |
196 |
1 |
assertEquals("(0 modified, 1 added, 0 removed)", diffSummary.getClassPropertiesSummary()); |
197 |
1 |
assertEquals(Arrays.asList("SmallAttachment.txt"), diffSummary.toggleAttachmentsDetails().getAddedAttachments()); |
198 |
1 |
assertEquals(Arrays.asList("XWiki.JavaScriptExtension[0]", "XWiki.XWikiComments[0]"), diffSummary |
199 |
|
.toggleObjectsDetails().getAddedObjects()); |
200 |
1 |
assertEquals(Arrays.asList("age"), diffSummary.toggleClassPropertiesDetails().getAddedClassProperties()); |
201 |
|
|
202 |
|
|
203 |
1 |
assertThat(Arrays.asList("Page properties", "SmallAttachment.txt", "XWiki.JavaScriptExtension[0]", |
204 |
|
"XWiki.XWikiComments[0]", "age"), containsInAnyOrder(changesPane.getChangedEntities().toArray())); |
205 |
|
|
206 |
|
|
207 |
1 |
EntityDiff pageProperties = changesPane.getEntityDiff("Page properties"); |
208 |
1 |
assertThat(Arrays.asList("Title", "Parent", "Author", "Tags", "Content"), |
209 |
|
containsInAnyOrder(pageProperties.getPropertyNames().toArray())); |
210 |
1 |
assertDiff(pageProperties.getDiff("Title"), "-<del>T</del>est", |
211 |
|
"+<ins>Compar</ins>e<ins> ver</ins>s<ins>ions </ins>t<ins>est</ins>"); |
212 |
1 |
assertDiff(pageProperties.getDiff("Parent"), "+Sandbox.WebHome"); |
213 |
1 |
assertDiff(pageProperties.getDiff("Author"), "-XWiki.A<del>dm</del>i<del>n</del>", |
214 |
|
"+XWiki.A<ins>l</ins>i<ins>ce</ins>"); |
215 |
1 |
assertDiff(pageProperties.getDiff("Tags"), "+bar"); |
216 |
1 |
assertDiff(pageProperties.getDiff("Content"), "@@ -1,3 +1,3 @@", " one", "-two", |
217 |
|
"-<del>th</del>r<del>ee</del>", "+<ins>**</ins>two<ins>**</ins>", "+<ins>fou</ins>r"); |
218 |
|
|
219 |
|
|
220 |
1 |
EntityDiff attachmentDiff = changesPane.getEntityDiff("SmallAttachment.txt"); |
221 |
1 |
assertThat(Arrays.asList("Author", "Size", "Content"), |
222 |
|
containsInAnyOrder(attachmentDiff.getPropertyNames().toArray())); |
223 |
1 |
assertDiff(attachmentDiff.getDiff("Author"), "+XWiki.Admin"); |
224 |
1 |
assertDiff(attachmentDiff.getDiff("Size"), "+27 bytes"); |
225 |
1 |
assertDiff(attachmentDiff.getDiff("Content"), "+This is a small attachment."); |
226 |
|
|
227 |
|
|
228 |
1 |
EntityDiff jsxDiff = changesPane.getEntityDiff("XWiki.JavaScriptExtension[0]"); |
229 |
1 |
assertThat(Arrays.asList("Caching policy", "Name", "Use this extension", "Code"), |
230 |
|
containsInAnyOrder(jsxDiff.getPropertyNames().toArray())); |
231 |
1 |
assertDiff(jsxDiff.getDiff("Caching policy"), "+long"); |
232 |
1 |
assertDiff(jsxDiff.getDiff("Name"), "+Code snippet"); |
233 |
1 |
assertDiff(jsxDiff.getDiff("Use this extension"), "+onDemand"); |
234 |
1 |
assertDiff(jsxDiff.getDiff("Code"), "+var tmp = alice;", "+alice = 2 * bob;", "+bob = tmp;"); |
235 |
|
|
236 |
|
|
237 |
1 |
EntityDiff commentDiff = changesPane.getEntityDiff("XWiki.XWikiComments[0]"); |
238 |
1 |
assertThat(Arrays.asList("Author", "Date", "Comment"), |
239 |
|
containsInAnyOrder(commentDiff.getPropertyNames().toArray())); |
240 |
1 |
assertDiff(commentDiff.getDiff("Author"), "+XWiki.Alice"); |
241 |
1 |
assertEquals(2, commentDiff.getDiff("Date").size()); |
242 |
1 |
assertDiff(commentDiff.getDiff("Comment"), "+first line", "+line in between", "+second line"); |
243 |
|
|
244 |
|
|
245 |
1 |
EntityDiff ageDiff = changesPane.getEntityDiff("age"); |
246 |
1 |
assertThat(Arrays.asList("Name", "Number", "Pretty Name", "Size", "Number Type"), |
247 |
|
containsInAnyOrder(ageDiff.getPropertyNames().toArray())); |
248 |
1 |
assertDiff(ageDiff.getDiff("Name"), "+age"); |
249 |
1 |
assertDiff(ageDiff.getDiff("Number"), "+1"); |
250 |
1 |
assertDiff(ageDiff.getDiff("Pretty Name"), "+age"); |
251 |
1 |
assertDiff(ageDiff.getDiff("Size"), "+30"); |
252 |
1 |
assertDiff(ageDiff.getDiff("Number Type"), "+integer"); |
253 |
|
} |
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
258 |
1 |
@Test... |
259 |
|
public void testNoChanges() |
260 |
|
{ |
261 |
1 |
HistoryPane historyTab = testPage.openHistoryDocExtraPane(); |
262 |
1 |
String currentVersion = historyTab.getCurrentVersion(); |
263 |
1 |
assertTrue(historyTab.compare(currentVersion, currentVersion).getChangesPane().hasNoChanges()); |
264 |
|
} |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
269 |
1 |
@Test... |
270 |
|
public void testUnifiedDiffShowsInlineChanges() |
271 |
|
{ |
272 |
1 |
ChangesPane changesPane = |
273 |
|
testPage.openHistoryDocExtraPane().showMinorEdits().compare("2.2", "2.3").getChangesPane(); |
274 |
1 |
EntityDiff jsxDiff = changesPane.getEntityDiff("XWiki.JavaScriptExtension[0]"); |
275 |
1 |
assertDiff(jsxDiff.getDiff("Code"), "@@ -1,3 +1,3 @@", " var tmp = alice;", "-alice = bob;", |
276 |
|
"+alice = <ins>2 * </ins>bob;", " bob = tmp;"); |
277 |
|
} |
278 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
279 |
20 |
private void assertDiff(List<String> actualLines, String... expectedLines)... |
280 |
|
{ |
281 |
20 |
if (expectedLines.length > 0 && !expectedLines[0].startsWith("@@")) { |
282 |
18 |
assertEquals(Arrays.asList(expectedLines), actualLines.subList(1, actualLines.size())); |
283 |
|
} else { |
284 |
2 |
assertEquals(Arrays.asList(expectedLines), actualLines); |
285 |
|
} |
286 |
|
} |
287 |
|
} |