File indexing completed on 2024-12-22 04:46:13

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "whatsnewcomboboxwidgettest.h"
0007 #include "whatsnew/whatsnewcomboboxwidget.h"
0008 #include <KSeparator>
0009 #include <QComboBox>
0010 #include <QLabel>
0011 #include <QSignalSpy>
0012 #include <QTest>
0013 #include <QVBoxLayout>
0014 
0015 QTEST_MAIN(WhatsNewComboBoxWidgetTest)
0016 
0017 WhatsNewComboBoxWidgetTest::WhatsNewComboBoxWidgetTest(QObject *parent)
0018     : QObject{parent}
0019 {
0020 }
0021 
0022 void WhatsNewComboBoxWidgetTest::shouldHaveDefaultValues()
0023 {
0024     WhatsNewComboBoxWidget w;
0025     auto mainLayout = w.findChild<QVBoxLayout *>(QStringLiteral("mainLayout"));
0026     QVERIFY(mainLayout);
0027     QCOMPARE(mainLayout->contentsMargins(), QMargins{});
0028 
0029     auto hboxLayout = w.findChild<QHBoxLayout *>(QStringLiteral("hboxLayout"));
0030     QVERIFY(hboxLayout);
0031     QCOMPARE(hboxLayout->contentsMargins(), QMargins{});
0032 
0033     auto mVersionComboBox = w.findChild<QComboBox *>(QStringLiteral("mVersionComboBox"));
0034     QVERIFY(mVersionComboBox);
0035 
0036     auto label = w.findChild<QLabel *>(QStringLiteral("label"));
0037     QVERIFY(label);
0038     QVERIFY(!label->text().isEmpty());
0039 
0040     auto separator = w.findChild<KSeparator *>(QStringLiteral("separator"));
0041     QVERIFY(separator);
0042 }
0043 
0044 void WhatsNewComboBoxWidgetTest::shouldInitializeComboBox()
0045 {
0046     WhatsNewComboBoxWidget w;
0047     w.initializeVersion(WhatsNewComboBoxWidget::Version2_0);
0048     auto mVersionComboBox = w.findChild<QComboBox *>(QStringLiteral("mVersionComboBox"));
0049     QCOMPARE(mVersionComboBox->currentData(), WhatsNewComboBoxWidget::Version2_0);
0050 }
0051 
0052 void WhatsNewComboBoxWidgetTest::shouldEmitVersionChanged()
0053 {
0054     WhatsNewComboBoxWidget w;
0055     QSignalSpy versionChanged(&w, &WhatsNewComboBoxWidget::versionChanged);
0056 
0057     auto mVersionComboBox = w.findChild<QComboBox *>(QStringLiteral("mVersionComboBox"));
0058     mVersionComboBox->setCurrentIndex(mVersionComboBox->findData(WhatsNewComboBoxWidget::AllVersion));
0059     QCOMPARE(versionChanged.count(), 0);
0060 
0061     // Same => not emitted.
0062     mVersionComboBox->setCurrentIndex(mVersionComboBox->findData(WhatsNewComboBoxWidget::AllVersion));
0063     QCOMPARE(versionChanged.count(), 0);
0064 
0065     // Different => emitted.
0066     mVersionComboBox->setCurrentIndex(mVersionComboBox->findData(WhatsNewComboBoxWidget::Version2_0));
0067     QCOMPARE(versionChanged.count(), 1);
0068 }
0069 
0070 #include "moc_whatsnewcomboboxwidgettest.cpp"