1 /*
2    SPDX-FileCopyrightText: 2020-2021 Laurent Montel <montel@kde.org>
3 
4    SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "reportmessagedialogtest.h"
8 #include "dialogs/reportmessagedialog.h"
9 #include "dialogs/reportmessagewidget.h"
10 #include <KTextEdit>
11 #include <QDialogButtonBox>
12 #include <QPushButton>
13 #include <QStandardPaths>
14 #include <QTest>
15 #include <QVBoxLayout>
16 
QTEST_MAIN(ReportMessageDialogTest)17 QTEST_MAIN(ReportMessageDialogTest)
18 
19 ReportMessageDialogTest::ReportMessageDialogTest(QObject *parent)
20     : QObject(parent)
21 {
22     QStandardPaths::setTestModeEnabled(true);
23 }
24 
shouldHaveDefaultValues()25 void ReportMessageDialogTest::shouldHaveDefaultValues()
26 {
27     ReportMessageDialog w;
28     QVERIFY(!w.windowTitle().isEmpty());
29 
30     auto mainLayout = w.findChild<QVBoxLayout *>(QStringLiteral("mainLayout"));
31     QVERIFY(mainLayout);
32 
33     auto mReportMessageWidget = w.findChild<ReportMessageWidget *>(QStringLiteral("mReportMessageWidget"));
34     QVERIFY(mReportMessageWidget);
35 
36     auto button = w.findChild<QDialogButtonBox *>(QStringLiteral("button"));
37     QVERIFY(button);
38 
39     QVERIFY(w.message().isEmpty());
40 
41     QPushButton *okButton = button->button(QDialogButtonBox::Ok);
42     QVERIFY(!okButton->isEnabled());
43 }
44 
shouldUpdateOkButton()45 void ReportMessageDialogTest::shouldUpdateOkButton()
46 {
47     ReportMessageDialog w;
48     auto mReportMessageWidget = w.findChild<ReportMessageWidget *>(QStringLiteral("mReportMessageWidget"));
49     auto button = w.findChild<QDialogButtonBox *>(QStringLiteral("button"));
50 
51     auto mMessageLineEdit = mReportMessageWidget->findChild<KTextEdit *>(QStringLiteral("mMessageLineEdit"));
52     QVERIFY(mMessageLineEdit);
53     mMessageLineEdit->setText(QStringLiteral("foo"));
54     QPushButton *okButton = button->button(QDialogButtonBox::Ok);
55     QVERIFY(okButton->isEnabled());
56 }
57