Commit b1990237 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add autotests

parent 1a73af4a
Pipeline #122511 passed with stage
in 14 minutes and 32 seconds
......@@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause
macro(add_messageviewer_openwithurl_unittest _source)
get_filename_component(_name ${_source} NAME_WE)
ecm_add_test(${_source}
ecm_add_test(${_source} ${_name}.h
TEST_NAME ${_name}
NAME_PREFIX "messageviewer-"
LINK_LIBRARIES KF5::MessageViewer openurlwithconfigure Qt${QT_MAJOR_VERSION}::Test
......@@ -10,3 +10,4 @@ macro(add_messageviewer_openwithurl_unittest _source)
endmacro ()
add_messageviewer_openwithurl_unittest(openurlwithconfigurewidgettest.cpp)
add_messageviewer_openwithurl_unittest(openurlwithconfiguredialogtest.cpp)
/*
SPDX-FileCopyrightText: 2022 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "openurlwithconfiguredialogtest.h"
#include "openurlwithconfiguredialog.h"
#include "openurlwithconfigurewidget.h"
#include <QDialogButtonBox>
#include <QStandardPaths>
#include <QTest>
#include <QVBoxLayout>
QTEST_MAIN(OpenUrlWithConfigureDialogTest)
OpenUrlWithConfigureDialogTest::OpenUrlWithConfigureDialogTest(QObject *parent)
: QObject{parent}
{
QStandardPaths::setTestModeEnabled(true);
}
void OpenUrlWithConfigureDialogTest::shouldHaveDefaultValues()
{
OpenUrlWithConfigureDialog dlg;
QVERIFY(!dlg.windowTitle().isEmpty());
auto mainLayout = dlg.findChild<QVBoxLayout *>(QStringLiteral("mainlayout"));
QVERIFY(mainLayout);
auto mConfigureWidget = dlg.findChild<OpenUrlWithConfigureWidget *>(QStringLiteral("mOpenUrlWithWidget"));
QVERIFY(mConfigureWidget);
auto buttonBox = dlg.findChild<QDialogButtonBox *>(QStringLiteral("buttonBox"));
QVERIFY(buttonBox);
QCOMPARE(buttonBox->standardButtons(), {QDialogButtonBox::Ok | QDialogButtonBox::Cancel});
}
/*
SPDX-FileCopyrightText: 2022 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QObject>
class OpenUrlWithConfigureDialogTest : public QObject
{
Q_OBJECT
public:
explicit OpenUrlWithConfigureDialogTest(QObject *parent = nullptr);
~OpenUrlWithConfigureDialogTest() override = default;
private Q_SLOTS:
void shouldHaveDefaultValues();
};
......@@ -6,10 +6,17 @@
#include "openurlwithconfiguredialog.h"
#include "openurlwithconfigurewidget.h"
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
#include <QDialogButtonBox>
#include <QVBoxLayout>
namespace
{
static const char myOpenUrlWithConfigureConfigGroupName[] = "OpenUrlWithConfigureDialogbonjour ";
}
OpenUrlWithConfigureDialog::OpenUrlWithConfigureDialog(QWidget *parent)
: QDialog(parent)
, mOpenUrlWithWidget(new OpenUrlWithConfigureWidget(this))
......@@ -28,12 +35,31 @@ OpenUrlWithConfigureDialog::OpenUrlWithConfigureDialog(QWidget *parent)
connect(buttonBox, &QDialogButtonBox::accepted, this, &OpenUrlWithConfigureDialog::slotAccepted);
connect(buttonBox, &QDialogButtonBox::rejected, this, &OpenUrlWithConfigureDialog::reject);
// mConfigureWidget->loadSettings();
// readConfig();
readConfig();
}
OpenUrlWithConfigureDialog::~OpenUrlWithConfigureDialog() = default;
OpenUrlWithConfigureDialog::~OpenUrlWithConfigureDialog()
{
writeConfig();
}
void OpenUrlWithConfigureDialog::slotAccepted()
{
accept();
}
void OpenUrlWithConfigureDialog::readConfig()
{
KConfigGroup grp(KSharedConfig::openStateConfig(), myOpenUrlWithConfigureConfigGroupName);
const QSize size = grp.readEntry("Size", QSize(300, 200));
if (size.isValid()) {
resize(size);
}
}
void OpenUrlWithConfigureDialog::writeConfig()
{
KConfigGroup grp(KSharedConfig::openStateConfig(), myOpenUrlWithConfigureConfigGroupName);
grp.writeEntry("Size", size());
grp.sync();
}
......@@ -18,5 +18,7 @@ public:
private:
void slotAccepted();
void readConfig();
void writeConfig();
OpenUrlWithConfigureWidget *const mOpenUrlWithWidget;
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment