tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / qa / uitest / calc_tests / mergedRowsColumns.py
blob8399d8b76777a6401ca895f1bf5bda93ad2d5fa9
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 from libreoffice.uno.propertyvalue import mkPropertyValues
11 from uitest.framework import UITestCase
12 from libreoffice.calc.document import get_cell_by_position
13 from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
15 class mergedRowsColumns(UITestCase):
17 def test_merged_row_delete_tdf105412(self):
18 with self.ui_test.load_file(get_url_for_data_file("tdf105412.ods")) as calc_doc:
19 xTopWindow = self.xUITest.getTopFocusWindow()
20 gridwin = xTopWindow.getChild("grid_window")
22 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A20"}))
23 self.xUITest.executeCommand(".uno:SelectRow")
24 self.xUITest.executeCommand(".uno:DeleteRows")
25 self.xUITest.executeCommand(".uno:Undo")
26 self.xUITest.executeCommand(".uno:Redo")
28 self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 18).getString(), "L6")
30 def test_merged_columns_delete(self):
31 with self.ui_test.load_file(get_url_for_data_file("tdf105412.ods")) as calc_doc:
32 xTopWindow = self.xUITest.getTopFocusWindow()
33 gridwin = xTopWindow.getChild("grid_window")
35 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
36 self.xUITest.executeCommand(".uno:SelectColumn")
37 self.xUITest.executeCommand(".uno:DeleteColumns")
38 self.xUITest.executeCommand(".uno:Undo")
39 self.xUITest.executeCommand(".uno:Redo")
41 self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 18).getString(), "L6")
43 def test_undo_not_available_merged_cells_tdf37901(self):
44 with self.ui_test.load_file(get_url_for_data_file("tdf105412.ods")) as calc_doc:
45 xTopWindow = self.xUITest.getTopFocusWindow()
46 gridwin = xTopWindow.getChild("grid_window")
48 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B1:B2"}))
49 self.xUITest.executeCommand(".uno:MergeCells")
50 self.xUITest.executeCommand(".uno:Undo")
51 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 1).getString(), "Key#")
52 self.xUITest.executeCommand(".uno:ToggleMergeCells")
53 self.xUITest.executeCommand(".uno:Undo")
54 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 1).getString(), "Key#")
55 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A2:B2"}))
56 self.xUITest.executeCommand(".uno:MergeCells")
57 self.xUITest.executeCommand(".uno:Undo")
58 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 1).getString(), "Key#")
59 self.xUITest.executeCommand(".uno:ToggleMergeCells")
60 self.xUITest.executeCommand(".uno:Undo")
62 def test_calculations_in_merged_cells_tdf51368(self):
63 with self.ui_test.load_file(get_url_for_data_file("tdf51368.ods")) as calc_doc:
64 xTopWindow = self.xUITest.getTopFocusWindow()
65 gridwin = xTopWindow.getChild("grid_window")
67 #move the content of the hidden cells into the first cell
68 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A11:A12"}))
69 with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
70 xMoveCells = xDialog.getChild("move-cells-radio")
71 xMoveCells.executeAction("CLICK", tuple())
72 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2 3")
73 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "0")
75 self.xUITest.executeCommand(".uno:Undo")
76 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2")
77 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "3")
79 #keep the contents of the hidden cells
80 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A11:A12"}))
81 with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
82 xMoveCells = xDialog.getChild("keep-content-radio")
83 xMoveCells.executeAction("CLICK", tuple())
84 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2")
85 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 11).getString(), "3")
86 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "3")
88 self.xUITest.executeCommand(".uno:Undo")
89 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2")
90 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "3")
92 #Empty the contents of the hidden cells
93 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A11:A12"}))
94 with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
95 xMoveCells = xDialog.getChild("move-cells-radio")
96 xMoveCells.executeAction("CLICK", tuple())
97 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2 3")
98 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 11).getString(), "")
99 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "0")
101 self.xUITest.executeCommand(".uno:Undo")
102 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2")
103 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "3")
105 #A21-A22
106 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A21:A22"}))
107 with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
108 xMoveCells = xDialog.getChild("keep-content-radio")
109 xMoveCells.executeAction("CLICK", tuple())
110 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 20).getString(), "2")
111 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 21).getString(), "3")
112 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 21).getString(), "2")
114 self.xUITest.executeCommand(".uno:Undo")
115 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 20).getString(), "2")
116 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 21).getString(), "2")
118 #A30-A32
119 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A30:A32"}))
120 with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
121 xMoveCells = xDialog.getChild("keep-content-radio")
122 xMoveCells.executeAction("CLICK", tuple())
123 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 31).getString(), "thisisbad")
125 self.xUITest.executeCommand(".uno:Undo")
126 self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 30).getString(), "is")
127 self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 31).getString(), "thisisbad")
129 #J12-K12
130 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "J12:K12"}))
131 with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
133 xMoveCells = xDialog.getChild("keep-content-radio")
134 xMoveCells.executeAction("CLICK", tuple())
135 self.assertEqual(get_cell_by_position(calc_doc, 0, 9, 11).getString(), "2")
136 self.assertEqual(get_cell_by_position(calc_doc, 0, 11, 11).getString(), "3")
138 self.xUITest.executeCommand(".uno:Undo")
139 self.assertEqual(get_cell_by_position(calc_doc, 0, 9, 11).getString(), "2")
140 self.assertEqual(get_cell_by_position(calc_doc, 0, 11, 11).getString(), "3")
142 #J22-K22
143 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "J22:K22"}))
144 with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
145 xMoveCells = xDialog.getChild("keep-content-radio")
146 xMoveCells.executeAction("CLICK", tuple())
147 self.assertEqual(get_cell_by_position(calc_doc, 0, 9, 21).getString(), "2")
148 self.assertEqual(get_cell_by_position(calc_doc, 0, 11, 21).getString(), "2")
150 self.xUITest.executeCommand(".uno:Undo")
151 self.assertEqual(get_cell_by_position(calc_doc, 0, 9, 21).getString(), "2")
152 self.assertEqual(get_cell_by_position(calc_doc, 0, 11, 21).getString(), "2")
154 def test_move_merged_cells(self):
155 with self.ui_test.create_doc_in_start_center("calc"):
156 xTopWindow = self.xUITest.getTopFocusWindow()
157 gridwin = xTopWindow.getChild("grid_window")
159 gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B1:C1"}))
160 self.xUITest.executeCommand(".uno:ToggleMergeCells")
161 gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
162 self.xUITest.executeCommand(".uno:GoLeft")
163 self.xUITest.executeCommand(".uno:GoLeft")
164 self.assertEqual(get_state_as_dict(gridwin)["CurrentColumn"], "0")
165 self.assertEqual(get_state_as_dict(gridwin)["CurrentRow"], "0") #position A1
167 # vim: set shiftwidth=4 softtabstop=4 expandtab: