File indexing completed on 2024-05-12 16:15:56
0001 /* 0002 SPDX-FileCopyrightText: 2014-2023 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "texttospeechactionstest.h" 0008 #include "../texttospeechactions.h" 0009 #include <QAction> 0010 #include <QSignalSpy> 0011 #include <QTest> 0012 0013 Q_DECLARE_METATYPE(TextEditTextToSpeech::TextToSpeechWidget::State) 0014 QTEST_MAIN(TextToSpeechActionsTest) 0015 TextToSpeechActionsTest::TextToSpeechActionsTest(QObject *parent) 0016 : QObject(parent) 0017 { 0018 qRegisterMetaType<TextEditTextToSpeech::TextToSpeechWidget::State>(); 0019 QIcon::setThemeName(QStringLiteral("breeze")); 0020 } 0021 0022 TextToSpeechActionsTest::~TextToSpeechActionsTest() = default; 0023 0024 void TextToSpeechActionsTest::shouldHaveDefaultValue() 0025 { 0026 TextEditTextToSpeech::TextToSpeechActions act; 0027 QVERIFY(act.stopAction()); 0028 QVERIFY(act.playPauseAction()); 0029 QCOMPARE(act.state(), TextEditTextToSpeech::TextToSpeechWidget::Stop); 0030 0031 QVERIFY(act.stopAction()->isEnabled()); 0032 QVERIFY(!act.stopAction()->icon().isNull()); 0033 0034 QVERIFY(!act.playPauseAction()->isEnabled()); 0035 QVERIFY(!act.playPauseAction()->icon().isNull()); 0036 } 0037 0038 void TextToSpeechActionsTest::shouldChangeButtonEnableStateWhenChangeState() 0039 { 0040 TextEditTextToSpeech::TextToSpeechActions act; 0041 act.setState(TextEditTextToSpeech::TextToSpeechWidget::Play); 0042 0043 QVERIFY(act.stopAction()->isEnabled()); 0044 QVERIFY(act.playPauseAction()->isEnabled()); 0045 0046 act.setState(TextEditTextToSpeech::TextToSpeechWidget::Pause); 0047 QVERIFY(act.stopAction()->isEnabled()); 0048 QVERIFY(act.playPauseAction()->isEnabled()); 0049 0050 act.setState(TextEditTextToSpeech::TextToSpeechWidget::Stop); 0051 0052 QVERIFY(act.stopAction()->isEnabled()); 0053 QVERIFY(!act.playPauseAction()->isEnabled()); 0054 } 0055 0056 void TextToSpeechActionsTest::shouldChangeStateWhenClickOnPlayPause() 0057 { 0058 TextEditTextToSpeech::TextToSpeechActions act; 0059 act.setState(TextEditTextToSpeech::TextToSpeechWidget::Play); 0060 QCOMPARE(act.state(), TextEditTextToSpeech::TextToSpeechWidget::Play); 0061 0062 act.playPauseAction()->trigger(); 0063 QCOMPARE(act.state(), TextEditTextToSpeech::TextToSpeechWidget::Pause); 0064 0065 act.playPauseAction()->trigger(); 0066 QCOMPARE(act.state(), TextEditTextToSpeech::TextToSpeechWidget::Play); 0067 } 0068 0069 void TextToSpeechActionsTest::shouldChangeStateWhenClickOnStop() 0070 { 0071 TextEditTextToSpeech::TextToSpeechActions act; 0072 act.setState(TextEditTextToSpeech::TextToSpeechWidget::Play); 0073 0074 act.stopAction()->trigger(); 0075 QCOMPARE(act.state(), TextEditTextToSpeech::TextToSpeechWidget::Stop); 0076 } 0077 0078 void TextToSpeechActionsTest::shouldEmitStateChanged() 0079 { 0080 TextEditTextToSpeech::TextToSpeechActions act; 0081 act.setState(TextEditTextToSpeech::TextToSpeechWidget::Play); 0082 QSignalSpy spy(&act, &TextEditTextToSpeech::TextToSpeechActions::stateChanged); 0083 act.setState(TextEditTextToSpeech::TextToSpeechWidget::Play); 0084 QCOMPARE(spy.count(), 0); 0085 0086 act.playPauseAction()->trigger(); 0087 QCOMPARE(spy.count(), 1); 0088 QCOMPARE(spy.at(0).at(0).value<TextEditTextToSpeech::TextToSpeechWidget::State>(), TextEditTextToSpeech::TextToSpeechWidget::Pause); 0089 act.playPauseAction()->trigger(); 0090 QCOMPARE(spy.count(), 2); 0091 QCOMPARE(spy.at(1).at(0).value<TextEditTextToSpeech::TextToSpeechWidget::State>(), TextEditTextToSpeech::TextToSpeechWidget::Play); 0092 act.playPauseAction()->trigger(); 0093 QCOMPARE(spy.count(), 3); 0094 QCOMPARE(spy.at(2).at(0).value<TextEditTextToSpeech::TextToSpeechWidget::State>(), TextEditTextToSpeech::TextToSpeechWidget::Pause); 0095 act.stopAction()->trigger(); 0096 QCOMPARE(spy.count(), 4); 0097 QCOMPARE(spy.at(3).at(0).value<TextEditTextToSpeech::TextToSpeechWidget::State>(), TextEditTextToSpeech::TextToSpeechWidget::Stop); 0098 } 0099 0100 #include "moc_texttospeechactionstest.cpp"