File indexing completed on 2024-12-22 04:46:03
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 "roomheaderwidgettest.h" 0008 #include "room/roomheaderlabel.h" 0009 #include "room/roomheaderwidget.h" 0010 #include "room/teamnamelabel.h" 0011 #include <QLabel> 0012 #include <QSignalSpy> 0013 #include <QTest> 0014 #include <QToolButton> 0015 #include <QVBoxLayout> 0016 #include <qtestmouse.h> 0017 QTEST_MAIN(RoomHeaderWidgetTest) 0018 RoomHeaderWidgetTest::RoomHeaderWidgetTest(QObject *parent) 0019 : QObject(parent) 0020 { 0021 } 0022 0023 void RoomHeaderWidgetTest::shouldHaveDefaultValues() 0024 { 0025 RoomHeaderWidget w; 0026 auto mainLayout = w.findChild<QVBoxLayout *>(QStringLiteral("mainLayout")); 0027 QVERIFY(mainLayout); 0028 QCOMPARE(mainLayout->contentsMargins(), QMargins{}); 0029 0030 auto mRoomName = w.findChild<QLabel *>(QStringLiteral("mRoomName")); 0031 QVERIFY(mRoomName); 0032 QVERIFY(mRoomName->text().isEmpty()); 0033 QVERIFY(!mRoomName->isVisible()); 0034 QCOMPARE(mRoomName->textInteractionFlags(), Qt::TextBrowserInteraction); 0035 0036 auto roomNameLayout = w.findChild<QHBoxLayout *>(QStringLiteral("roomNameLayout")); 0037 QVERIFY(roomNameLayout); 0038 QCOMPARE(roomNameLayout->contentsMargins(), QMargins{}); 0039 0040 auto mTeamName = w.findChild<TeamNameLabel *>(QStringLiteral("mTeamName")); 0041 QVERIFY(mTeamName); 0042 QVERIFY(mTeamName->text().isEmpty()); 0043 QVERIFY(!mTeamName->isVisible()); 0044 QCOMPARE(mTeamName->textInteractionFlags(), Qt::TextBrowserInteraction); 0045 0046 auto mRoomHeaderLabel = w.findChild<RoomHeaderLabel *>(QStringLiteral("mRoomHeaderLabel")); 0047 QVERIFY(mRoomHeaderLabel); 0048 0049 auto mFavoriteButton = w.findChild<QToolButton *>(QStringLiteral("mFavoriteButton")); 0050 QVERIFY(mFavoriteButton); 0051 QVERIFY(mFavoriteButton->isCheckable()); 0052 QVERIFY(mFavoriteButton->autoRaise()); 0053 0054 auto mEncryptedButton = w.findChild<QToolButton *>(QStringLiteral("mEncryptedButton")); 0055 QVERIFY(mEncryptedButton); 0056 QVERIFY(mEncryptedButton->isCheckable()); 0057 QVERIFY(!mEncryptedButton->isVisible()); 0058 QVERIFY(mEncryptedButton->autoRaise()); 0059 0060 auto mDiscussionBackButton = w.findChild<QToolButton *>(QStringLiteral("mDiscussionBackButton")); 0061 QVERIFY(mDiscussionBackButton); 0062 QVERIFY(!mDiscussionBackButton->isCheckable()); 0063 QVERIFY(!mDiscussionBackButton->isVisible()); 0064 QVERIFY(mDiscussionBackButton->autoRaise()); 0065 0066 auto mChannelInfoButton = w.findChild<QToolButton *>(QStringLiteral("mChannelInfoButton")); 0067 QVERIFY(mChannelInfoButton); 0068 QVERIFY(!mChannelInfoButton->isCheckable()); 0069 QVERIFY(!mChannelInfoButton->toolTip().isEmpty()); 0070 QVERIFY(!mChannelInfoButton->icon().isNull()); 0071 QVERIFY(mChannelInfoButton->autoRaise()); 0072 0073 auto mCallButton = w.findChild<QToolButton *>(QStringLiteral("mCallButton")); 0074 QVERIFY(mCallButton); 0075 QVERIFY(!mCallButton->isCheckable()); 0076 QVERIFY(!mCallButton->toolTip().isEmpty()); 0077 QVERIFY(!mCallButton->icon().isNull()); 0078 QVERIFY(mCallButton->autoRaise()); 0079 0080 auto mListOfUsersButton = w.findChild<QToolButton *>(QStringLiteral("mListOfUsersButton")); 0081 QVERIFY(mListOfUsersButton); 0082 QVERIFY(mListOfUsersButton->isCheckable()); 0083 QVERIFY(!mListOfUsersButton->isChecked()); 0084 QVERIFY(!mListOfUsersButton->toolTip().isEmpty()); 0085 QVERIFY(!mListOfUsersButton->icon().isNull()); 0086 QVERIFY(mListOfUsersButton->autoRaise()); 0087 0088 auto mSearchMessageButton = w.findChild<QToolButton *>(QStringLiteral("mSearchMessageButton")); 0089 QVERIFY(mSearchMessageButton); 0090 QVERIFY(!mSearchMessageButton->isCheckable()); 0091 QVERIFY(!mSearchMessageButton->toolTip().isEmpty()); 0092 QVERIFY(!mSearchMessageButton->icon().isNull()); 0093 QVERIFY(mSearchMessageButton->autoRaise()); 0094 0095 auto mChannelAction = w.findChild<QToolButton *>(QStringLiteral("mChannelAction")); 0096 QVERIFY(mChannelAction); 0097 QCOMPARE(mChannelAction->popupMode(), QToolButton::InstantPopup); 0098 QVERIFY(!mChannelAction->icon().isNull()); 0099 QVERIFY(mChannelAction->autoRaise()); 0100 0101 auto mTeamChannelsButton = w.findChild<QToolButton *>(QStringLiteral("mTeamChannelsButton")); 0102 QVERIFY(mTeamChannelsButton); 0103 QVERIFY(!mTeamChannelsButton->icon().isNull()); 0104 QVERIFY(mTeamChannelsButton->autoRaise()); 0105 QVERIFY(!mTeamChannelsButton->toolTip().isEmpty()); 0106 } 0107 0108 void RoomHeaderWidgetTest::shouldShowHideIcon() 0109 { 0110 RoomHeaderWidget w; 0111 w.show(); 0112 QVERIFY(QTest::qWaitForWindowExposed(&w)); 0113 0114 auto mFavoriteButton = w.findChild<QToolButton *>(QStringLiteral("mFavoriteButton")); 0115 auto mDiscussionBackButton = w.findChild<QToolButton *>(QStringLiteral("mDiscussionBackButton")); 0116 0117 w.setIsDiscussion(true); 0118 QVERIFY(!mFavoriteButton->isVisible()); 0119 QVERIFY(mDiscussionBackButton->isVisible()); 0120 0121 w.setIsDiscussion(false); 0122 QVERIFY(mFavoriteButton->isVisible()); 0123 QVERIFY(!mDiscussionBackButton->isVisible()); 0124 } 0125 0126 void RoomHeaderWidgetTest::shouldEmitSignal() 0127 { 0128 RoomHeaderWidget w; 0129 w.show(); 0130 QVERIFY(QTest::qWaitForWindowExposed(&w)); 0131 0132 QSignalSpy favoriteSignal(&w, &RoomHeaderWidget::favoriteChanged); 0133 auto mFavoriteButton = w.findChild<QToolButton *>(QStringLiteral("mFavoriteButton")); 0134 QTest::mouseClick(mFavoriteButton, Qt::LeftButton); 0135 QCOMPARE(favoriteSignal.count(), 1); 0136 0137 auto mSearchMessageButton = w.findChild<QToolButton *>(QStringLiteral("mSearchMessageButton")); 0138 0139 QSignalSpy searchMessageSignal(&w, &RoomHeaderWidget::searchMessageRequested); 0140 QTest::mouseClick(mSearchMessageButton, Qt::LeftButton); 0141 QCOMPARE(searchMessageSignal.count(), 1); 0142 } 0143 0144 #include "moc_roomheaderwidgettest.cpp"