sw/qa/uitest/writer_tests/tdf145062.py |   63 +++++++++++++++++++++++++++++++++
 sw/source/ui/fldui/flddb.cxx           |    3 +
 sw/source/ui/fldui/flddinf.cxx         |    3 +
 sw/source/ui/fldui/flddok.cxx          |    3 +
 sw/source/ui/fldui/fldfunc.cxx         |    3 +
 sw/source/ui/fldui/fldref.cxx          |    3 +
 sw/source/ui/fldui/fldvar.cxx          |    3 +
 7 files changed, 81 insertions(+)

New commits:
commit deea3b7471c3dab0220eca6146c225a2d47681a2
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Wed Dec 15 16:50:26 2021 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Dec 16 00:30:44 2021 +0100

    tdf#145062: sw: Add UItest
    
    the different tabs in the insert field dialog share the same 'type' id,
    so create a unique one for each tab
    
    Change-Id: I14013f17aa00b73ae5a7ade8c2f12f01a37d13b7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126889
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/uitest/writer_tests/tdf145062.py 
b/sw/qa/uitest/writer_tests/tdf145062.py
new file mode 100644
index 000000000000..09bcec80fd7d
--- /dev/null
+++ b/sw/qa/uitest/writer_tests/tdf145062.py
@@ -0,0 +1,63 @@
+# -*- 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 libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper.common import get_state_as_dict
+from uitest.uihelper.common import select_pos
+
+class Tdf145062(UITestCase):
+
+    def test_tdf145062(self):
+
+        with self.ui_test.create_doc_in_start_center("writer") as writer_doc:
+
+            with 
self.ui_test.execute_modeless_dialog_through_command(".uno:InsertField", 
close_button="") as xDialog:
+                xTab = xDialog.getChild("tabcontrol")
+                select_pos(xTab, "2")
+
+                xType = xDialog.getChild("type-func")
+                xType.getChild('2').executeAction("SELECT", tuple())
+                self.assertEqual("Input field", 
get_state_as_dict(xType)['SelectEntryText'])
+
+                xOkBtn = xDialog.getChild("ok")
+                with 
self.ui_test.execute_blocking_action(xOkBtn.executeAction, args=('CLICK', ())) 
as xFieldDialog:
+                    xText = xFieldDialog.getChild("text")
+                    xText.executeAction("TYPE", mkPropertyValues({"TEXT": 
"AAA"}))
+
+                # move cursor to the middle of the field
+                self.xUITest.executeCommand(".uno:GoLeft")
+                self.xUITest.executeCommand(".uno:GoLeft")
+
+                xType.getChild('6').executeAction("SELECT", tuple())
+                self.assertEqual("Hidden text", 
get_state_as_dict(xType)['SelectEntryText'])
+
+                # try to insert a hidden text a few times
+                # Without the fix in place, this test would have crashed here
+                for i in range(10):
+                    xOkBtn.executeAction("CLICK", ())
+
+                # close_dialog_through_button should be used here but it hangs 
and
+                # the reason seems to be that interacting with the document 
while
+                # the dialog is open doesn't play well together in the uitests
+                # As a workaround, leave the dialog open, close the document,
+                # open a new one and then, close the dialog.
+                # If the dialog is not closed, it will be displayed in other 
tests
+
+            textfields = writer_doc.getTextFields()
+            textfield = textfields.createEnumeration().nextElement()
+            
self.assertTrue(textfield.supportsService("com.sun.star.text.TextField.Input"))
+            self.assertEqual('AAA', textfield.Content)
+
+        with self.ui_test.load_empty_file("writer"):
+            xDialog = self.xUITest.getTopFocusWindow()
+            xCancelBtn = xDialog.getChild("cancel")
+            self.ui_test.close_dialog_through_button(xCancelBtn)
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/ui/fldui/flddb.cxx b/sw/source/ui/fldui/flddb.cxx
index 3764a5145d85..5bc1c8d77645 100644
--- a/sw/source/ui/fldui/flddb.cxx
+++ b/sw/source/ui/fldui/flddb.cxx
@@ -62,6 +62,9 @@ SwFieldDBPage::SwFieldDBPage(weld::Container* pPage, 
weld::DialogController* pCo
 
     m_xValueED->connect_changed(LINK(this, SwFieldDBPage, ModifyHdl));
     m_xAddDBPB->connect_clicked(LINK(this, SwFieldDBPage, AddDBHdl));
+
+    // uitests
+    m_xTypeLB->set_buildable_name(m_xTypeLB->get_buildable_name() + "-db");
 }
 
 SwFieldDBPage::~SwFieldDBPage()
diff --git a/sw/source/ui/fldui/flddinf.cxx b/sw/source/ui/fldui/flddinf.cxx
index eb00d587fffd..aa5536d3eff8 100644
--- a/sw/source/ui/fldui/flddinf.cxx
+++ b/sw/source/ui/fldui/flddinf.cxx
@@ -77,6 +77,9 @@ SwFieldDokInfPage::SwFieldDokInfPage(weld::Container* pPage, 
weld::DialogControl
         : nullptr;
     if ( pItem )
         pItem->GetValue() >>= xCustomPropertySet;
+
+    // uitests
+    m_xTypeTLB->set_buildable_name(m_xTypeTLB->get_buildable_name() + 
"-docinf");
 }
 
 SwFieldDokInfPage::~SwFieldDokInfPage()
diff --git a/sw/source/ui/fldui/flddok.cxx b/sw/source/ui/fldui/flddok.cxx
index fba96e93cb4a..b977568c71cd 100644
--- a/sw/source/ui/fldui/flddok.cxx
+++ b/sw/source/ui/fldui/flddok.cxx
@@ -68,6 +68,9 @@ SwFieldDokPage::SwFieldDokPage(weld::Container* pPage, 
weld::DialogController* p
     m_xDateOffsetED->set_range(INT_MIN, INT_MAX);
     //enable 'active' language selection
     m_xNumFormatLB->SetShowLanguageControl(true);
+
+    // uitests
+    m_xTypeLB->set_buildable_name(m_xTypeLB->get_buildable_name() + "-doc");
 }
 
 SwFieldDokPage::~SwFieldDokPage()
diff --git a/sw/source/ui/fldui/fldfunc.cxx b/sw/source/ui/fldui/fldfunc.cxx
index 9679691a6323..346327d1e026 100644
--- a/sw/source/ui/fldui/fldfunc.cxx
+++ b/sw/source/ui/fldui/fldfunc.cxx
@@ -79,6 +79,9 @@ SwFieldFuncPage::SwFieldFuncPage(weld::Container* pPage, 
weld::DialogController*
 
     m_xCond1ED->ShowBrackets(false);
     m_xCond2ED->ShowBrackets(false);
+
+    // uitests
+    m_xTypeLB->set_buildable_name(m_xTypeLB->get_buildable_name() + "-func");
 }
 
 SwFieldFuncPage::~SwFieldFuncPage()
diff --git a/sw/source/ui/fldui/fldref.cxx b/sw/source/ui/fldui/fldref.cxx
index 7eb82c575bc4..0c9b10eae16b 100644
--- a/sw/source/ui/fldui/fldref.cxx
+++ b/sw/source/ui/fldui/fldref.cxx
@@ -102,6 +102,9 @@ SwFieldRefPage::SwFieldRefPage(weld::Container* pPage, 
weld::DialogController* p
     m_xSelectionToolTipLB->connect_changed( LINK(this, SwFieldRefPage, 
SubTypeTreeListBoxHdl) );
     m_xSelectionToolTipLB->connect_row_activated( LINK(this, SwFieldRefPage, 
TreeViewInsertHdl) );
     m_xFilterED->grab_focus();
+
+    // uitests
+    m_xTypeLB->set_buildable_name(m_xTypeLB->get_buildable_name() + "-ref");
 }
 
 SwFieldRefPage::~SwFieldRefPage()
diff --git a/sw/source/ui/fldui/fldvar.cxx b/sw/source/ui/fldui/fldvar.cxx
index bc3078ceb574..b07f3d117837 100644
--- a/sw/source/ui/fldui/fldvar.cxx
+++ b/sw/source/ui/fldui/fldvar.cxx
@@ -79,6 +79,9 @@ SwFieldVarPage::SwFieldVarPage(weld::Container* pPage, 
weld::DialogController* p
     m_xChapterLevelLB->set_active(0);
     //enable 'active' language selection
     m_xNumFormatLB->SetShowLanguageControl(true);
+
+    // uitests
+    m_xTypeLB->set_buildable_name(m_xTypeLB->get_buildable_name() + "-var");
 }
 
 SwFieldVarPage::~SwFieldVarPage()

Reply via email to