File indexing completed on 2024-12-01 04:36:35

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "ruqolamainwindowtest.h"
0008 #include "misc/statuscombobox.h"
0009 #include "ruqolamainwindow.h"
0010 
0011 #include <QLabel>
0012 #include <QSplitter>
0013 #include <QStackedWidget>
0014 #include <QStandardPaths>
0015 #include <QTest>
0016 #include <QToolButton>
0017 #include <QWidgetAction>
0018 
0019 QTEST_MAIN(RuqolaMainWindowTest)
0020 
0021 RuqolaMainWindowTest::RuqolaMainWindowTest(QObject *parent)
0022     : QObject(parent)
0023 {
0024     QStandardPaths::setTestModeEnabled(true);
0025 }
0026 
0027 static void switchToMainWidget(RuqolaMainWindow &w)
0028 {
0029     auto mStackedWidget = w.findChild<QStackedWidget *>(QStringLiteral("mStackedWidget"));
0030     QVERIFY(mStackedWidget);
0031     auto mRuqolaMainWidget = mStackedWidget->findChild<QWidget *>(QStringLiteral("mRuqolaMainWidget"));
0032     QVERIFY(mRuqolaMainWidget);
0033     mStackedWidget->setCurrentWidget(mRuqolaMainWidget);
0034     QCOMPARE(mStackedWidget->currentWidget(), mRuqolaMainWidget);
0035 }
0036 
0037 void RuqolaMainWindowTest::shouldHaveDefaultValues()
0038 {
0039     RuqolaMainWindow w;
0040     auto mSplitter = w.findChild<QSplitter *>(QStringLiteral("mSplitter"));
0041     QVERIFY(mSplitter);
0042     switchToMainWidget(w);
0043 
0044     auto statusAction = qobject_cast<QWidgetAction *>(w.action(QStringLiteral("status")));
0045     QVERIFY(statusAction);
0046     QVERIFY(!statusAction->text().isEmpty());
0047 
0048     auto status = statusAction->defaultWidget();
0049     QVERIFY(status);
0050     QVERIFY(status->layout());
0051 
0052     auto mStatusComboBox = status->findChild<StatusCombobox *>(QStringLiteral("mStatusComboBox"));
0053     QVERIFY(mStatusComboBox);
0054 
0055     auto label = status->findChild<QLabel *>(QStringLiteral("label"));
0056     QVERIFY(label);
0057     QVERIFY(!label->text().isEmpty());
0058 
0059     auto mStatusBarTypingMessage = w.findChild<QLabel *>(QStringLiteral("mStatusBarTypingMessage"));
0060     QVERIFY(mStatusBarTypingMessage);
0061     QCOMPARE(mStatusBarTypingMessage->textFormat(), Qt::RichText);
0062 
0063     auto mNotificationToolButton = w.findChild<QToolButton *>(QStringLiteral("mNotificationToolButton"));
0064     QVERIFY(mNotificationToolButton);
0065     QVERIFY(!mNotificationToolButton->toolTip().isEmpty());
0066     QVERIFY(mNotificationToolButton->isHidden());
0067     QVERIFY(mNotificationToolButton->autoRaise());
0068 }
0069 
0070 void RuqolaMainWindowTest::shouldRestoreSizes()
0071 {
0072     // Save
0073     QList<int> actualSizes;
0074     {
0075         RuqolaMainWindow w;
0076         switchToMainWidget(w);
0077         w.resize(800, 800);
0078         w.show();
0079 
0080         auto mSplitter = w.findChild<QSplitter *>(QStringLiteral("mSplitter"));
0081         QVERIFY(mSplitter);
0082         mSplitter->setSizes({100, 400});
0083         actualSizes = mSplitter->sizes(); // not exactly {100, 400} but more something like {167, 308}
0084     }
0085     // Restore
0086     {
0087         RuqolaMainWindow w;
0088         switchToMainWidget(w);
0089         QCOMPARE(w.size(), QSize(800, 800));
0090         w.show();
0091 
0092         auto mSplitter = w.findChild<QSplitter *>(QStringLiteral("mSplitter"));
0093         QVERIFY(mSplitter);
0094         QCOMPARE(mSplitter->sizes(), actualSizes);
0095     }
0096 }
0097 
0098 #include "moc_ruqolamainwindowtest.cpp"