File indexing completed on 2024-06-09 04:59:32
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 "threadmessagewidgettest.h" 0008 #include "room/messagelinewidget.h" 0009 #include "room/messagelistview.h" 0010 #include "room/roomwidgetbase.h" 0011 #include "threadwidget/threadmessagewidget.h" 0012 #include <QLabel> 0013 #include <QStandardPaths> 0014 #include <QTest> 0015 #include <QToolButton> 0016 #include <QVBoxLayout> 0017 QTEST_MAIN(ThreadMessageWidgetTest) 0018 0019 ThreadMessageWidgetTest::ThreadMessageWidgetTest(QObject *parent) 0020 : QObject(parent) 0021 { 0022 QStandardPaths::setTestModeEnabled(true); 0023 } 0024 0025 void ThreadMessageWidgetTest::shouldHaveDefaultValues() 0026 { 0027 ThreadMessageWidget::ThreadMessageInfo info; 0028 QVERIFY(info.threadMessageId.isEmpty()); 0029 QVERIFY(info.threadMessagePreview.isEmpty()); 0030 QVERIFY(!info.threadIsFollowing); 0031 QVERIFY(!info.room); 0032 0033 ThreadMessageWidget w(nullptr); 0034 auto mainLayout = w.findChild<QVBoxLayout *>(QStringLiteral("mainLayout")); 0035 QVERIFY(mainLayout); 0036 QCOMPARE(mainLayout->contentsMargins(), QMargins{}); 0037 0038 auto mThreadPreview = w.findChild<QLabel *>(QStringLiteral("mThreadPreview")); 0039 QVERIFY(mThreadPreview); 0040 QVERIFY(mThreadPreview->wordWrap()); 0041 QCOMPARE(mThreadPreview->contextMenuPolicy(), Qt::NoContextMenu); 0042 QVERIFY(mThreadPreview->text().isEmpty()); 0043 0044 auto mRoomWidgetBase = w.findChild<RoomWidgetBase *>(QStringLiteral("mRoomWidgetBase")); 0045 QVERIFY(mRoomWidgetBase); 0046 0047 auto hboxLayout = w.findChild<QHBoxLayout *>(QStringLiteral("hboxLayout")); 0048 QVERIFY(hboxLayout); 0049 QCOMPARE(hboxLayout->contentsMargins(), QMargins()); 0050 0051 auto mFollowButton = w.findChild<QToolButton *>(QStringLiteral("mFollowButton")); 0052 QVERIFY(mFollowButton); 0053 QVERIFY(mFollowButton->autoRaise()); 0054 QVERIFY(mFollowButton->isCheckable()); 0055 } 0056 0057 void ThreadMessageWidgetTest::shouldChangeThreadPreview() 0058 { 0059 ThreadMessageWidget w(nullptr); 0060 auto mThreadPreview = w.findChild<QLabel *>(QStringLiteral("mThreadPreview")); 0061 const QString threadPreview{QStringLiteral("bla")}; 0062 ThreadMessageWidget::ThreadMessageInfo info; 0063 info.threadMessagePreview = threadPreview; 0064 0065 w.setThreadMessageInfo(info); 0066 QCOMPARE(mThreadPreview->text(), threadPreview); 0067 } 0068 0069 #include "moc_threadmessagewidgettest.cpp"