Commit 01ced26f authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add autotest + make sure that ok button is disabled

parent b73a20ad
Pipeline #70055 passed with stage
in 41 minutes and 6 seconds
......@@ -12,3 +12,4 @@ add_kmail_checkbeforedeleting_unittest(confirmbeforedeletingdialogtest.cpp)
add_kmail_checkbeforedeleting_unittest(confirmbeforedeletingwidgettest.cpp)
add_kmail_checkbeforedeleting_unittest(confirmbeforedeletingruletest.cpp)
add_kmail_checkbeforedeleting_unittest(confirmbeforedeletingcreaterulewidgettest.cpp)
add_kmail_checkbeforedeleting_unittest(confirmbeforedeletingcreateruledialogtest.cpp)
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "confirmbeforedeletingcreateruledialogtest.h"
#include "confirmbeforedeletingcreateruledialog.h"
#include "confirmbeforedeletingcreaterulewidget.h"
#include <QDialogButtonBox>
#include <QPushButton>
#include <QTest>
#include <QVBoxLayout>
QTEST_MAIN(ConfirmBeforeDeletingCreateRuleDialogTest)
ConfirmBeforeDeletingCreateRuleDialogTest::ConfirmBeforeDeletingCreateRuleDialogTest(QObject *parent)
: QObject(parent)
{
}
void ConfirmBeforeDeletingCreateRuleDialogTest::shouldHaveDefaultValues()
{
ConfirmBeforeDeletingCreateRuleDialog w;
QVERIFY(!w.windowTitle().isEmpty());
auto mainLayout = w.findChild<QVBoxLayout *>(QStringLiteral("mainlayout"));
QVERIFY(mainLayout);
auto mConfirmBeforeDeletingCreateRuleWidget =
w.findChild<ConfirmBeforeDeletingCreateRuleWidget *>(QStringLiteral("mConfirmBeforeDeletingCreateRuleWidget"));
mainLayout->addWidget(mConfirmBeforeDeletingCreateRuleWidget);
auto buttonBox = w.findChild<QDialogButtonBox *>(QStringLiteral("buttonBox"));
QVERIFY(buttonBox);
auto okButton = buttonBox->button(QDialogButtonBox::Ok);
QVERIFY(!okButton->isEnabled());
}
/*
SPDX-FileCopyrightText: 2021 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include <QObject>
class ConfirmBeforeDeletingCreateRuleDialogTest : public QObject
{
Q_OBJECT
public:
explicit ConfirmBeforeDeletingCreateRuleDialogTest(QObject *parent = nullptr);
~ConfirmBeforeDeletingCreateRuleDialogTest() override = default;
private Q_SLOTS:
void shouldHaveDefaultValues();
};
......@@ -7,6 +7,7 @@
#include "confirmbeforedeletingcreateruledialog.h"
#include <KLocalizedString>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
ConfirmBeforeDeletingCreateRuleDialog::ConfirmBeforeDeletingCreateRuleDialog(QWidget *parent)
......@@ -25,6 +26,9 @@ ConfirmBeforeDeletingCreateRuleDialog::ConfirmBeforeDeletingCreateRuleDialog(QWi
mainLayout->addWidget(buttonBox);
connect(buttonBox, &QDialogButtonBox::accepted, this, &ConfirmBeforeDeletingCreateRuleDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfirmBeforeDeletingCreateRuleDialog::reject);
auto okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setEnabled(false);
connect(mConfirmBeforeDeletingCreateRuleWidget, &ConfirmBeforeDeletingCreateRuleWidget::updateOkButton, okButton, &QPushButton::setEnabled);
}
ConfirmBeforeDeletingCreateRuleDialog::~ConfirmBeforeDeletingCreateRuleDialog()
......
......@@ -34,6 +34,9 @@ ConfirmBeforeDeletingCreateRuleWidget::ConfirmBeforeDeletingCreateRuleWidget(QWi
mPatternLineEdit->setObjectName(QStringLiteral("mPatternLineEdit"));
mainLayout->addWidget(mPatternLineEdit);
fillComboBox();
connect(mPatternLineEdit, &QLineEdit::textChanged, this, [this](const QString &str) {
Q_EMIT updateOkButton(!str.trimmed().isEmpty());
});
}
ConfirmBeforeDeletingCreateRuleWidget::~ConfirmBeforeDeletingCreateRuleWidget()
......
......@@ -25,6 +25,9 @@ public:
void setInfo(const ConfirmBeforeDeletingCreateRuleWidget::ConfirmBeforeDeletingInfo &info);
Q_SIGNALS:
void updateOkButton(bool enabled);
private:
void fillComboBox();
QLineEdit *const mPatternLineEdit;
......
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