summaryrefslogtreecommitdiff
path: root/sc/qa/uitest/calc_tests/mergedRowsColumns.py
blob: 2f081e6355cda6b65ccf421234d2f648d4b124ec (plain)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# 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_column
import time
from uitest.debug import sleep
from uitest.path import get_srcdir_url
from libreoffice.calc.document import get_cell_by_position
from uitest.uihelper.common import get_state_as_dict

def get_url_for_data_file(file_name):
    return get_srcdir_url() + "/sc/qa/uitest/calc_tests/data/" + file_name

class mergedRowsColumns(UITestCase):

    def test_merged_row_delete_tdf105412(self):
        calc_doc = self.ui_test.load_file(get_url_for_data_file("tdf105412.ods"))
        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")

        self.ui_test.close_doc()

    def test_merged_columns_delete(self):
        calc_doc = self.ui_test.load_file(get_url_for_data_file("tdf105412.ods"))
        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")

        self.ui_test.close_doc()

    def test_undo_not_available_merged_cells_tdf37901(self):
        calc_doc = self.ui_test.load_file(get_url_for_data_file("tdf105412.ods"))
        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")

        self.ui_test.close_doc()

    def test_calculations_in_merged_cells_tdf51368(self):
        calc_doc = self.ui_test.load_file(get_url_for_data_file("tdf51368.ods"))
        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"}))
        self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells")
        xDialog = self.xUITest.getTopFocusWindow()

        xMoveCells = xDialog.getChild("move-cells-radio")
        xMoveCells.executeAction("CLICK", tuple())
        self.ui_test.close_dialog_through_button(xDialog.getChild("ok"))
        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"}))
        self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells")
        xDialog = self.xUITest.getTopFocusWindow()

        xMoveCells = xDialog.getChild("keep-content-radio")
        xMoveCells.executeAction("CLICK", tuple())
        self.ui_test.close_dialog_through_button(xDialog.getChild("ok"))
        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"}))
        self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells")
        xDialog = self.xUITest.getTopFocusWindow()

        xMoveCells = xDialog.getChild("move-cells-radio")
        xMoveCells.executeAction("CLICK", tuple())
        self.ui_test.close_dialog_through_button(xDialog.getChild("ok"))
        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"}))
        self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells")
        xDialog = self.xUITest.getTopFocusWindow()

        xMoveCells = xDialog.getChild("keep-content-radio")
        xMoveCells.executeAction("CLICK", tuple())
        self.ui_test.close_dialog_through_button(xDialog.getChild("ok"))
        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"}))
        self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells")
        xDialog = self.xUITest.getTopFocusWindow()

        xMoveCells = xDialog.getChild("keep-content-radio")
        xMoveCells.executeAction("CLICK", tuple())
        self.ui_test.close_dialog_through_button(xDialog.getChild("ok"))
        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"}))
        self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells")
        xDialog = self.xUITest.getTopFocusWindow()

        xMoveCells = xDialog.getChild("keep-content-radio")
        xMoveCells.executeAction("CLICK", tuple())
        self.ui_test.close_dialog_through_button(xDialog.getChild("ok"))
        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"}))
        self.ui_test.execute_dialog_through_command(".uno:ToggleMergeCells")
        xDialog = self.xUITest.getTopFocusWindow()

        xMoveCells = xDialog.getChild("keep-content-radio")
        xMoveCells.executeAction("CLICK", tuple())
        self.ui_test.close_dialog_through_button(xDialog.getChild("ok"))
        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")
        self.ui_test.close_doc()

    def test_merge_merged_cells_tdf63766(self):
        calc_doc = self.ui_test.load_file(get_url_for_data_file("tdf105412.ods"))
        xTopWindow = self.xUITest.getTopFocusWindow()
        gridwin = xTopWindow.getChild("grid_window")

        gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "C19:F22"}))
        self.xUITest.executeCommand(".uno:ToggleMergeCells")
        self.assertEqual(get_cell_by_position(calc_doc, 0, 2, 18).getString(), "L6")
        self.xUITest.executeCommand(".uno:Undo")

        self.ui_test.close_doc()

    def test_move_merged_cells(self):
        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

        self.ui_test.close_doc()
# vim: set shiftwidth=4 softtabstop=4 expandtab: