File indexing completed on 2024-06-09 04:59:05

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 "playsoundwidgettest.h"
0008 #include "dialogs/playsoundwidget.h"
0009 #include <KMessageWidget>
0010 #include <QLabel>
0011 #include <QPushButton>
0012 #include <QSlider>
0013 #include <QStandardPaths>
0014 #include <QTest>
0015 #include <QToolButton>
0016 #include <QVBoxLayout>
0017 QTEST_MAIN(PlaySoundWidgetTest)
0018 
0019 PlaySoundWidgetTest::PlaySoundWidgetTest(QObject *parent)
0020     : QObject(parent)
0021 {
0022     QStandardPaths::setTestModeEnabled(true);
0023 }
0024 
0025 void PlaySoundWidgetTest::shouldHaveDefaultValues()
0026 {
0027     PlaySoundWidget w(nullptr);
0028 
0029     auto mainLayout = w.findChild<QVBoxLayout *>(QStringLiteral("mainLayout"));
0030     QVERIFY(mainLayout);
0031     QCOMPARE(mainLayout->contentsMargins(), QMargins{});
0032 
0033     auto playerLayout = w.findChild<QHBoxLayout *>(QStringLiteral("playerLayout"));
0034     QVERIFY(playerLayout);
0035     QCOMPARE(playerLayout->contentsMargins(), QMargins{});
0036 
0037     auto mPlayButton = w.findChild<QPushButton *>(QStringLiteral("mPlayButton"));
0038     QVERIFY(mPlayButton);
0039     QVERIFY(!mPlayButton->isEnabled());
0040 
0041     auto mPositionSlider = w.findChild<QSlider *>(QStringLiteral("mPositionSlider"));
0042     QVERIFY(mPositionSlider);
0043 
0044     auto mSoundButton = w.findChild<QToolButton *>(QStringLiteral("mSoundButton"));
0045     QVERIFY(mSoundButton);
0046     QVERIFY(mSoundButton->isCheckable());
0047     QVERIFY(!mSoundButton->icon().isNull());
0048 
0049     auto mSoundSlider = w.findChild<QSlider *>(QStringLiteral("mSoundSlider"));
0050     QVERIFY(mSoundSlider);
0051     QCOMPARE(mSoundSlider->value(), 50);
0052     QCOMPARE(mSoundSlider->minimum(), 0);
0053     QCOMPARE(mSoundSlider->maximum(), 100);
0054 
0055     auto mLabelDuration = w.findChild<QLabel *>(QStringLiteral("mLabelDuration"));
0056     QVERIFY(mLabelDuration);
0057     QVERIFY(mLabelDuration->text().isEmpty());
0058     QCOMPARE(mLabelDuration->textFormat(), Qt::PlainText);
0059 
0060     auto mMessageWidget = w.findChild<KMessageWidget *>(QStringLiteral("mMessageWidget"));
0061     QVERIFY(mMessageWidget);
0062     QVERIFY(!mMessageWidget->isCloseButtonVisible());
0063     QVERIFY(mMessageWidget->wordWrap());
0064     QCOMPARE(mMessageWidget->messageType(), KMessageWidget::Information);
0065 
0066     auto mLabelPercentSound = w.findChild<QLabel *>(QStringLiteral("mLabelPercentSound"));
0067     QVERIFY(mLabelPercentSound);
0068     QVERIFY(!mLabelPercentSound->text().isEmpty());
0069     QCOMPARE(mLabelPercentSound->textFormat(), Qt::PlainText);
0070 }
0071 
0072 #include "moc_playsoundwidgettest.cpp"