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 libreoffice
.uno
.propertyvalue
import mkPropertyValues
13 class dropDownFormFieldDialog(UITestCase
):
15 def test_add_new_items(self
):
17 # open a file with an empty form field
18 with self
.ui_test
.load_file(get_url_for_data_file("empty_drop_down_form_field.odt")):
20 # open the dialog (cursor is at the field)
21 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
23 itemEntry
= xDialog
.getChild("item_entry")
24 addButton
= xDialog
.getChild("add_button")
25 itemsList
= xDialog
.getChild("items_treeview")
28 self
.assertEqual(get_state_as_dict(itemEntry
)["Text"], "")
29 self
.assertEqual(get_state_as_dict(addButton
)["Enabled"], "false")
30 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "0")
33 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"1000"}))
34 self
.assertEqual(get_state_as_dict(addButton
)["Enabled"], "true")
35 addButton
.executeAction("CLICK", tuple())
36 self
.assertEqual(get_state_as_dict(addButton
)["Enabled"], "false")
37 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"2000"}))
38 addButton
.executeAction("CLICK", tuple())
39 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"3000"}))
40 addButton
.executeAction("CLICK", tuple())
41 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"4000"}))
42 addButton
.executeAction("CLICK", tuple())
44 # check whether the items are there in the list
45 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "4")
46 self
.assertEqual(get_state_as_dict(itemsList
.getChild("0"))["Text"], "1000")
47 self
.assertEqual(get_state_as_dict(itemsList
.getChild("1"))["Text"], "2000")
48 self
.assertEqual(get_state_as_dict(itemsList
.getChild("2"))["Text"], "3000")
49 self
.assertEqual(get_state_as_dict(itemsList
.getChild("3"))["Text"], "4000")
52 # check whether items are the same after reopening
53 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
55 itemsList
= xDialog
.getChild("items_treeview")
56 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "4")
57 self
.assertEqual(get_state_as_dict(itemsList
.getChild("0"))["Text"], "1000")
58 self
.assertEqual(get_state_as_dict(itemsList
.getChild("1"))["Text"], "2000")
59 self
.assertEqual(get_state_as_dict(itemsList
.getChild("2"))["Text"], "3000")
60 self
.assertEqual(get_state_as_dict(itemsList
.getChild("3"))["Text"], "4000")
63 def test_remove_items(self
):
65 # open a file with an empty form field
66 with self
.ui_test
.load_file(get_url_for_data_file("empty_drop_down_form_field.odt")):
68 # open the dialog (cursor is at the field)
69 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
71 itemEntry
= xDialog
.getChild("item_entry")
72 addButton
= xDialog
.getChild("add_button")
73 itemsList
= xDialog
.getChild("items_treeview")
74 removeButton
= xDialog
.getChild("remove_button")
77 self
.assertEqual(get_state_as_dict(itemEntry
)["Text"], "")
78 self
.assertEqual(get_state_as_dict(addButton
)["Enabled"], "false")
79 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "0")
80 self
.assertEqual(get_state_as_dict(removeButton
)["Enabled"], "false")
83 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"1000"}))
84 self
.assertEqual(get_state_as_dict(addButton
)["Enabled"], "true")
85 addButton
.executeAction("CLICK", tuple())
86 self
.assertEqual(get_state_as_dict(removeButton
)["Enabled"], "true")
87 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"2000"}))
88 addButton
.executeAction("CLICK", tuple())
89 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"3000"}))
90 addButton
.executeAction("CLICK", tuple())
91 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"4000"}))
92 addButton
.executeAction("CLICK", tuple())
94 # check whether the items are there in the list
95 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "4")
96 self
.assertEqual(get_state_as_dict(itemsList
.getChild("0"))["Text"], "1000")
97 self
.assertEqual(get_state_as_dict(itemsList
.getChild("1"))["Text"], "2000")
98 self
.assertEqual(get_state_as_dict(itemsList
.getChild("2"))["Text"], "3000")
99 self
.assertEqual(get_state_as_dict(itemsList
.getChild("3"))["Text"], "4000")
101 # select an item from the list and remove it
102 itemsList
.getChild("1").executeAction("SELECT", tuple())
103 removeButton
.executeAction("CLICK", tuple())
105 # check whether the right item was removed
106 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "3")
107 self
.assertEqual(get_state_as_dict(itemsList
.getChild("0"))["Text"], "1000")
108 self
.assertEqual(get_state_as_dict(itemsList
.getChild("1"))["Text"], "3000")
109 self
.assertEqual(get_state_as_dict(itemsList
.getChild("2"))["Text"], "4000")
112 # check whether items are the same after reopening
113 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
115 itemsList
= xDialog
.getChild("items_treeview")
116 removeButton
= xDialog
.getChild("remove_button")
117 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "3")
118 self
.assertEqual(get_state_as_dict(itemsList
.getChild("0"))["Text"], "1000")
119 self
.assertEqual(get_state_as_dict(itemsList
.getChild("1"))["Text"], "3000")
120 self
.assertEqual(get_state_as_dict(itemsList
.getChild("2"))["Text"], "4000")
123 itemsList
.getChild("1").executeAction("SELECT", tuple())
124 removeButton
.executeAction("CLICK", tuple())
125 removeButton
.executeAction("CLICK", tuple())
126 removeButton
.executeAction("CLICK", tuple())
128 self
.assertEqual(get_state_as_dict(removeButton
)["Enabled"], "false")
129 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "0")
132 def test_move_items(self
):
134 # open a file with an empty form field
135 with self
.ui_test
.load_file(get_url_for_data_file("empty_drop_down_form_field.odt")):
137 # open the dialog (cursor is at the field)
138 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
140 itemEntry
= xDialog
.getChild("item_entry")
141 addButton
= xDialog
.getChild("add_button")
142 itemsList
= xDialog
.getChild("items_treeview")
143 upButton
= xDialog
.getChild("up_button")
144 downButton
= xDialog
.getChild("down_button")
147 self
.assertEqual(get_state_as_dict(itemEntry
)["Text"], "")
148 self
.assertEqual(get_state_as_dict(addButton
)["Enabled"], "false")
149 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "0")
150 self
.assertEqual(get_state_as_dict(upButton
)["Enabled"], "false")
151 self
.assertEqual(get_state_as_dict(downButton
)["Enabled"], "false")
154 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"1000"}))
155 self
.assertEqual(get_state_as_dict(addButton
)["Enabled"], "true")
156 addButton
.executeAction("CLICK", tuple())
157 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"2000"}))
158 addButton
.executeAction("CLICK", tuple())
159 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"3000"}))
160 addButton
.executeAction("CLICK", tuple())
161 itemEntry
.executeAction("TYPE", mkPropertyValues({"TEXT":"4000"}))
162 addButton
.executeAction("CLICK", tuple())
164 # check whether the items are there in the list
165 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "4")
166 self
.assertEqual(get_state_as_dict(itemsList
.getChild("0"))["Text"], "1000")
167 self
.assertEqual(get_state_as_dict(itemsList
.getChild("1"))["Text"], "2000")
168 self
.assertEqual(get_state_as_dict(itemsList
.getChild("2"))["Text"], "3000")
169 self
.assertEqual(get_state_as_dict(itemsList
.getChild("3"))["Text"], "4000")
171 # select an item from the list and move it up
172 itemsList
.getChild("1").executeAction("SELECT", tuple())
173 self
.assertEqual(get_state_as_dict(upButton
)["Enabled"], "true")
174 self
.assertEqual(get_state_as_dict(downButton
)["Enabled"], "true")
175 upButton
.executeAction("CLICK", tuple())
176 self
.assertEqual(get_state_as_dict(upButton
)["Enabled"], "false")
177 self
.assertEqual(get_state_as_dict(downButton
)["Enabled"], "true")
179 # check whether the item was correctly moved
180 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "4")
181 self
.assertEqual(get_state_as_dict(itemsList
.getChild("0"))["Text"], "2000")
182 self
.assertEqual(get_state_as_dict(itemsList
.getChild("1"))["Text"], "1000")
183 self
.assertEqual(get_state_as_dict(itemsList
.getChild("2"))["Text"], "3000")
184 self
.assertEqual(get_state_as_dict(itemsList
.getChild("3"))["Text"], "4000")
186 # move down the selected item
187 downButton
.executeAction("CLICK", tuple())
188 downButton
.executeAction("CLICK", tuple())
189 downButton
.executeAction("CLICK", tuple())
190 self
.assertEqual(get_state_as_dict(upButton
)["Enabled"], "true")
191 self
.assertEqual(get_state_as_dict(downButton
)["Enabled"], "false")
193 # check whether the item was correctly moved
194 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "4")
195 self
.assertEqual(get_state_as_dict(itemsList
.getChild("0"))["Text"], "1000")
196 self
.assertEqual(get_state_as_dict(itemsList
.getChild("1"))["Text"], "3000")
197 self
.assertEqual(get_state_as_dict(itemsList
.getChild("2"))["Text"], "4000")
198 self
.assertEqual(get_state_as_dict(itemsList
.getChild("3"))["Text"], "2000")
201 # check whether items are the same after reopening
202 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
204 itemsList
= xDialog
.getChild("items_treeview")
205 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "4")
206 self
.assertEqual(get_state_as_dict(itemsList
.getChild("0"))["Text"], "1000")
207 self
.assertEqual(get_state_as_dict(itemsList
.getChild("1"))["Text"], "3000")
208 self
.assertEqual(get_state_as_dict(itemsList
.getChild("2"))["Text"], "4000")
209 self
.assertEqual(get_state_as_dict(itemsList
.getChild("3"))["Text"], "2000")
212 def test_drop_down_after_import(self
):
214 files
= ["drop_down_form_field.odt", "drop_down_form_field.doc", "drop_down_form_field.docx"]
216 # open a file with a drop-down for field with items and selection
217 with self
.ui_test
.load_file(get_url_for_data_file(file)):
219 # open the dialog (cursor is at the field)
220 with self
.ui_test
.execute_dialog_through_command(".uno:ControlProperties") as xDialog
:
222 itemsList
= xDialog
.getChild("items_treeview")
224 # check whether the items are there in the list
225 self
.assertEqual(get_state_as_dict(itemsList
)["Children"], "4")
226 self
.assertEqual(get_state_as_dict(itemsList
.getChild("0"))["Text"], "1000")
227 self
.assertEqual(get_state_as_dict(itemsList
.getChild("1"))["Text"], "2000")
228 self
.assertEqual(get_state_as_dict(itemsList
.getChild("2"))["Text"], "3000")
229 self
.assertEqual(get_state_as_dict(itemsList
.getChild("3"))["Text"], "4000")
231 self
.assertEqual(get_state_as_dict(itemsList
)["SelectEntryText"], "3000")
234 # vim: set shiftwidth=4 softtabstop=4 expandtab: