Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / uitest / writer_tests / trackedChanges.py
blob14aea9bcee0d198bf7a92ff6bdfd75084e0bfb7d
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # tests for tracked changes ; tdf912270
11 from uitest.framework import UITestCase
12 from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file, type_text, select_by_text
13 from libreoffice.uno.propertyvalue import mkPropertyValues
14 from tempfile import TemporaryDirectory
15 from org.libreoffice.unotest import systemPathToFileUrl
16 import os.path
18 class trackedchanges(UITestCase):
20 def test_tdf91270(self):
22 with self.ui_test.create_doc_in_start_center("writer"):
24 xWriterDoc = self.xUITest.getTopFocusWindow()
25 xWriterEdit = xWriterDoc.getChild("writer_edit")
26 type_text(xWriterEdit, "Test")
28 self.xUITest.executeCommand(".uno:TrackChanges")
30 self.xUITest.executeCommand(".uno:SelectAll") #select whole text
31 self.xUITest.executeCommand(".uno:Cut") #cut text
33 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close"):
34 pass
36 def test_tracked_changes_accept(self):
38 with self.ui_test.create_doc_in_start_center("writer") as document:
39 xWriterDoc = self.xUITest.getTopFocusWindow()
40 xWriterEdit = xWriterDoc.getChild("writer_edit")
42 self.xUITest.executeCommand(".uno:TrackChanges")
43 type_text(xWriterEdit, "Test LibreOffice")
44 self.xUITest.executeCommand(".uno:ShowTrackedChanges")
46 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
47 xAccBtn = xTrackDlg.getChild("accept")
48 xAccBtn.executeAction("CLICK", tuple())
50 self.assertEqual(document.Text.String[0:16], "Test LibreOffice")
52 def test_tracked_changes_acceptall(self):
54 with self.ui_test.create_doc_in_start_center("writer") as document:
55 xWriterDoc = self.xUITest.getTopFocusWindow()
56 xWriterEdit = xWriterDoc.getChild("writer_edit")
58 self.xUITest.executeCommand(".uno:TrackChanges")
59 type_text(xWriterEdit, "Test LibreOffice")
60 self.xUITest.executeCommand(".uno:ShowTrackedChanges")
62 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
64 xAccBtn = xTrackDlg.getChild("acceptall")
65 xAccBtn.executeAction("CLICK", tuple())
68 self.assertEqual(document.Text.String[0:16], "Test LibreOffice")
70 def test_tracked_changes_reject(self):
72 with self.ui_test.create_doc_in_start_center("writer") as document:
73 xWriterDoc = self.xUITest.getTopFocusWindow()
74 xWriterEdit = xWriterDoc.getChild("writer_edit")
76 self.xUITest.executeCommand(".uno:TrackChanges")
77 type_text(xWriterEdit, "Test LibreOffice")
78 self.xUITest.executeCommand(".uno:ShowTrackedChanges")
80 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
82 xRejBtn = xTrackDlg.getChild("reject")
83 xRejBtn.executeAction("CLICK", tuple())
85 self.assertEqual(document.Text.String[0:1], "")
87 def test_tracked_changes_rejectall(self):
89 with self.ui_test.create_doc_in_start_center("writer") as document:
90 xWriterDoc = self.xUITest.getTopFocusWindow()
91 xWriterEdit = xWriterDoc.getChild("writer_edit")
93 self.xUITest.executeCommand(".uno:TrackChanges")
94 type_text(xWriterEdit, "Test LibreOffice")
95 self.xUITest.executeCommand(".uno:ShowTrackedChanges")
97 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
99 xAccBtn = xTrackDlg.getChild("rejectall")
100 xAccBtn.executeAction("CLICK", tuple())
102 self.assertEqual(document.Text.String[0:1], "")
104 def test_tracked_changes_zprev_next(self):
106 with self.ui_test.create_doc_in_start_center("writer") as document:
107 xWriterDoc = self.xUITest.getTopFocusWindow()
108 xWriterEdit = xWriterDoc.getChild("writer_edit")
110 self.xUITest.executeCommand(".uno:TrackChanges")
111 type_text(xWriterEdit, "Test LibreOffice")
112 self.xUITest.executeCommand(".uno:TrackChanges")
113 type_text(xWriterEdit, " Test2")
114 self.xUITest.executeCommand(".uno:TrackChanges")
115 type_text(xWriterEdit, " Test3")
116 self.xUITest.executeCommand(".uno:TrackChanges")
117 type_text(xWriterEdit, " Test4")
118 self.xUITest.executeCommand(".uno:TrackChanges")
119 type_text(xWriterEdit, " Test5")
120 self.xUITest.executeCommand(".uno:PreviousTrackedChange")
121 self.xUITest.executeCommand(".uno:RejectTrackedChange")
122 self.assertEqual(document.Text.String[0:37], "Test LibreOffice Test2 Test3 Test4")
124 self.xUITest.executeCommand(".uno:PreviousTrackedChange")
125 self.xUITest.executeCommand(".uno:PreviousTrackedChange")
126 self.xUITest.executeCommand(".uno:AcceptTrackedChange")
127 self.assertEqual(document.Text.String[0:37], "Test LibreOffice Test2 Test3 Test4")
129 self.xUITest.executeCommand(".uno:NextTrackedChange")
130 self.xUITest.executeCommand(".uno:RejectTrackedChange")
131 self.assertEqual(document.Text.String[0:30], "Test LibreOffice Test2 Test4")
134 def test_list_of_changes(self):
135 with self.ui_test.load_file(get_url_for_data_file("trackedChanges.odt")) as document:
137 listText = [
138 "Unknown Author\t01/24/2020 16:19:32\t",
139 "Unknown Author\t01/24/2020 16:19:35\t",
140 "Unknown Author\t01/24/2020 16:19:39\t",
141 "Unknown Author\t01/24/2020 16:19:39\t",
142 "Xisco Fauli\t01/27/2020 17:42:55\t"]
144 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
145 changesList = xTrackDlg.getChild("writerchanges")
147 resultsAccept = [
148 "The tennis ball is a small ball. The baskedtball is much bigger.",
149 "The tennis ball is a small ball. The baskedtball is much bigger.",
150 "The tennis ball is a small ball. The baskedtball is much bigger.",
151 "The tennis ball is a small ball. The basketball is much bigger.",
152 "The tennis ball is a small ball. The basketball is much bigger.",
153 "The tennis ball is a small ball. The basketball is much bigger."]
155 for i in range(len(listText)):
156 self.assertEqual(document.Text.String.strip(), resultsAccept[i])
157 self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], listText[i] )
158 xAccBtn = xTrackDlg.getChild("accept")
159 xAccBtn.executeAction("CLICK", tuple())
161 self.assertEqual(document.Text.String.strip(), resultsAccept[5])
162 #List is empty
163 self.assertFalse('0' in changesList.getChildren())
165 for i in reversed(range(len(listText))):
166 xUndoBtn = xTrackDlg.getChild("undo")
167 xUndoBtn.executeAction("CLICK", tuple())
168 self.assertEqual(document.Text.String.strip(), resultsAccept[i])
169 self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], listText[i] )
171 resultsReject = [
172 "The tennis ball is a small ball. The baskedtball is much bigger.",
173 "The tenis ball is a small ball. The baskedtball is much bigger.",
174 "The tenis ball is a small bal. The baskedtball is much bigger.",
175 "The tenis ball is a small bal. The baskedtball is much bigger.",
176 "The tenis ball is a small bal. The baskedball is much bigger.",
177 "The tenis ball is a small bal. The baskedball is much biger."]
179 for i in range(len(listText)):
180 self.assertEqual(document.Text.String.strip(), resultsReject[i])
181 self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], listText[i] )
182 xAccBtn = xTrackDlg.getChild("reject")
183 xAccBtn.executeAction("CLICK", tuple())
185 self.assertEqual(document.Text.String.strip(), resultsReject[5])
186 #List is empty
187 self.assertFalse('0' in changesList.getChildren())
189 for i in reversed(range(len(listText))):
190 xUndoBtn = xTrackDlg.getChild("undo")
191 xUndoBtn.executeAction("CLICK", tuple())
192 self.assertEqual(document.Text.String.strip(), resultsReject[i])
193 self.assertEqual(get_state_as_dict(changesList.getChild('0'))["Text"], listText[i] )
196 def test_tdf135018(self):
197 with self.ui_test.load_file(get_url_for_data_file("tdf135018.odt")) as document:
199 self.assertEqual(5, document.CurrentController.PageCount)
201 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
202 changesList = xTrackDlg.getChild("writerchanges")
203 self.assertEqual(111, len(changesList.getChildren()))
205 # Without the fix in place, it would have crashed here
206 xAccBtn = xTrackDlg.getChild("acceptall")
207 xAccBtn.executeAction("CLICK", tuple())
209 self.assertEqual(0, len(changesList.getChildren()))
211 xUndoBtn = xTrackDlg.getChild("undo")
212 xUndoBtn.executeAction("CLICK", tuple())
214 self.assertEqual(111, len(changesList.getChildren()))
217 # Check the changes are shown after opening the Manage Tracked Changes dialog
218 self.assertGreater(document.CurrentController.PageCount, 5)
220 def test_tdf144270_tracked_table_rows(self):
221 with self.ui_test.load_file(get_url_for_data_file("TC-table-del-add.docx")) as document:
223 tables = document.getTextTables()
224 self.assertEqual(3, len(tables))
226 # Accept
227 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
228 changesList = xTrackDlg.getChild("writerchanges")
230 # This was 14 (every cell is a different change instead of counting rows or tables)
231 # Now: 4 changes (2 deleted/inserted rows and 2 deleted/inserted tables)
232 self.assertEqual(4, len(changesList.getChildren()))
234 # Without the fix in place, it would have crashed here
235 for i in (3, 2, 1, 0):
236 xAccBtn = xTrackDlg.getChild("accept")
237 xAccBtn.executeAction("CLICK", tuple())
238 self.assertEqual(i, len(changesList.getChildren()))
240 tables = document.getTextTables()
241 self.assertEqual(2, len(tables))
243 for i in range(1, 5):
244 xUndoBtn = xTrackDlg.getChild("undo")
245 xUndoBtn.executeAction("CLICK", tuple())
246 self.assertEqual(i, len(changesList.getChildren()))
248 tables = document.getTextTables()
249 self.assertEqual(3, len(tables))
251 # Accept All
252 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
253 changesList = xTrackDlg.getChild("writerchanges")
255 # This was 14 (every cell is a different change instead of counting rows or tables)
256 # Now: 4 changes (2 deleted/inserted rows and 2 deleted/inserted tables)
257 self.assertEqual(4, len(changesList.getChildren()))
259 xAccBtn = xTrackDlg.getChild("acceptall")
260 xAccBtn.executeAction("CLICK", tuple())
261 self.assertEqual(0, len(changesList.getChildren()))
263 tables = document.getTextTables()
264 self.assertEqual(2, len(tables))
266 xUndoBtn = xTrackDlg.getChild("undo")
267 xUndoBtn.executeAction("CLICK", tuple())
268 self.assertEqual(4, len(changesList.getChildren()))
270 tables = document.getTextTables()
271 self.assertEqual(3, len(tables))
273 # goto to the start of the document to reject from the first tracked table row change
274 self.xUITest.executeCommand(".uno:GoToStartOfDoc")
276 # Reject
277 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
278 changesList = xTrackDlg.getChild("writerchanges")
280 # This was 14 (every cell is a different change instead of counting rows or tables)
281 # Now: 4 changes (2 deleted/inserted rows and 2 deleted/inserted tables)
282 self.assertEqual(4, len(changesList.getChildren()))
284 # jump to the parent to allow rejecting the table change
285 changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "LEFT"}))
287 # Without the fix in place, it would have crashed here
288 for i in (3, 2, 1, 0):
289 xAccBtn = xTrackDlg.getChild("reject")
290 xAccBtn.executeAction("CLICK", tuple())
291 self.assertEqual(i, len(changesList.getChildren()))
293 tables = document.getTextTables()
294 self.assertEqual(2, len(tables))
296 for i in range(1, 5):
297 xUndoBtn = xTrackDlg.getChild("undo")
298 xUndoBtn.executeAction("CLICK", tuple())
299 self.assertEqual(i, len(changesList.getChildren()))
301 tables = document.getTextTables()
302 self.assertEqual(3, len(tables))
304 # Reject All
305 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
306 changesList = xTrackDlg.getChild("writerchanges")
308 # This was 14 (every cell is a different change instead of counting rows or tables)
309 # Now: 4 changes (2 deleted/inserted rows and 2 deleted/inserted tables)
310 self.assertEqual(4, len(changesList.getChildren()))
312 xAccBtn = xTrackDlg.getChild("rejectall")
313 xAccBtn.executeAction("CLICK", tuple())
314 self.assertEqual(0, len(changesList.getChildren()))
316 tables = document.getTextTables()
317 self.assertEqual(2, len(tables))
319 xUndoBtn = xTrackDlg.getChild("undo")
320 xUndoBtn.executeAction("CLICK", tuple())
321 self.assertEqual(4, len(changesList.getChildren()))
323 tables = document.getTextTables()
324 self.assertEqual(3, len(tables))
326 def test_tdf148032(self):
328 with self.ui_test.load_file(get_url_for_data_file("trackedChanges.odt")):
330 # adding new Comment
331 self.xUITest.executeCommand(".uno:InsertAnnotation")
333 # wait until the comment is available
334 xComment1 = self.ui_test.wait_until_child_is_available('Comment1')
336 xEditView1 = xComment1.getChild("editview")
337 xEditView1.executeAction("TYPE", mkPropertyValues({"TEXT": "This is the First Comment"}))
338 self.assertEqual(get_state_as_dict(xComment1)["Text"], "This is the First Comment" )
339 self.assertEqual(get_state_as_dict(xComment1)["Resolved"], "false" )
340 self.assertEqual(get_state_as_dict(xComment1)["Author"], "Unknown Author" )
341 self.assertEqual(get_state_as_dict(xComment1)["ReadOnly"], "false" )
343 xComment1.executeAction("LEAVE", mkPropertyValues({}))
345 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
346 changesList = xTrackDlg.getChild("writerchanges")
347 self.assertEqual(6, len(changesList.getChildren()))
349 xChild = changesList.getChild(0)
350 # This was False (missing comment)
351 self.assertEqual(True, get_state_as_dict(xChild)["Text"].endswith('\tComment added'))
354 def get_annotation_count(self, document):
355 n = 0
356 textfields = document.getTextFields()
357 for textfield in textfields:
358 if textfield.supportsService("com.sun.star.text.TextField.Annotation"):
359 n = n + 1
360 return n
362 def test_tdf153016_annotation_in_DOC(self):
363 # load a test document, and add a tracked comment
364 with TemporaryDirectory() as tempdir:
365 xFilePath = os.path.join(tempdir, 'temp_drop_down_form_field.doc')
367 with self.ui_test.load_file(get_url_for_data_file('drop_down_form_field.doc')) as document:
369 self.xUITest.executeCommand(".uno:TrackChanges")
370 self.xUITest.executeCommand('.uno:SelectAll')
372 self.assertEqual(0, self.get_annotation_count(document))
374 self.xUITest.executeCommand('.uno:InsertAnnotation')
376 self.assertEqual(1, self.get_annotation_count(document))
378 # Save Copy as
379 with self.ui_test.execute_dialog_through_command('.uno:SaveAs', close_button="") as xDialog:
380 xFileName = xDialog.getChild('file_name')
381 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'CTRL+A'}))
382 xFileName.executeAction('TYPE', mkPropertyValues({'KEYCODE':'BACKSPACE'}))
383 xFileName.executeAction('TYPE', mkPropertyValues({'TEXT': xFilePath}))
385 xOpen = xDialog.getChild("open")
386 # DOC confirmation dialog is displayed
387 with self.ui_test.execute_dialog_through_action(xOpen, "CLICK", close_button="save"):
388 pass
390 with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as document:
391 # This was 2
392 self.assertEqual(1, self.get_annotation_count(document))
395 def test_tdf147179(self):
396 with self.ui_test.load_file(get_url_for_data_file("TC-table-del-add.docx")) as document:
397 xWriterDoc = self.xUITest.getTopFocusWindow()
398 xWriterEdit = xWriterDoc.getChild("writer_edit")
400 tables = document.getTextTables()
401 self.assertEqual(3, len(tables))
403 # Select text of the tracked row, not only text of its first cell
404 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
405 changesList = xTrackDlg.getChild("writerchanges")
407 # select second tracked table row in tree list
408 changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
409 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
410 while get_state_as_dict(xWriterEdit)["SelectedText"] != 'klj':
411 xToolkit.processEventsToIdle()
413 # this was "j" (only text of the first cell was selected, not text of the row)
414 self.assertEqual(get_state_as_dict(xWriterEdit)["SelectedText"], "klj" )
416 # select first tracked table row in tree list
417 changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "UP"}))
418 while get_state_as_dict(xWriterEdit)["SelectedText"] != 'bca':
419 xToolkit.processEventsToIdle()
421 # this was "a" (only text of the first cell was selected, not text of the row)
422 self.assertEqual(get_state_as_dict(xWriterEdit)["SelectedText"], "bca" )
424 def test_RedlineSuccessorData(self):
425 with TemporaryDirectory() as tempdir:
426 xFilePath = os.path.join(tempdir, "redlinesuccessordata-temp.odt")
427 with self.ui_test.load_file(get_url_for_data_file("redlinesuccessordata.docx")) as document:
429 # check tracked deletion in tracked insertion
430 with self.ui_test.execute_modeless_dialog_through_command('.uno:AcceptTrackedChanges', close_button="close") as xTrackDlg:
431 changesList = xTrackDlg.getChild('writerchanges')
432 # four children, but only three visible
433 state = get_state_as_dict(changesList)
434 self.assertEqual(state['Children'], '4')
435 self.assertEqual(state['VisibleCount'], '3')
437 # select tracked deletion with RedlineSuccessorData in tree list
438 changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
439 state = get_state_as_dict(changesList)
440 self.assertEqual(state['SelectEntryText'], 'Kelemen Gábor 2\t05/19/2021 12:35:00\t')
441 self.assertEqual(get_state_as_dict(changesList.getChild(1))['Children'], '1')
442 self.assertEqual(get_state_as_dict(changesList.getChild(1))['VisibleChildCount'], '0')
444 # open tree node with the tracked insertion: four visible children
445 changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RIGHT"}))
446 state = get_state_as_dict(changesList)
447 self.assertEqual(state['Children'], '4')
448 self.assertEqual(state['VisibleCount'], '4')
449 self.assertEqual(get_state_as_dict(changesList.getChild(1))['Children'], '1')
450 self.assertEqual(get_state_as_dict(changesList.getChild(1))['VisibleChildCount'], '1')
452 # select tracked insertion in tree list
453 changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
454 state = get_state_as_dict(changesList)
455 self.assertEqual(state['SelectEntryText'], 'First Person\t10/21/2012 23:45:00\t')
457 # Save the DOCX document as ODT with a tracked deletion in a tracked insertion
458 with self.ui_test.execute_dialog_through_command(".uno:SaveAs", close_button="open") as xSaveDialog:
459 xFileName = xSaveDialog.getChild("file_name")
460 xFileName.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
461 xFileName.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
462 xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": xFilePath}))
463 xFileTypeCombo = xSaveDialog.getChild("file_type")
464 select_by_text(xFileTypeCombo, "ODF Text Document (.odt)")
466 # load the temporary file, and check ODF roundtrip of the tracked deletion in a tracked insertion
467 with self.ui_test.load_file(systemPathToFileUrl(xFilePath)) as document:
468 # check tracked deletion in tracked insertion
469 with self.ui_test.execute_modeless_dialog_through_command('.uno:AcceptTrackedChanges', close_button="close") as xTrackDlg:
470 changesList = xTrackDlg.getChild('writerchanges')
471 # four children, but only three visible
472 state = get_state_as_dict(changesList)
473 self.assertEqual(state['Children'], '4')
474 self.assertEqual(state['VisibleCount'], '3')
476 # select tracked deletion with RedlineSuccessorData in tree list
477 changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
478 state = get_state_as_dict(changesList)
479 self.assertEqual(state['SelectEntryText'], 'Kelemen Gábor 2\t05/19/2021 12:35:00\t')
480 self.assertEqual(get_state_as_dict(changesList.getChild(1))['Children'], '1')
481 self.assertEqual(get_state_as_dict(changesList.getChild(1))['VisibleChildCount'], '0')
483 # open tree node with the tracked insertion: four visible children
484 changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RIGHT"}))
485 state = get_state_as_dict(changesList)
486 self.assertEqual(state['Children'], '4')
487 self.assertEqual(state['VisibleCount'], '4')
488 self.assertEqual(get_state_as_dict(changesList.getChild(1))['Children'], '1')
489 self.assertEqual(get_state_as_dict(changesList.getChild(1))['VisibleChildCount'], '1')
491 # select tracked insertion in tree list
492 changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
493 state = get_state_as_dict(changesList)
494 self.assertEqual(state['SelectEntryText'], 'First Person\t10/21/2012 23:45:00\t')
496 # reject all
497 xAccBtn = xTrackDlg.getChild("rejectall")
498 xAccBtn.executeAction("CLICK", tuple())
499 # FIXME why we need double rejectall (dialog-only)?
500 xAccBtn.executeAction("CLICK", tuple())
501 self.assertEqual(0, len(changesList.getChildren()))
502 # This was false, because of not rejected tracked deletion
503 # of the text "inserts": "Document text inserts document"...
504 self.assertTrue(document.getText().getString().startswith('Document text document text'))
506 def test_tdf155342_tracked_table_colums(self):
507 with self.ui_test.load_file(get_url_for_data_file("TC-table-del-add.docx")) as document:
509 # accept all changes and insert new columns with change tracking
510 self.xUITest.executeCommand(".uno:AcceptAllTrackedChanges")
511 tables = document.getTextTables()
512 self.assertEqual(2, len(tables))
513 self.assertEqual(len(tables[0].getColumns()), 3)
514 self.xUITest.executeCommand(".uno:InsertColumnsAfter")
515 self.xUITest.executeCommand(".uno:InsertColumnsAfter")
516 self.assertEqual(len(tables[0].getColumns()), 5)
518 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
519 xToolkit.processEventsToIdle()
521 # check and reject changes
522 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
523 changesList = xTrackDlg.getChild("writerchanges")
525 # six changes, but only one visible in the Manage Changes dialog window
526 state = get_state_as_dict(changesList)
527 self.assertEqual(state['Children'], '6')
528 self.assertEqual(state['VisibleCount'], '1')
530 # This was 6 (every cell is a different change instead of counting column changes)
531 # Now: 1 changes (2 inserted columns)
532 self.assertEqual(1, len(changesList.getChildren()))
534 # reject column insertion
536 xAccBtn = xTrackDlg.getChild("reject")
537 xAccBtn.executeAction("CLICK", tuple())
539 # all inserted columns are removed
541 self.assertEqual(len(tables[0].getColumns()), 3)
543 # no changes in the dialog window
545 self.assertEqual(0, len(changesList.getChildren()))
547 def test_tdf155847_multiple_tracked_columns(self):
548 with self.ui_test.load_file(get_url_for_data_file("TC-table-del-add.docx")) as document:
550 # accept all changes and insert new columns with change tracking
551 self.xUITest.executeCommand(".uno:AcceptAllTrackedChanges")
552 tables = document.getTextTables()
553 self.assertEqual(2, len(tables))
554 self.assertEqual(len(tables[0].getColumns()), 3)
555 self.xUITest.executeCommand(".uno:InsertColumnsAfter")
556 self.xUITest.executeCommand(".uno:DeleteColumns")
557 self.assertEqual(len(tables[0].getColumns()), 4)
559 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
560 xToolkit.processEventsToIdle()
562 # check and reject changes
563 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
564 changesList = xTrackDlg.getChild("writerchanges")
566 # six changes, but only one visible in the Manage Changes dialog window
567 state = get_state_as_dict(changesList)
568 self.assertEqual(state['Children'], '6')
570 # This was 4 (missing handling of multiple different columns)
571 self.assertEqual(state['VisibleCount'], '2')
572 # Now: 2 changes (deleted and inserted columns)
573 self.assertEqual(2, len(changesList.getChildren()))
575 # accept column deletion
577 xAccBtn = xTrackDlg.getChild("accept")
578 xAccBtn.executeAction("CLICK", tuple())
580 # deleted column is removed
582 self.assertEqual(len(tables[0].getColumns()), 3)
584 # single parent left in the dialog window
585 self.assertEqual(1, len(changesList.getChildren()))
587 # reject column insertion
589 xAccBtn = xTrackDlg.getChild("reject")
590 xAccBtn.executeAction("CLICK", tuple())
592 # inserted column is removed
594 self.assertEqual(len(tables[0].getColumns()), 2)
596 # no changes in the dialog window
598 self.assertEqual(0, len(changesList.getChildren()))
600 def test_tdf155847_multiple_tracked_columns_crash(self):
601 with self.ui_test.load_file(get_url_for_data_file("TC-table-del-add.docx")) as document:
603 xWriterDoc = self.xUITest.getTopFocusWindow()
604 xWriterEdit = xWriterDoc.getChild("writer_edit")
606 # accept all changes and insert new columns with change tracking
607 self.xUITest.executeCommand(".uno:AcceptAllTrackedChanges")
608 tables = document.getTextTables()
609 self.assertEqual(2, len(tables))
610 self.assertEqual(len(tables[0].getColumns()), 3)
611 self.xUITest.executeCommand(".uno:InsertColumnsAfter")
612 self.xUITest.executeCommand(".uno:DeleteColumns")
613 self.assertEqual(len(tables[0].getColumns()), 4)
615 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
616 xToolkit.processEventsToIdle()
618 # check and reject changes
619 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptTrackedChanges", close_button="close") as xTrackDlg:
620 changesList = xTrackDlg.getChild("writerchanges")
622 # six changes, but only one visible in the Manage Changes dialog window
623 state = get_state_as_dict(changesList)
624 self.assertEqual(state['Children'], '6')
626 # This was 4 (missing handling of multiple different columns)
627 self.assertEqual(state['VisibleCount'], '2')
628 # Now: 2 changes (deleted and inserted columns)
629 self.assertEqual(2, len(changesList.getChildren()))
631 # select second tracked table column in tree list
632 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
633 changesList.executeAction("TYPE", mkPropertyValues({"KEYCODE": "DOWN"}))
635 # while not empty, i.e. starts with CH_TXT_TRACKED_DUMMY_CHAR
636 while len(get_state_as_dict(xWriterEdit)["SelectedText"]):
637 xToolkit.processEventsToIdle()
639 # reject column insertion
641 xAccBtn = xTrackDlg.getChild("reject")
642 # Without the fix in place, it would have crashed here
643 xAccBtn.executeAction("CLICK", tuple())
645 # inserted column is removed
647 self.assertEqual(len(tables[0].getColumns()), 3)
649 # single parent left in the dialog window
650 self.assertEqual(1, len(changesList.getChildren()))
652 # accept column deletion
654 xAccBtn = xTrackDlg.getChild("accept")
655 xAccBtn.executeAction("CLICK", tuple())
657 # deleted column is removed
659 self.assertEqual(len(tables[0].getColumns()), 2)
661 # no changes in the dialog window
663 self.assertEqual(0, len(changesList.getChildren()))
665 # vim: set shiftwidth=4 softtabstop=4 expandtab: