summaryrefslogtreecommitdiffstats
path: root/sw/qa/uitest/writer_tests5/DropDownFormFieldPropertiesDialog.py
blob: e64e32b02b3c974ba4282e6f0051434a121bb5e5 (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
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# 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, get_url_for_data_file
from libreoffice.uno.propertyvalue import mkPropertyValues

class dropDownFormFieldDialog(UITestCase):

    def test_add_new_items(self):

        # open a file with an empty form field
        with self.ui_test.load_file(get_url_for_data_file("empty_drop_down_form_field.odt")) as writer_doc:
            xWriterDoc = self.xUITest.getTopFocusWindow()

            # open the dialog (cursor is at the field)
            with self.ui_test.execute_dialog_through_command(".uno:ControlProperties") as xDialog:

                itemEntry = xDialog.getChild("item_entry")
                addButton = xDialog.getChild("add_button")
                itemsList = xDialog.getChild("items_treeview")

                # initial state
                self.assertEqual(get_state_as_dict(itemEntry)["Text"], "")
                self.assertEqual(get_state_as_dict(addButton)["Enabled"], "false")
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "0")

                # add some new items
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"1000"}))
                self.assertEqual(get_state_as_dict(addButton)["Enabled"], "true")
                addButton.executeAction("CLICK", tuple())
                self.assertEqual(get_state_as_dict(addButton)["Enabled"], "false")
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"2000"}))
                addButton.executeAction("CLICK", tuple())
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"3000"}))
                addButton.executeAction("CLICK", tuple())
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"4000"}))
                addButton.executeAction("CLICK", tuple())

                # check whether the items are there in the list
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
                self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "2000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")


            # check whether items are the same after reopening
            with self.ui_test.execute_dialog_through_command(".uno:ControlProperties") as xDialog:

                itemsList = xDialog.getChild("items_treeview")
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
                self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "2000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")


    def test_remove_items(self):

        # open a file with an empty form field
        with self.ui_test.load_file(get_url_for_data_file("empty_drop_down_form_field.odt")) as writer_doc:
            xWriterDoc = self.xUITest.getTopFocusWindow()

            # open the dialog (cursor is at the field)
            with self.ui_test.execute_dialog_through_command(".uno:ControlProperties") as xDialog:

                itemEntry = xDialog.getChild("item_entry")
                addButton = xDialog.getChild("add_button")
                itemsList = xDialog.getChild("items_treeview")
                removeButton = xDialog.getChild("remove_button")

                # initial state
                self.assertEqual(get_state_as_dict(itemEntry)["Text"], "")
                self.assertEqual(get_state_as_dict(addButton)["Enabled"], "false")
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "0")
                self.assertEqual(get_state_as_dict(removeButton)["Enabled"], "false")

                # add some new items
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"1000"}))
                self.assertEqual(get_state_as_dict(addButton)["Enabled"], "true")
                addButton.executeAction("CLICK", tuple())
                self.assertEqual(get_state_as_dict(removeButton)["Enabled"], "true")
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"2000"}))
                addButton.executeAction("CLICK", tuple())
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"3000"}))
                addButton.executeAction("CLICK", tuple())
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"4000"}))
                addButton.executeAction("CLICK", tuple())

                # check whether the items are there in the list
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
                self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "2000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")

                # select an item from the list and remove it
                itemsList.getChild("1").executeAction("SELECT", tuple());
                removeButton.executeAction("CLICK", tuple())

                # check whether the right item was removed
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "3")
                self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "3000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "4000")


            # check whether items are the same after reopening
            with self.ui_test.execute_dialog_through_command(".uno:ControlProperties") as xDialog:

                itemsList = xDialog.getChild("items_treeview")
                removeButton = xDialog.getChild("remove_button")
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "3")
                self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "3000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "4000")

                # remove all items
                itemsList.getChild("1").executeAction("SELECT", tuple());
                removeButton.executeAction("CLICK", tuple())
                removeButton.executeAction("CLICK", tuple())
                removeButton.executeAction("CLICK", tuple())

                self.assertEqual(get_state_as_dict(removeButton)["Enabled"], "false")
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "0")


    def test_move_items(self):

        # open a file with an empty form field
        with self.ui_test.load_file(get_url_for_data_file("empty_drop_down_form_field.odt")) as writer_doc:
            xWriterDoc = self.xUITest.getTopFocusWindow()

            # open the dialog (cursor is at the field)
            with self.ui_test.execute_dialog_through_command(".uno:ControlProperties") as xDialog:

                itemEntry = xDialog.getChild("item_entry")
                addButton = xDialog.getChild("add_button")
                itemsList = xDialog.getChild("items_treeview")
                upButton = xDialog.getChild("up_button")
                downButton = xDialog.getChild("down_button")

                # initial state
                self.assertEqual(get_state_as_dict(itemEntry)["Text"], "")
                self.assertEqual(get_state_as_dict(addButton)["Enabled"], "false")
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "0")
                self.assertEqual(get_state_as_dict(upButton)["Enabled"], "false")
                self.assertEqual(get_state_as_dict(downButton)["Enabled"], "false")

                # add some new items
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"1000"}))
                self.assertEqual(get_state_as_dict(addButton)["Enabled"], "true")
                addButton.executeAction("CLICK", tuple())
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"2000"}))
                addButton.executeAction("CLICK", tuple())
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"3000"}))
                addButton.executeAction("CLICK", tuple())
                itemEntry.executeAction("TYPE", mkPropertyValues({"TEXT":"4000"}))
                addButton.executeAction("CLICK", tuple())

                # check whether the items are there in the list
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
                self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "2000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")

                # select an item from the list and move it up
                itemsList.getChild("1").executeAction("SELECT", tuple())
                self.assertEqual(get_state_as_dict(upButton)["Enabled"], "true")
                self.assertEqual(get_state_as_dict(downButton)["Enabled"], "true")
                upButton.executeAction("CLICK", tuple())
                self.assertEqual(get_state_as_dict(upButton)["Enabled"], "false")
                self.assertEqual(get_state_as_dict(downButton)["Enabled"], "true")

                # check whether the item was correctly moved
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
                self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "2000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "1000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")

                # move down the selected item
                downButton.executeAction("CLICK", tuple())
                downButton.executeAction("CLICK", tuple())
                downButton.executeAction("CLICK", tuple())
                self.assertEqual(get_state_as_dict(upButton)["Enabled"], "true")
                self.assertEqual(get_state_as_dict(downButton)["Enabled"], "false")

                # check whether the item was correctly moved
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
                self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "3000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "4000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "2000")


            # check whether items are the same after reopening
            with self.ui_test.execute_dialog_through_command(".uno:ControlProperties") as xDialog:

                itemsList = xDialog.getChild("items_treeview")
                self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
                self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "3000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "4000")
                self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "2000")


    def test_drop_down_after_import(self):

        files = ["drop_down_form_field.odt", "drop_down_form_field.doc", "drop_down_form_field.docx"]
        for file in files:
            # open a file with a drop-down for field with items and selection
            with self.ui_test.load_file(get_url_for_data_file(file)) as writer_doc:
                xWriterDoc = self.xUITest.getTopFocusWindow()

                # open the dialog (cursor is at the field)
                with self.ui_test.execute_dialog_through_command(".uno:ControlProperties") as xDialog:

                    itemsList = xDialog.getChild("items_treeview")

                    # check whether the items are there in the list
                    self.assertEqual(get_state_as_dict(itemsList)["Children"], "4")
                    self.assertEqual(get_state_as_dict(itemsList.getChild("0"))["Text"], "1000")
                    self.assertEqual(get_state_as_dict(itemsList.getChild("1"))["Text"], "2000")
                    self.assertEqual(get_state_as_dict(itemsList.getChild("2"))["Text"], "3000")
                    self.assertEqual(get_state_as_dict(itemsList.getChild("3"))["Text"], "4000")

                    self.assertEqual(get_state_as_dict(itemsList)["SelectEntryText"], "3000")


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