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/.
9 from uitest
.framework
import UITestCase
10 from uitest
.uihelper
.common
import get_state_as_dict
, get_url_for_data_file
11 from uitest
.uihelper
.common
import select_by_text
12 from libreoffice
.calc
.document
import get_cell_by_position
13 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
15 class consolidate(UITestCase
):
16 def test_consolidate(self
):
17 with self
.ui_test
.load_file(get_url_for_data_file("consolidate.ods")) as calc_doc
:
18 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:DataConsolidate") as xDialog
:
19 xfunc
= xDialog
.getChild("func")
20 xlbdataarea
= xDialog
.getChild("lbdataarea")
21 xadd
= xDialog
.getChild("add")
22 xbyrow
= xDialog
.getChild("byrow")
23 xbycol
= xDialog
.getChild("bycol")
24 xeddestarea
= xDialog
.getChild("eddestarea")
26 select_by_text(xfunc
, "Sum")
28 select_by_text(xlbdataarea
, "range1")
29 xadd
.executeAction("CLICK", tuple())
30 select_by_text(xlbdataarea
, "range2")
31 xadd
.executeAction("CLICK", tuple())
32 propsC
= {"TEXT": "range3"}
33 actionPropsC
= mkPropertyValues(propsC
)
34 xlbdataarea
.executeAction("SELECT", actionPropsC
)
35 xadd
.executeAction("CLICK", tuple())
36 xbyrow
.executeAction("CLICK", tuple())
37 xbycol
.executeAction("CLICK", tuple())
38 xeddestarea
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"CTRL+A"}))
39 xeddestarea
.executeAction("TYPE", mkPropertyValues({"KEYCODE":"BACKSPACE"}))
40 xeddestarea
.executeAction("TYPE", mkPropertyValues({"TEXT":"$Total.$A$2"}))
43 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 1, 2).getValue(), 300)
44 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 1, 3).getValue(), 303)
45 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 1, 4).getValue(), 306)
46 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 1, 5).getValue(), 309)
48 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 2, 2).getValue(), 303)
49 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 2, 3).getValue(), 306)
50 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 2, 4).getValue(), 309)
51 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 2, 5).getValue(), 312)
53 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 3, 2).getValue(), 306)
54 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 3, 3).getValue(), 309)
55 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 3, 4).getValue(), 312)
56 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 3, 5).getValue(), 315)
58 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 4, 2).getValue(), 309)
59 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 4, 3).getValue(), 312)
60 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 4, 4).getValue(), 315)
61 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 4, 5).getValue(), 318)
63 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:DataConsolidate") as xDialog
:
64 xfunc
= xDialog
.getChild("func")
65 xlbdataarea
= xDialog
.getChild("lbdataarea")
66 xdelete
= xDialog
.getChild("delete")
67 xbyrow
= xDialog
.getChild("byrow")
68 xbycol
= xDialog
.getChild("bycol")
69 xeddestarea
= xDialog
.getChild("eddestarea")
70 xconsareas
= xDialog
.getChild("consareas")
71 self
.assertEqual(get_state_as_dict(xfunc
)["SelectEntryText"], "Sum")
72 self
.assertEqual(get_state_as_dict(xconsareas
)["Children"], "3")
73 self
.assertEqual(get_state_as_dict(xeddestarea
)["Text"], "$Total.$A$2")
74 self
.assertEqual(get_state_as_dict(xbyrow
)["Selected"], "true")
75 self
.assertEqual(get_state_as_dict(xbycol
)["Selected"], "true")
77 xFirstEntry
= xconsareas
.getChild("0")
78 xFirstEntry
.executeAction("SELECT", tuple())
79 xdelete
.executeAction("CLICK", tuple())
80 self
.assertEqual(get_state_as_dict(xconsareas
)["Children"], "2")
82 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 1, 2).getValue(), 200)
83 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 1, 3).getValue(), 202)
84 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 1, 4).getValue(), 204)
85 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 1, 5).getValue(), 206)
87 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 2, 2).getValue(), 202)
88 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 2, 3).getValue(), 204)
89 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 2, 4).getValue(), 206)
90 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 2, 5).getValue(), 208)
92 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 3, 2).getValue(), 204)
93 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 3, 3).getValue(), 206)
94 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 3, 4).getValue(), 208)
95 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 3, 5).getValue(), 210)
97 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 4, 2).getValue(), 206)
98 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 4, 3).getValue(), 208)
99 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 4, 4).getValue(), 210)
100 self
.assertEqual(get_cell_by_position(calc_doc
, 0, 4, 5).getValue(), 212)
103 with self
.ui_test
.execute_modeless_dialog_through_command(".uno:DataConsolidate", close_button
="cancel"):
106 # vim: set shiftwidth=4 softtabstop=4 expandtab: