1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
from libreoffice.uno.propertyvalue import mkPropertyValues
from uitest.framework import UITestCase
from libreoffice.calc.document import get_cell_by_position
from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file
class mergedRowsColumns(UITestCase):
def test_merged_row_delete_tdf105412(self):
with self.ui_test.load_file(get_url_for_data_file("tdf105412.ods")) as calc_doc:
xTopWindow = self.xUITest.getTopFocusWindow()
gridwin = xTopWindow.getChild("grid_window")
gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A20"}))
self.xUITest.executeCommand(".uno:SelectRow")
self.xUITest.executeCommand(".uno:DeleteRows")
self.xUITest.executeCommand(".uno:Undo")
self.xUITest.executeCommand(".uno:Redo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 18).getString(), "L6")
def test_merged_columns_delete(self):
with self.ui_test.load_file(get_url_for_data_file("tdf105412.ods")) as calc_doc:
xTopWindow = self.xUITest.getTopFocusWindow()
gridwin = xTopWindow.getChild("grid_window")
gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
self.xUITest.executeCommand(".uno:SelectColumn")
self.xUITest.executeCommand(".uno:DeleteColumns")
self.xUITest.executeCommand(".uno:Undo")
self.xUITest.executeCommand(".uno:Redo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 18).getString(), "L6")
def test_undo_not_available_merged_cells_tdf37901(self):
with self.ui_test.load_file(get_url_for_data_file("tdf105412.ods")) as calc_doc:
xTopWindow = self.xUITest.getTopFocusWindow()
gridwin = xTopWindow.getChild("grid_window")
gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B1:B2"}))
self.xUITest.executeCommand(".uno:MergeCells")
self.xUITest.executeCommand(".uno:Undo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 1).getString(), "Key#")
self.xUITest.executeCommand(".uno:ToggleMergeCells")
self.xUITest.executeCommand(".uno:Undo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 1).getString(), "Key#")
gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A2:B2"}))
self.xUITest.executeCommand(".uno:MergeCells")
self.xUITest.executeCommand(".uno:Undo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 1).getString(), "Key#")
self.xUITest.executeCommand(".uno:ToggleMergeCells")
self.xUITest.executeCommand(".uno:Undo")
def test_calculations_in_merged_cells_tdf51368(self):
with self.ui_test.load_file(get_url_for_data_file("tdf51368.ods")) as calc_doc:
xTopWindow = self.xUITest.getTopFocusWindow()
gridwin = xTopWindow.getChild("grid_window")
#move the content of the hidden cells into the first cell
gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A11:A12"}))
with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
xMoveCells = xDialog.getChild("move-cells-radio")
xMoveCells.executeAction("CLICK", tuple())
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2 3")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "0")
self.xUITest.executeCommand(".uno:Undo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "3")
#keep the contents of the hidden cells
gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A11:A12"}))
with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
xMoveCells = xDialog.getChild("keep-content-radio")
xMoveCells.executeAction("CLICK", tuple())
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2")
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 11).getString(), "3")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "3")
self.xUITest.executeCommand(".uno:Undo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "3")
#Empty the contents of the hidden cells
gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A11:A12"}))
with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
xMoveCells = xDialog.getChild("move-cells-radio")
xMoveCells.executeAction("CLICK", tuple())
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2 3")
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 11).getString(), "")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "0")
self.xUITest.executeCommand(".uno:Undo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 10).getString(), "2")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 11).getString(), "3")
#A21-A22
gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A21:A22"}))
with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
xMoveCells = xDialog.getChild("keep-content-radio")
xMoveCells.executeAction("CLICK", tuple())
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 20).getString(), "2")
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 21).getString(), "3")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 21).getString(), "2")
self.xUITest.executeCommand(".uno:Undo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 20).getString(), "2")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 21).getString(), "2")
#A30-A32
gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "A30:A32"}))
with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
xMoveCells = xDialog.getChild("keep-content-radio")
xMoveCells.executeAction("CLICK", tuple())
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 31).getString(), "thisisbad")
self.xUITest.executeCommand(".uno:Undo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 0, 30).getString(), "is")
self.assertEqual(get_cell_by_position(calc_doc, 0, 1, 31).getString(), "thisisbad")
#J12-K12
gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "J12:K12"}))
with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
xMoveCells = xDialog.getChild("keep-content-radio")
xMoveCells.executeAction("CLICK", tuple())
self.assertEqual(get_cell_by_position(calc_doc, 0, 9, 11).getString(), "2")
self.assertEqual(get_cell_by_position(calc_doc, 0, 11, 11).getString(), "3")
self.xUITest.executeCommand(".uno:Undo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 9, 11).getString(), "2")
self.assertEqual(get_cell_by_position(calc_doc, 0, 11, 11).getString(), "3")
#J22-K22
gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "J22:K22"}))
with self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells") as xDialog:
xMoveCells = xDialog.getChild("keep-content-radio")
xMoveCells.executeAction("CLICK", tuple())
self.assertEqual(get_cell_by_position(calc_doc, 0, 9, 21).getString(), "2")
self.assertEqual(get_cell_by_position(calc_doc, 0, 11, 21).getString(), "2")
self.xUITest.executeCommand(".uno:Undo")
self.assertEqual(get_cell_by_position(calc_doc, 0, 9, 21).getString(), "2")
self.assertEqual(get_cell_by_position(calc_doc, 0, 11, 21).getString(), "2")
def test_move_merged_cells(self):
with self.ui_test.create_doc_in_start_center("calc"):
xTopWindow = self.xUITest.getTopFocusWindow()
gridwin = xTopWindow.getChild("grid_window")
gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B1:C1"}))
self.xUITest.executeCommand(".uno:ToggleMergeCells")
gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
self.xUITest.executeCommand(".uno:GoLeft")
self.xUITest.executeCommand(".uno:GoLeft")
self.assertEqual(get_state_as_dict(gridwin)["CurrentColumn"], "0")
self.assertEqual(get_state_as_dict(gridwin)["CurrentRow"], "0") #position A1
# vim: set shiftwidth=4 softtabstop=4 expandtab:
|