1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
9 from uitest
.framework
import UITestCase
10 from libreoffice
.calc
.document
import get_column
11 from uitest
.uihelper
.calc
import enter_text_to_cell
12 from libreoffice
.calc
.document
import get_cell_by_position
13 from uitest
.uihelper
.common
import select_pos
14 from uitest
.uihelper
.common
import get_state_as_dict
15 import org
.libreoffice
.unotest
18 from uitest
.debug
import sleep
20 def get_url_for_data_file(file_name
):
21 return pathlib
.Path(org
.libreoffice
.unotest
.makeCopyFromTDOC(file_name
)).as_uri()
23 class Subtotals(UITestCase
):
25 def test_tdf114720(self
):
26 calc_doc
= self
.ui_test
.create_doc_in_start_center("calc")
27 XcalcDoc
= self
.xUITest
.getTopFocusWindow()
28 document
= self
.ui_test
.get_component()
29 gridwin
= XcalcDoc
.getChild("grid_window")
31 enter_text_to_cell(gridwin
, "A1", "1")
32 enter_text_to_cell(gridwin
, "A2", "1")
33 enter_text_to_cell(gridwin
, "A3", "1")
34 enter_text_to_cell(gridwin
, "A4", "1")
35 enter_text_to_cell(gridwin
, "A5", "1")
36 enter_text_to_cell(gridwin
, "A6", "1")
37 enter_text_to_cell(gridwin
, "A7", "1")
38 enter_text_to_cell(gridwin
, "A8", "1")
39 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "A9"}))
41 self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals")
42 xDialog
= self
.xUITest
.getTopFocusWindow()
44 xOKBtn
= xDialog
.getChild("ok")
45 self
.ui_test
.close_dialog_through_button(xOKBtn
)
46 self
.assertEqual(get_cell_by_position(document
, 0, 0, 7).getValue(), 1)
47 self
.assertEqual(get_cell_by_position(document
, 0, 0, 8).getString(), "")
50 self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals")
51 xDialog
= self
.xUITest
.getTopFocusWindow()
52 xCancelBtn
= xDialog
.getChild("cancel")
53 self
.ui_test
.close_dialog_through_button(xCancelBtn
)
55 self
.ui_test
.close_doc()
57 def test_tdf88792(self
):
58 calc_doc
= self
.ui_test
.load_file(get_url_for_data_file("tdf88792.ods"))
59 XcalcDoc
= self
.xUITest
.getTopFocusWindow()
60 document
= self
.ui_test
.get_component()
61 gridwin
= XcalcDoc
.getChild("grid_window")
64 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
65 # Select from the menu bar Data
66 # Select option subtotal
67 # Subtotal dialog displays
68 self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals")
69 xDialog
= self
.xUITest
.getTopFocusWindow()
70 # Select group by: Category
71 xGroupBy
= xDialog
.getChild("group_by")
72 props
= {"TEXT": "Category"}
73 actionProps
= mkPropertyValues(props
)
74 xGroupBy
.executeAction("SELECT", actionProps
)
75 # Select calculate subtotals for the months - selected by default
77 xTabs
= xDialog
.getChild("tabcontrol")
78 select_pos(xTabs
, "3")
79 # select option include formats
80 xformats
= xDialog
.getChild("formats")
81 xformats
.executeAction("CLICK", tuple())
83 xOKBtn
= xDialog
.getChild("ok")
84 self
.ui_test
.close_dialog_through_button(xOKBtn
)
86 self
.assertEqual(get_cell_by_position(document
, 0, 3, 5).getValue(), 28000)
87 self
.ui_test
.close_doc()
89 def test_tdf88735(self
):
90 calc_doc
= self
.ui_test
.load_file(get_url_for_data_file("tdf88735.ods"))
91 XcalcDoc
= self
.xUITest
.getTopFocusWindow()
92 document
= self
.ui_test
.get_component()
93 gridwin
= XcalcDoc
.getChild("grid_window")
95 self
.xUITest
.executeCommand(".uno:SelectAll")#use uno command Menu Edit->Select All
96 # 2 invoke sub-total menu and select none
97 self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals")
98 xDialog
= self
.xUITest
.getTopFocusWindow()
99 xGroupBy
= xDialog
.getChild("group_by")
100 props
= {"TEXT": "- none -"}
101 actionProps
= mkPropertyValues(props
)
102 xGroupBy
.executeAction("SELECT", actionProps
)
103 xOKBtn
= xDialog
.getChild("ok")
104 self
.ui_test
.close_dialog_through_button(xOKBtn
)
105 # 2 invoke sort menu and... crash
106 self
.ui_test
.execute_dialog_through_command(".uno:DataSort")
107 xDialog
= self
.xUITest
.getTopFocusWindow()
108 xCancelBtn
= xDialog
.getChild("cancel")
109 self
.ui_test
.close_dialog_through_button(xCancelBtn
)
111 self
.assertEqual(get_cell_by_position(document
, 0, 0, 8).getString(), "z")
112 self
.assertEqual(get_cell_by_position(document
, 0, 1, 8).getValue(), 8)
113 self
.ui_test
.close_doc()
115 def test_tdf56958(self
):
116 calc_doc
= self
.ui_test
.load_file(get_url_for_data_file("tdf56958.ods"))
117 XcalcDoc
= self
.xUITest
.getTopFocusWindow()
118 document
= self
.ui_test
.get_component()
119 gridwin
= XcalcDoc
.getChild("grid_window")
120 # 1. Open the test file
122 self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals")
123 xDialog
= self
.xUITest
.getTopFocusWindow()
124 # 3. Group by->Trans date
125 xGroupBy
= xDialog
.getChild("group_by")
126 props
= {"TEXT": "Trans Date"}
127 actionProps
= mkPropertyValues(props
)
128 xGroupBy
.executeAction("SELECT", actionProps
)
129 # 4. Tick 'Calculate subtotals for' -> Amount (grid1)
130 xCheckListMenu
= xDialog
.getChild("grid1")
131 xTreeList
= xCheckListMenu
.getChild("columns")
132 xFirstEntry
= xTreeList
.getChild("2")
133 xFirstEntry
.executeAction("CLICK", tuple())
135 xOKBtn
= xDialog
.getChild("ok")
136 self
.ui_test
.close_dialog_through_button(xOKBtn
)
138 self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals")
139 xDialog
= self
.xUITest
.getTopFocusWindow()
140 # 7. Group by->-none-
141 xGroupBy
= xDialog
.getChild("group_by")
142 props
= {"TEXT": "- none -"}
143 actionProps
= mkPropertyValues(props
)
144 xGroupBy
.executeAction("SELECT", actionProps
)
145 # 8. Untick 'Calculate subtotals for' -> Amount
146 xCheckListMenu
= xDialog
.getChild("grid1")
147 xTreeList
= xCheckListMenu
.getChild("columns")
148 xFirstEntry
= xTreeList
.getChild("2")
149 xFirstEntry
.executeAction("CLICK", tuple())
151 xOKBtn
= xDialog
.getChild("ok")
152 self
.ui_test
.close_dialog_through_button(xOKBtn
)
154 self
.ui_test
.execute_dialog_through_command(".uno:DataSort")
155 xDialog
= self
.xUITest
.getTopFocusWindow()
156 # 11. Sort key 1->Post Date.
157 sortkey1
= xDialog
.getChild("sortlb")
158 props
= {"TEXT": "Post Date"}
159 actionProps
= mkPropertyValues(props
)
160 sortkey1
.executeAction("SELECT", actionProps
)
161 # 12. Sort key 2->-undefined-
162 sortkey2
= xDialog
.getChild("sortuserlb")
163 props
= {"TEXT": "- undefined -"}
164 actionProps
= mkPropertyValues(props
)
165 sortkey2
.executeAction("SELECT", actionProps
)
167 xOKBtn
= xDialog
.getChild("ok")
168 self
.ui_test
.close_dialog_through_button(xOKBtn
)
169 self
.assertEqual(get_cell_by_position(document
, 0, 2, 1).getValue(), -0.25)
170 self
.ui_test
.close_doc()
172 def test_tdf55734(self
):
173 calc_doc
= self
.ui_test
.load_file(get_url_for_data_file("tdf55734.ods"))
174 XcalcDoc
= self
.xUITest
.getTopFocusWindow()
175 document
= self
.ui_test
.get_component()
176 gridwin
= XcalcDoc
.getChild("grid_window")
177 # 1. Open attached document
178 # 2. Place cursor in cell outside of subtotals range (e.g. B7)
179 gridwin
.executeAction("SELECT", mkPropertyValues({"CELL": "B7"}))
180 # 3. Data → Subtotals
181 self
.ui_test
.execute_dialog_through_command(".uno:DataSubTotals")
182 xDialog
= self
.xUITest
.getTopFocusWindow()
183 # 4. Group by: "- none -"
184 xGroupBy
= xDialog
.getChild("group_by")
185 props
= {"TEXT": "- none -"}
186 actionProps
= mkPropertyValues(props
)
187 xGroupBy
.executeAction("SELECT", actionProps
)
188 # 5. Press "OK" and watch LibreOffice crash.
189 xOKBtn
= xDialog
.getChild("ok")
190 self
.ui_test
.close_dialog_through_button(xOKBtn
)
192 self
.assertEqual(get_cell_by_position(document
, 0, 0, 1).getValue(), 1)
193 self
.assertEqual(get_cell_by_position(document
, 0, 1, 1).getValue(), 2)
194 self
.ui_test
.close_doc()
196 # vim: set shiftwidth=4 softtabstop=4 expandtab: