[Libreoffice-commits] core.git: sw/qa sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sun Mar 10 15:44:01 UTC 2019


 sw/qa/uitest/writer_tests/data/drop_down_form_field.doc         |binary
 sw/qa/uitest/writer_tests/data/drop_down_form_field.docx        |binary
 sw/qa/uitest/writer_tests/data/drop_down_form_field.odt         |binary
 sw/qa/uitest/writer_tests/data/empty_drop_down_form_field.odt   |binary
 sw/qa/uitest/writer_tests5/DropDownFormFieldPropertiesDialog.py |  266 ++++++++++
 sw/source/ui/fldui/DropDownFormFieldDialog.cxx                  |    8 
 sw/source/uibase/inc/DropDownFormFieldDialog.hxx                |    2 
 7 files changed, 269 insertions(+), 7 deletions(-)

New commits:
commit d18b9b977a33a8f75a3d8beab82f469e93c3071a
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Sun Mar 10 12:49:21 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Sun Mar 10 16:43:37 2019 +0100

    MSForms: UITest for drop-down form field's propertis dialog
    
    Also changed the dialog's code a bit to work correctly with
    the UI test too.
    
    Change-Id: Idec85746f5ada979518d1fb0e09dc1c8e22ba7c1
    Reviewed-on: https://gerrit.libreoffice.org/68967
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/sw/qa/uitest/writer_tests/data/drop_down_form_field.doc b/sw/qa/uitest/writer_tests/data/drop_down_form_field.doc
new file mode 100644
index 000000000000..cf94a1fdada1
Binary files /dev/null and b/sw/qa/uitest/writer_tests/data/drop_down_form_field.doc differ
diff --git a/sw/qa/uitest/writer_tests/data/drop_down_form_field.docx b/sw/qa/uitest/writer_tests/data/drop_down_form_field.docx
new file mode 100644
index 000000000000..d039cd2b60d3
Binary files /dev/null and b/sw/qa/uitest/writer_tests/data/drop_down_form_field.docx differ
diff --git a/sw/qa/uitest/writer_tests/data/drop_down_form_field.odt b/sw/qa/uitest/writer_tests/data/drop_down_form_field.odt
new file mode 100644
index 000000000000..f27b1157418c
Binary files /dev/null and b/sw/qa/uitest/writer_tests/data/drop_down_form_field.odt differ
diff --git a/sw/qa/uitest/writer_tests/data/empty_drop_down_form_field.odt b/sw/qa/uitest/writer_tests/data/empty_drop_down_form_field.odt
new file mode 100644
index 000000000000..bd85dc2a902d
Binary files /dev/null and b/sw/qa/uitest/writer_tests/data/empty_drop_down_form_field.odt differ
diff --git a/sw/qa/uitest/writer_tests5/DropDownFormFieldPropertiesDialog.py b/sw/qa/uitest/writer_tests5/DropDownFormFieldPropertiesDialog.py
new file mode 100644
index 000000000000..5628e83992e1
--- /dev/null
+++ b/sw/qa/uitest/writer_tests5/DropDownFormFieldPropertiesDialog.py
@@ -0,0 +1,266 @@
+# -*- 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 libreoffice.uno.propertyvalue import mkPropertyValues
+import org.libreoffice.unotest
+import pathlib
+import time
+
+def get_url_for_data_file(file_name):
+    return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
+
+class dropDownFormFieldDialog(UITestCase):
+
+    def test_add_new_items(self):
+
+        # open a file with an empty form field
+        writer_doc = self.ui_test.load_file(get_url_for_data_file("empty_drop_down_form_field.odt"))
+        document = self.ui_test.get_component()
+        xWriterDoc = self.xUITest.getTopFocusWindow()
+
+        # open the dialog (cursor is at the field)
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        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")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        # check whether items are the same after reopening
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        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")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        self.ui_test.close_doc()
+
+    def test_remove_items(self):
+
+        # open a file with an empty form field
+        writer_doc = self.ui_test.load_file(get_url_for_data_file("empty_drop_down_form_field.odt"))
+        document = self.ui_test.get_component()
+        xWriterDoc = self.xUITest.getTopFocusWindow()
+
+        # open the dialog (cursor is at the field)
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        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")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        # check whether items are the same after reopening
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        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")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        self.ui_test.close_doc()
+
+    def test_move_items(self):
+
+        # open a file with an empty form field
+        writer_doc = self.ui_test.load_file(get_url_for_data_file("empty_drop_down_form_field.odt"))
+        document = self.ui_test.get_component()
+        xWriterDoc = self.xUITest.getTopFocusWindow()
+
+        # open the dialog (cursor is at the field)
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        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")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        # check whether items are the same after reopening
+        self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+        xDialog = self.xUITest.getTopFocusWindow()
+
+        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")
+
+        xOKBtn = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOKBtn)
+
+        self.ui_test.close_doc()
+
+    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
+            writer_doc = self.ui_test.load_file(get_url_for_data_file(file))
+            document = self.ui_test.get_component()
+            xWriterDoc = self.xUITest.getTopFocusWindow()
+
+            # open the dialog (cursor is at the field)
+            self.ui_test.execute_dialog_through_command(".uno:ControlProperties")
+            xDialog = self.xUITest.getTopFocusWindow()
+
+            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")
+
+            xOKBtn = xDialog.getChild("ok")
+            self.ui_test.close_dialog_through_button(xOKBtn)
+
+            self.ui_test.close_doc()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/ui/fldui/DropDownFormFieldDialog.cxx b/sw/source/ui/fldui/DropDownFormFieldDialog.cxx
index dd187704aa7a..4b6c848feefb 100644
--- a/sw/source/ui/fldui/DropDownFormFieldDialog.cxx
+++ b/sw/source/ui/fldui/DropDownFormFieldDialog.cxx
@@ -28,7 +28,7 @@ DropDownFormFieldDialog::DropDownFormFieldDialog(weld::Window* pParent,
     , m_xListDownButton(m_xBuilder->weld_button("down_button"))
 {
     m_xListItemEntry->connect_key_press(LINK(this, DropDownFormFieldDialog, KeyPressedHdl));
-    m_xListItemEntry->connect_key_release(LINK(this, DropDownFormFieldDialog, KeyReleasedHdl));
+    m_xListItemEntry->connect_changed(LINK(this, DropDownFormFieldDialog, EntryChangedHdl));
 
     m_xListItemsTreeView->set_size_request(m_xListItemEntry->get_preferred_size().Width(),
                                            m_xListItemEntry->get_preferred_size().Height() * 5);
@@ -57,11 +57,7 @@ IMPL_LINK(DropDownFormFieldDialog, KeyPressedHdl, const KeyEvent&, rEvent, bool)
     return false;
 }
 
-IMPL_LINK_NOARG(DropDownFormFieldDialog, KeyReleasedHdl, const KeyEvent&, bool)
-{
-    UpdateButtons();
-    return false;
-}
+IMPL_LINK_NOARG(DropDownFormFieldDialog, EntryChangedHdl, weld::Entry&, void) { UpdateButtons(); }
 
 IMPL_LINK(DropDownFormFieldDialog, ButtonPushedHdl, weld::Button&, rButton, void)
 {
diff --git a/sw/source/uibase/inc/DropDownFormFieldDialog.hxx b/sw/source/uibase/inc/DropDownFormFieldDialog.hxx
index 3fbb59db0ebc..aee5c5232845 100644
--- a/sw/source/uibase/inc/DropDownFormFieldDialog.hxx
+++ b/sw/source/uibase/inc/DropDownFormFieldDialog.hxx
@@ -41,7 +41,7 @@ private:
 
     DECL_LINK(ListChangedHdl, weld::TreeView&, void);
     DECL_LINK(KeyPressedHdl, const KeyEvent&, bool);
-    DECL_LINK(KeyReleasedHdl, const KeyEvent&, bool);
+    DECL_LINK(EntryChangedHdl, weld::Entry&, void);
     DECL_LINK(ButtonPushedHdl, weld::Button&, void);
 
     void InitControls();


More information about the Libreoffice-commits mailing list