summaryrefslogtreecommitdiff
path: root/sc/qa/uitest/calc_tests/columns.py
blob: 7938d5a25c99a724dc29a6c673c646d66959c4b2 (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# -*- 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 uitest.framework import UITestCase
from uitest.uihelper.common import get_state_as_dict
from uitest.uihelper.common import change_measurement_unit
from libreoffice.uno.propertyvalue import mkPropertyValues

class CalcColumns(UITestCase):
    def test_column_width(self):
        with self.ui_test.create_doc_in_start_center("calc"):
            xCalcDoc = self.xUITest.getTopFocusWindow()
            gridwin = xCalcDoc.getChild("grid_window")
            document = self.ui_test.get_component()

            change_measurement_unit(self, "Centimeter")

            #select A1
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
            #column width
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            xdefault = xDialog.getChild("default")
            self.assertEqual(get_state_as_dict(xdefault)["Selected"], "true")  #default selected
            heightStrOrig = get_state_as_dict(xvalue)["Text"]
            heightVal = heightStrOrig[:4]  #default 2.26 cm
            xvalue.executeAction("UP", tuple())  #2.36 cm
            heightStr = get_state_as_dict(xvalue)["Text"]
            heightValNew = heightStr[:4]
            self.assertEqual(get_state_as_dict(xdefault)["Selected"], "false")  #default not selected
            self.assertEqual(heightValNew > heightVal, True)  #new value is bigger
            xdefault.executeAction("CLICK", tuple())  #click default
            self.assertEqual(get_state_as_dict(xvalue)["Text"] == heightStrOrig, True)  #default value set
            #write your own value
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"1 cm"}))
            # Click Ok
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)
            #verify
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.0001 cm")
            xCancel = xDialog.getChild("cancel")
            self.ui_test.close_dialog_through_button(xCancel)

    def test_column_width_two_columns(self):
        with self.ui_test.create_doc_in_start_center("calc"):
            xCalcDoc = self.xUITest.getTopFocusWindow()
            gridwin = xCalcDoc.getChild("grid_window")
            document = self.ui_test.get_component()

            change_measurement_unit(self, "Centimeter")

            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1", "EXTEND":"1"}))

            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            xdefault = xDialog.getChild("default")
            #write your own value
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"1 cm"}))
            # Click Ok
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)
            #verify
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.0001 cm")
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)

            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.0001 cm")
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)

    def test_column_width_copy(self):
        with self.ui_test.create_doc_in_start_center("calc"):
            xCalcDoc = self.xUITest.getTopFocusWindow()
            gridwin = xCalcDoc.getChild("grid_window")
            document = self.ui_test.get_component()

            change_measurement_unit(self, "Centimeter")

            #select A1
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
            #column width
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"1 cm"}))
            # Click Ok
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)
            #select column 1
            self.xUITest.executeCommand(".uno:SelectColumn")
            #copy
            self.xUITest.executeCommand(".uno:Copy")
            #select C1
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
            #paste
            self.xUITest.executeCommand(".uno:Paste")
            #verify
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.0001 cm")
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)

    def test_column_hide_show(self):
        with self.ui_test.create_doc_in_start_center("calc"):
            xCalcDoc = self.xUITest.getTopFocusWindow()
            gridwin = xCalcDoc.getChild("grid_window")
            document = self.ui_test.get_component()
            #select A3
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
            self.xUITest.executeCommand(".uno:HideColumn") #uno command moves focus one cell down
            #verify D1
            gridWinState = get_state_as_dict(gridwin)
            self.assertEqual(gridWinState["CurrentColumn"], "3")
            gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"LEFT"}))
            #verify B (column C is hidden)
            gridWinState = get_state_as_dict(gridwin)
            self.assertEqual(gridWinState["CurrentColumn"], "1")
            #Show hidden column: select B1:D1
            gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "B1:D1"}))
            self.xUITest.executeCommand(".uno:ShowColumn")
            #verify
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
            gridWinState = get_state_as_dict(gridwin)
            self.assertEqual(gridWinState["CurrentColumn"], "3")
            gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"LEFT"}))
            #verify C1 (COlumn C is not hidden)
            gridWinState = get_state_as_dict(gridwin)
            self.assertEqual(gridWinState["CurrentColumn"], "2")

    def test_column_test_move(self):
        with self.ui_test.create_doc_in_start_center("calc"):
            xCalcDoc = self.xUITest.getTopFocusWindow()
            gridwin = xCalcDoc.getChild("grid_window")
            document = self.ui_test.get_component()
            #select C1
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
            gridWinState = get_state_as_dict(gridwin)
            self.assertEqual(gridWinState["CurrentColumn"], "2")
            #right
            gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"RIGHT"}))
            #verify D1
            gridWinState = get_state_as_dict(gridwin)
            self.assertEqual(gridWinState["CurrentColumn"], "3")
            gridwin.executeAction("TYPE", mkPropertyValues({"KEYCODE":"LEFT"}))
            #verify C1
            gridWinState = get_state_as_dict(gridwin)
            self.assertEqual(gridWinState["CurrentColumn"], "2")

    def test_tdf117522_column_width_insert_left(self):
        with self.ui_test.create_doc_in_start_center("calc"):
            xCalcDoc = self.xUITest.getTopFocusWindow()
            gridwin = xCalcDoc.getChild("grid_window")
            document = self.ui_test.get_component()

            change_measurement_unit(self, "Centimeter")

            #select C1
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
            #column width
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"1 cm"}))
            # Click Ok
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)
            #select D1
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
            #column width
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"2 cm"}))
            # Click Ok
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)
            #select E1
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "E1"}))
            #column width
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
            xvalue.executeAction("TYPE", mkPropertyValues({"TEXT":"3 cm"}))
            # Click Ok
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)
            #select columns C-E
            gridwin.executeAction("SELECT", mkPropertyValues({"RANGE": "C1:E1"}))
            self.xUITest.executeCommand(".uno:SelectColumn")
            #Insert Columns Left
            self.xUITest.executeCommand(".uno:InsertColumnsBefore")
            #verify
            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "C1"}))
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.0001 cm")
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)

            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "D1"}))
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            self.assertEqual(get_state_as_dict(xvalue)["Text"], "2.0003 cm")
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)

            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "E1"}))
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            self.assertEqual(get_state_as_dict(xvalue)["Text"], "3.0004 cm")
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)

            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "F1"}))
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            self.assertEqual(get_state_as_dict(xvalue)["Text"], "1.0001 cm")
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)

            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "G1"}))
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            self.assertEqual(get_state_as_dict(xvalue)["Text"], "2.0003 cm")
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)

            gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "H1"}))
            self.ui_test.execute_dialog_through_command(".uno:ColumnWidth")
            xDialog = self.xUITest.getTopFocusWindow()
            xvalue = xDialog.getChild("value")
            self.assertEqual(get_state_as_dict(xvalue)["Text"], "3.0004 cm")
            xOK = xDialog.getChild("ok")
            self.ui_test.close_dialog_through_button(xOK)

# vim: set shiftwidth=4 softtabstop=4 expandtab: