tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / qa / uitest / calc_tests4 / trackedChanges.py
blob5ad8c3f3a9d2b2c93c1c7c1f014a21421153eaad
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
12 from uitest.framework import UITestCase
13 from libreoffice.calc.document import get_cell_by_position
14 from libreoffice.uno.propertyvalue import mkPropertyValues
15 from uitest.uihelper.calc import enter_text_to_cell
16 from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
17 import datetime
19 class CalcTrackedChanges(UITestCase):
21 def test_tdf131907(self):
22 with self.ui_test.load_file(get_url_for_data_file("tdf131907.ods")):
23 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptChanges", close_button="close") as xTrackDlg:
25 xChangesList = xTrackDlg.getChild("calcchanges")
26 self.assertEqual(1, len(xChangesList.getChildren()))
28 textStart = "Row inserted \tSheet1.1:1\t \t"
29 textEnd = "(Row 1:1 inserted)"
30 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].startswith(textStart))
31 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].endswith(textEnd))
33 #it would crash here
34 xRejBtn = xTrackDlg.getChild("reject")
35 xRejBtn.executeAction("CLICK", tuple())
37 self.assertEqual(2, len(xChangesList.getChildren()))
38 self.assertEqual(get_state_as_dict(xChangesList.getChild('0'))["Text"], "Accepted")
39 self.assertEqual(get_state_as_dict(xChangesList.getChild('1'))["Text"], "Rejected")
42 def test_tdf66263_Protect_Records(self):
43 with self.ui_test.create_doc_in_start_center("calc"):
44 self.ui_test.wait_until_child_is_available("grid_window")
45 self.xUITest.executeCommand(".uno:TraceChangeMode")
46 #protect dialog
47 with self.ui_test.execute_dialog_through_command(".uno:ProtectTraceChangeMode") as xDialog:
48 xpass = xDialog.getChild("pass1ed")
49 xpass.executeAction("TYPE", mkPropertyValues({"TEXT":"a"}))
50 xconfirm = xDialog.getChild("confirm1ed")
51 xconfirm.executeAction("TYPE", mkPropertyValues({"TEXT":"a"}))
52 #verify password
53 with self.ui_test.execute_dialog_through_command(".uno:ProtectTraceChangeMode") as xDialog:
54 xpass = xDialog.getChild("pass1ed")
55 xpass.executeAction("TYPE", mkPropertyValues({"TEXT":"a"}))
57 def test_ContentChange(self):
59 with self.ui_test.create_doc_in_start_center("calc") as document:
60 self.ui_test.wait_until_child_is_available("grid_window")
61 xCalcDoc = self.xUITest.getTopFocusWindow()
62 gridwin = xCalcDoc.getChild("grid_window")
63 #track changes; enter text to cell
64 self.xUITest.executeCommand(".uno:TraceChangeMode")
65 enter_text_to_cell(gridwin, "A1", "Hello")
66 enter_text_to_cell(gridwin, "A1", "There")
68 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptChanges", close_button="close") as xTrackDlg:
70 xChangesList = xTrackDlg.getChild("calcchanges")
71 self.assertEqual(1, len(xChangesList.getChildren()))
73 textStart = "Changed contents\tSheet1.A1\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
75 xChild = xChangesList.getChild('0')
76 self.assertTrue(get_state_as_dict(xChild)["Text"].startswith(textStart))
78 xChild.executeAction("EXPAND", tuple())
80 self.assertEqual(3, len(xChild.getChildren()))
81 textStartChild1 = "<empty>\tSheet1.A1\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
82 textEndChild1 = "(Original: <empty>)"
83 textStartChild2 = "'Hello'\tSheet1.A1\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
84 textEndChild2 = "(Changed to 'Hello')"
85 textStartChild3 = "'There'\tSheet1.A1\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
86 textEndChild3 = "(Changed to 'There')"
88 self.assertTrue(get_state_as_dict(xChild.getChild('0'))["Text"].startswith(textStartChild1))
89 self.assertTrue(get_state_as_dict(xChild.getChild('0'))["Text"].endswith(textEndChild1))
90 self.assertTrue(get_state_as_dict(xChild.getChild('1'))["Text"].startswith(textStartChild2))
91 self.assertTrue(get_state_as_dict(xChild.getChild('1'))["Text"].endswith(textEndChild2))
92 self.assertTrue(get_state_as_dict(xChild.getChild('2'))["Text"].startswith(textStartChild3))
93 self.assertTrue(get_state_as_dict(xChild.getChild('2'))["Text"].endswith(textEndChild3))
95 self.assertEqual("There", get_cell_by_position(document, 0, 0, 0).getString())
97 def test_Tdf153096(self):
99 with self.ui_test.create_doc_in_start_center("calc"):
100 self.ui_test.wait_until_child_is_available("grid_window")
101 xCalcDoc = self.xUITest.getTopFocusWindow()
102 gridwin = xCalcDoc.getChild("grid_window")
103 #track changes; enter text to cell
104 self.xUITest.executeCommand(".uno:TraceChangeMode")
105 enter_text_to_cell(gridwin, "A1", "Hello")
107 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
109 self.xUITest.executeCommand(".uno:DeleteRows")
111 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptChanges", close_button="close") as xTrackDlg:
113 xChangesList = xTrackDlg.getChild("calcchanges")
114 self.assertEqual(1, len(xChangesList.getChildren()))
116 textStart = "Row deleted\t(Sheet1.1:1)\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
117 textEnd = "(Row 1:1 deleted)"
119 xChild = xChangesList.getChild('0')
121 # Without the fix in place, this test would have failed here
122 self.assertTrue(get_state_as_dict(xChild)["Text"].startswith(textStart))
123 self.assertTrue(get_state_as_dict(xChild)["Text"].endswith(textEnd))
125 xChild.executeAction("EXPAND", tuple())
127 self.assertEqual(1, len(xChild.getChildren()))
128 textStartChild1 = "Changed contents\t(Sheet1.A1)\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
129 textEndChild1 = "(Cell (A1) changed from '<empty>' to 'Hello')"
131 self.assertTrue(get_state_as_dict(xChild.getChild('0'))["Text"].startswith(textStartChild1))
132 self.assertTrue(get_state_as_dict(xChild.getChild('0'))["Text"].endswith(textEndChild1))
134 def test_tracked_changes_accept(self):
136 with self.ui_test.create_doc_in_start_center("calc") as document:
137 self.ui_test.wait_until_child_is_available("grid_window")
138 xCalcDoc = self.xUITest.getTopFocusWindow()
139 gridwin = xCalcDoc.getChild("grid_window")
140 #track changes; enter text to cell
141 self.xUITest.executeCommand(".uno:TraceChangeMode")
142 enter_text_to_cell(gridwin, "A1", "Test LibreOffice")
143 enter_text_to_cell(gridwin, "A2", "Test LibreOffice")
144 #accept tracked changes
145 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptChanges", close_button="close") as xTrackDlg:
147 xChangesList = xTrackDlg.getChild("calcchanges")
148 self.assertEqual(2, len(xChangesList.getChildren()))
150 textStart = "Changed contents\tSheet1.A1\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
151 textEnd = "(Cell A1 changed from '<empty>' to 'Test LibreOffice')"
152 textStart2 = "Changed contents\tSheet1.A2\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
153 textEnd2 = "(Cell A2 changed from '<empty>' to 'Test LibreOffice')"
154 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].startswith(textStart))
155 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].endswith(textEnd))
156 self.assertTrue(get_state_as_dict(xChangesList.getChild('1'))["Text"].startswith(textStart2))
157 self.assertTrue(get_state_as_dict(xChangesList.getChild('1'))["Text"].endswith(textEnd2))
159 xAccBtn = xTrackDlg.getChild("accept")
160 xAccBtn.executeAction("CLICK", tuple())
162 self.assertEqual(2, len(xChangesList.getChildren()))
163 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].startswith(textStart2))
164 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].endswith(textEnd2))
165 self.assertEqual(get_state_as_dict(xChangesList.getChild('1'))["Text"], "Accepted")
167 xAccBtn = xTrackDlg.getChild("accept")
168 xAccBtn.executeAction("CLICK", tuple())
170 self.assertEqual(1, len(xChangesList.getChildren()))
171 self.assertEqual(get_state_as_dict(xChangesList.getChild('0'))["Text"], "Accepted")
172 xChangesList.getChild('0').executeAction("EXPAND", tuple())
174 self.assertEqual(2, len(xChangesList.getChild('0').getChildren()))
176 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('0'))["Text"].startswith(textStart))
177 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('0'))["Text"].endswith(textEnd))
178 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('1'))["Text"].startswith(textStart2))
179 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('1'))["Text"].endswith(textEnd2))
182 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Test LibreOffice")
184 def test_tracked_changes_acceptall(self):
186 with self.ui_test.create_doc_in_start_center("calc") as document:
187 self.ui_test.wait_until_child_is_available("grid_window")
188 xCalcDoc = self.xUITest.getTopFocusWindow()
189 gridwin = xCalcDoc.getChild("grid_window")
190 #track changes; enter text to cell
191 self.xUITest.executeCommand(".uno:TraceChangeMode")
192 enter_text_to_cell(gridwin, "A1", "Test LibreOffice")
193 enter_text_to_cell(gridwin, "A2", "Test LibreOffice")
194 #accept All tracked changes
195 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptChanges", close_button="close") as xTrackDlg:
197 xChangesList = xTrackDlg.getChild("calcchanges")
198 self.assertEqual(2, len(xChangesList.getChildren()))
200 textStart = "Changed contents\tSheet1.A1\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
201 textEnd = "(Cell A1 changed from '<empty>' to 'Test LibreOffice')"
202 textStart2 = "Changed contents\tSheet1.A2\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
203 textEnd2 = "(Cell A2 changed from '<empty>' to 'Test LibreOffice')"
204 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].startswith(textStart))
205 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].endswith(textEnd))
206 self.assertTrue(get_state_as_dict(xChangesList.getChild('1'))["Text"].startswith(textStart2))
207 self.assertTrue(get_state_as_dict(xChangesList.getChild('1'))["Text"].endswith(textEnd2))
209 xAccBtn = xTrackDlg.getChild("acceptall")
210 xAccBtn.executeAction("CLICK", tuple())
212 self.assertEqual(1, len(xChangesList.getChildren()))
213 self.assertEqual(get_state_as_dict(xChangesList.getChild('0'))["Text"], "Accepted")
214 xChangesList.getChild('0').executeAction("EXPAND", tuple())
216 self.assertEqual(2, len(xChangesList.getChild('0').getChildren()))
218 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('0'))["Text"].startswith(textStart))
219 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('0'))["Text"].endswith(textEnd))
220 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('1'))["Text"].startswith(textStart2))
221 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('1'))["Text"].endswith(textEnd2))
224 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "Test LibreOffice")
226 def test_tracked_changes_reject(self):
228 with self.ui_test.create_doc_in_start_center("calc") as document:
229 self.ui_test.wait_until_child_is_available("grid_window")
230 xCalcDoc = self.xUITest.getTopFocusWindow()
231 gridwin = xCalcDoc.getChild("grid_window")
232 #track changes; enter text to cell
233 self.xUITest.executeCommand(".uno:TraceChangeMode")
234 enter_text_to_cell(gridwin, "A1", "Test LibreOffice")
235 enter_text_to_cell(gridwin, "A2", "Test LibreOffice")
236 #accept tracked changes
237 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptChanges", close_button="close") as xTrackDlg:
239 xChangesList = xTrackDlg.getChild("calcchanges")
240 self.assertEqual(2, len(xChangesList.getChildren()))
242 textStart = "Changed contents\tSheet1.A1\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
243 textEnd = "(Cell A1 changed from '<empty>' to 'Test LibreOffice')"
244 textStart2 = "Changed contents\tSheet1.A2\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
245 textEnd2 = "(Cell A2 changed from '<empty>' to 'Test LibreOffice')"
246 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].startswith(textStart))
247 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].endswith(textEnd))
248 self.assertTrue(get_state_as_dict(xChangesList.getChild('1'))["Text"].startswith(textStart2))
249 self.assertTrue(get_state_as_dict(xChangesList.getChild('1'))["Text"].endswith(textEnd2))
251 xRejBtn = xTrackDlg.getChild("reject")
252 xRejBtn.executeAction("CLICK", tuple())
254 self.assertEqual(3, len(xChangesList.getChildren()))
255 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].startswith(textStart2))
256 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].endswith(textEnd2))
257 self.assertEqual(get_state_as_dict(xChangesList.getChild('1'))["Text"], "Accepted")
258 self.assertEqual(get_state_as_dict(xChangesList.getChild('2'))["Text"], "Rejected")
260 xAccBtn = xTrackDlg.getChild("reject")
261 xAccBtn.executeAction("CLICK", tuple())
263 self.assertEqual(2, len(xChangesList.getChildren()))
264 self.assertEqual(get_state_as_dict(xChangesList.getChild('0'))["Text"], "Accepted")
265 self.assertEqual(get_state_as_dict(xChangesList.getChild('1'))["Text"], "Rejected")
267 xChangesList.getChild('0').executeAction("EXPAND", tuple())
268 self.assertEqual(2, len(xChangesList.getChild('0').getChildren()))
270 textEnd3 = "(Cell A1 changed from 'Test LibreOffice' to '<empty>')"
271 textEnd4 = "(Cell A2 changed from 'Test LibreOffice' to '<empty>')"
272 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('0'))["Text"].startswith(textStart))
273 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('0'))["Text"].endswith(textEnd3))
274 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('1'))["Text"].startswith(textStart2))
275 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('1'))["Text"].endswith(textEnd4))
277 xChangesList.getChild('1').executeAction("EXPAND", tuple())
278 self.assertEqual(2, len(xChangesList.getChild('1').getChildren()))
280 self.assertTrue(get_state_as_dict(xChangesList.getChild('1').getChild('0'))["Text"].startswith(textStart))
281 self.assertTrue(get_state_as_dict(xChangesList.getChild('1').getChild('0'))["Text"].endswith(textEnd))
282 self.assertTrue(get_state_as_dict(xChangesList.getChild('1').getChild('1'))["Text"].startswith(textStart2))
283 self.assertTrue(get_state_as_dict(xChangesList.getChild('1').getChild('1'))["Text"].endswith(textEnd2))
286 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "")
288 def test_tracked_changes_rejectall(self):
290 with self.ui_test.create_doc_in_start_center("calc") as document:
291 self.ui_test.wait_until_child_is_available("grid_window")
292 xCalcDoc = self.xUITest.getTopFocusWindow()
293 gridwin = xCalcDoc.getChild("grid_window")
294 #track changes; enter text to cell
295 self.xUITest.executeCommand(".uno:TraceChangeMode")
296 enter_text_to_cell(gridwin, "A1", "Test LibreOffice")
297 enter_text_to_cell(gridwin, "A2", "Test LibreOffice")
298 #accept tracked changes
299 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptChanges", close_button="close") as xTrackDlg:
301 xChangesList = xTrackDlg.getChild("calcchanges")
302 self.assertEqual(2, len(xChangesList.getChildren()))
304 textStart = "Changed contents\tSheet1.A1\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
305 textEnd = "(Cell A1 changed from '<empty>' to 'Test LibreOffice')"
306 textStart2 = "Changed contents\tSheet1.A2\tUnknown Author\t" + datetime.datetime.now().strftime("%m/%d/%Y")
307 textEnd2 = "(Cell A2 changed from '<empty>' to 'Test LibreOffice')"
308 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].startswith(textStart))
309 self.assertTrue(get_state_as_dict(xChangesList.getChild('0'))["Text"].endswith(textEnd))
310 self.assertTrue(get_state_as_dict(xChangesList.getChild('1'))["Text"].startswith(textStart2))
311 self.assertTrue(get_state_as_dict(xChangesList.getChild('1'))["Text"].endswith(textEnd2))
313 xAccBtn = xTrackDlg.getChild("rejectall")
314 xAccBtn.executeAction("CLICK", tuple())
316 self.assertEqual(2, len(xChangesList.getChildren()))
317 self.assertEqual(get_state_as_dict(xChangesList.getChild('0'))["Text"], "Accepted")
318 self.assertEqual(get_state_as_dict(xChangesList.getChild('1'))["Text"], "Rejected")
320 xChangesList.getChild('0').executeAction("EXPAND", tuple())
321 self.assertEqual(2, len(xChangesList.getChild('0').getChildren()))
323 textEnd3 = "(Cell A1 changed from 'Test LibreOffice' to '<empty>')"
324 textEnd4 = "(Cell A2 changed from 'Test LibreOffice' to '<empty>')"
325 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('0'))["Text"].startswith(textStart2))
326 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('0'))["Text"].endswith(textEnd4))
327 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('1'))["Text"].startswith(textStart))
328 self.assertTrue(get_state_as_dict(xChangesList.getChild('0').getChild('1'))["Text"].endswith(textEnd3))
330 xChangesList.getChild('1').executeAction("EXPAND", tuple())
331 self.assertEqual(2, len(xChangesList.getChild('1').getChildren()))
333 self.assertTrue(get_state_as_dict(xChangesList.getChild('1').getChild('0'))["Text"].startswith(textStart))
334 self.assertTrue(get_state_as_dict(xChangesList.getChild('1').getChild('0'))["Text"].endswith(textEnd))
335 self.assertTrue(get_state_as_dict(xChangesList.getChild('1').getChild('1'))["Text"].startswith(textStart2))
336 self.assertTrue(get_state_as_dict(xChangesList.getChild('1').getChild('1'))["Text"].endswith(textEnd2))
339 self.assertEqual(get_cell_by_position(document, 0, 0, 0).getString(), "")
341 def test_tdf136062(self):
343 with self.ui_test.load_file(get_url_for_data_file("tdf136062.ods")):
345 self.xUITest.getTopFocusWindow()
347 with self.ui_test.execute_modeless_dialog_through_command(".uno:AcceptChanges", close_button="close") as xTrackDlg:
349 xChangesList = xTrackDlg.getChild("calcchanges")
350 self.assertEqual(1, len(xChangesList.getChildren()))
352 xRejectAllBtn = xTrackDlg.getChild("rejectall")
353 xRejectBtn = xTrackDlg.getChild("reject")
354 xAcceptAllBtn = xTrackDlg.getChild("acceptall")
355 xAcceptBtn = xTrackDlg.getChild("accept")
357 # Without the fix in place, it would have failed with
358 # AssertionError: 'R~eject All' != 'R~eject All/Clear formatting'
359 self.assertEqual('R~eject All', get_state_as_dict(xRejectAllBtn)['Text'])
360 self.assertEqual('~Reject', get_state_as_dict(xRejectBtn)['Text'])
361 self.assertEqual('A~ccept All', get_state_as_dict(xAcceptAllBtn)['Text'])
362 self.assertEqual('~Accept', get_state_as_dict(xAcceptBtn)['Text'])
364 def test_tdf85353(self):
365 with self.ui_test.create_doc_in_start_center("calc"):
366 xCalcDoc = self.xUITest.getTopFocusWindow()
367 gridwin = xCalcDoc.getChild("grid_window")
369 enter_text_to_cell(gridwin, "A1", "15")
370 enter_text_to_cell(gridwin, "D1", "0")
371 enter_text_to_cell(gridwin, "E1", "0")
373 with self.ui_test.execute_dialog_through_command(".uno:CompareDocuments", close_button="") as xOpenDialog:
374 xFileName = xOpenDialog.getChild("file_name")
375 xFileName.executeAction("TYPE", mkPropertyValues({"TEXT": get_url_for_data_file("tdf85353.ods")}))
376 xOpenBtn = xOpenDialog.getChild("open")
378 with self.ui_test.execute_dialog_through_action(xOpenBtn, 'CLICK', close_button="close") as xTrackDlg:
379 changesList = xTrackDlg.getChild("calcchanges")
381 # Without the fix in place, this test would have failed with
382 # AssertionError: 1 != 0
383 self.assertEqual(1, len(changesList.getChildren()))
384 self.assertTrue(get_state_as_dict(changesList.getChild('0'))['Text'].startswith("Changed contents\tSheet1.E1"))
385 self.assertTrue(get_state_as_dict(changesList.getChild('0'))['Text'].endswith("(Cell E1 changed from '5' to '0')"))
387 # vim: set shiftwidth=4 softtabstop=4 expandtab: