tdf#170399: sw: Add UItest (Add UI wrapper for TemplateDlgLocalView)
Change-Id: I3b7fd93f8ae3533e2c5ca1acde6b79d091113ad6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197757 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> Tested-by: Jenkins
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
|
||||
class TemplateDlgLocalView final : public TemplateLocalView, public ListView
|
||||
{
|
||||
friend class TemplateDlgLocalViewUIObject;
|
||||
|
||||
public:
|
||||
TemplateDlgLocalView(std::unique_ptr<weld::ScrolledWindow> xWindow,
|
||||
std::unique_ptr<weld::Menu> xMenu,
|
||||
@@ -50,6 +52,8 @@ public:
|
||||
void insertItems(const std::vector<TemplateItemProperties>& rTemplates, bool isRegionSelected,
|
||||
bool bShowCategoryInTooltip);
|
||||
|
||||
virtual FactoryFunction GetUITestFactory() const override;
|
||||
|
||||
private:
|
||||
void ContextMenuSelectHdl(std::u16string_view rIdent);
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/.
|
||||
*/
|
||||
|
||||
#include <vcl/uitest/uiobject.hxx>
|
||||
#include <sfx2/templatedlg.hxx>
|
||||
|
||||
class TemplateDlgLocalViewUIObject : public DrawingAreaUIObject
|
||||
{
|
||||
TemplateDlgLocalView* mpTemplateDlgLocalView;
|
||||
|
||||
virtual OUString get_name() const override;
|
||||
|
||||
public:
|
||||
TemplateDlgLocalViewUIObject(vcl::Window* rTemplateDlgLocalView);
|
||||
|
||||
virtual void execute(const OUString& rAction, const StringMap& rParameters) override;
|
||||
virtual StringMap get_state() override;
|
||||
|
||||
static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
|
||||
};
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -167,6 +167,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
|
||||
sfx2/source/control/thumbnailview \
|
||||
sfx2/source/control/charmapcontainer \
|
||||
sfx2/source/control/charmapcontrol \
|
||||
sfx2/source/control/uiobject \
|
||||
sfx2/source/control/unoctitm \
|
||||
sfx2/source/devtools/DevelopmentToolChildWindow \
|
||||
sfx2/source/devtools/DevelopmentToolDockingWindow \
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <inputdlg.hxx>
|
||||
#include <templateviewitem.hxx>
|
||||
#include <sfx2/sfxresid.hxx>
|
||||
#include <sfx2/uiobject.hxx>
|
||||
#include <templatecontaineritem.hxx>
|
||||
#include <sfx2/strings.hrc>
|
||||
#include <vcl/commandevent.hxx>
|
||||
@@ -426,4 +427,10 @@ IMPL_LINK(TemplateDlgLocalView, KeyPressHdl, const KeyEvent&, rKEvt, bool)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FactoryFunction TemplateDlgLocalView::GetUITestFactory() const
|
||||
{
|
||||
return TemplateDlgLocalViewUIObject::create;
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/.
|
||||
*/
|
||||
|
||||
#include <sfx2/uiobject.hxx>
|
||||
#include <templateviewitem.hxx>
|
||||
|
||||
TemplateDlgLocalViewUIObject::TemplateDlgLocalViewUIObject(vcl::Window* rTemplateDlgLocalView)
|
||||
: DrawingAreaUIObject(rTemplateDlgLocalView)
|
||||
, mpTemplateDlgLocalView(static_cast<TemplateDlgLocalView*>(mpController))
|
||||
{
|
||||
}
|
||||
|
||||
StringMap TemplateDlgLocalViewUIObject::get_state()
|
||||
{
|
||||
StringMap aMap = WindowUIObject::get_state();
|
||||
aMap[u"SelectedIndex"_ustr] = OUString::number(mpTemplateDlgLocalView->get_selected_index());
|
||||
if (TemplateViewItem* pSelectedItem = mpTemplateDlgLocalView->mpSelectedItem)
|
||||
{
|
||||
aMap[u"SelectedItemTitle"_ustr] = pSelectedItem->getTitle();
|
||||
}
|
||||
|
||||
return aMap;
|
||||
}
|
||||
|
||||
void TemplateDlgLocalViewUIObject::execute(const OUString& rAction, const StringMap& rParameters)
|
||||
{
|
||||
if (rAction == "EDIT" || rAction == "RENAME" || rAction == "DELETE" || rAction == "DEFAULT"
|
||||
|| rAction == "MOVE" || rAction == "EXPORT")
|
||||
{
|
||||
if (mpTemplateDlgLocalView->mpSelectedItem)
|
||||
{
|
||||
mpTemplateDlgLocalView->ContextMenuSelectHdl(rAction.toAsciiLowerCase());
|
||||
}
|
||||
}
|
||||
else if (rAction == "SELECT")
|
||||
{
|
||||
if (rParameters.find(u"POS"_ustr) != rParameters.end())
|
||||
{
|
||||
auto itr = rParameters.find(u"POS"_ustr);
|
||||
sal_uInt32 nPos = itr->second.toUInt32();
|
||||
mpTemplateDlgLocalView->set_cursor(nPos);
|
||||
mpTemplateDlgLocalView->updateSelection();
|
||||
}
|
||||
}
|
||||
else
|
||||
WindowUIObject::execute(rAction, rParameters);
|
||||
}
|
||||
|
||||
std::unique_ptr<UIObject> TemplateDlgLocalViewUIObject::create(vcl::Window* pWindow)
|
||||
{
|
||||
return std::unique_ptr<UIObject>(new TemplateDlgLocalViewUIObject(pWindow));
|
||||
}
|
||||
|
||||
OUString TemplateDlgLocalViewUIObject::get_name() const
|
||||
{
|
||||
return u"TemplateDlgLocalViewUIObject"_ustr;
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -0,0 +1,40 @@
|
||||
# -*- 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
|
||||
from libreoffice.uno.propertyvalue import mkPropertyValues
|
||||
|
||||
class ManageTemplates(UITestCase):
|
||||
|
||||
def test_EditTemplate(self):
|
||||
|
||||
try:
|
||||
# Open "Manage Templates" dialog from the start center
|
||||
with self.ui_test.execute_dialog_through_command(".uno:NewDoc", close_button="") as xDialog:
|
||||
xTemplateView = xDialog.getChild("template_view")
|
||||
xTemplateView.executeAction("SELECT", mkPropertyValues({"POS": "1"}))
|
||||
print(get_state_as_dict(xTemplateView))
|
||||
self.assertEqual("1", get_state_as_dict(xTemplateView)["SelectedIndex"])
|
||||
self.assertTrue(get_state_as_dict(xTemplateView)["SelectedItemTitle"].startswith("Modern business letter"))
|
||||
|
||||
# tdf#170399: Without the fix in place, this test would have crashed here
|
||||
xTemplateView.executeAction("EDIT", tuple())
|
||||
except:
|
||||
# if it fails, close the dialog before disposing
|
||||
xTemplateDlg = self.xUITest.getTopFocusWindow()
|
||||
xCancelBtn = xTemplateDlg.getChild("close")
|
||||
self.ui_test.close_dialog_through_button(xCancelBtn)
|
||||
raise
|
||||
|
||||
document = self.ui_test.get_component()
|
||||
self.assertTrue(document.Title.startswith("Modern_business_letter"))
|
||||
self.ui_test.close_doc()
|
||||
|
||||
# vim: set shiftwidth=4 softtabstop=4 expandtab:
|
||||
Reference in New Issue
Block a user