File indexing completed on 2024-09-22 04:50:44
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "convertvariablesjobtest.h" 0008 #include "composer/composerviewbase.h" 0009 #include "composer/composerviewinterface.h" 0010 #include "snippet/convertsnippetvariablesjob.h" 0011 #include <QTest> 0012 QTEST_GUILESS_MAIN(ConvertVariablesJobTest) 0013 0014 ConvertVariablesJobTest::ConvertVariablesJobTest(QObject *parent) 0015 : QObject(parent) 0016 { 0017 } 0018 0019 void ConvertVariablesJobTest::shouldHaveDefaultValues() 0020 { 0021 MessageComposer::ConvertSnippetVariablesJob job; 0022 QVERIFY(job.text().isEmpty()); 0023 QVERIFY(!job.composerViewInterface()); 0024 QVERIFY(!job.canStart()); 0025 } 0026 0027 void ConvertVariablesJobTest::shouldCanStart() 0028 { 0029 MessageComposer::ConvertSnippetVariablesJob job; 0030 QVERIFY(!job.canStart()); 0031 job.setText(QStringLiteral("bla")); 0032 QVERIFY(!job.canStart()); 0033 MessageComposer::ComposerViewBase b; 0034 auto interface = new MessageComposer::ComposerViewInterface(&b); 0035 job.setComposerViewInterface(interface); 0036 QVERIFY(job.canStart()); 0037 } 0038 0039 void ConvertVariablesJobTest::shouldConvertVariables() 0040 { 0041 QFETCH(QString, original); 0042 QFETCH(QString, expected); 0043 MessageComposer::ComposerViewBase b; 0044 auto interface = new MessageComposer::ComposerViewInterface(&b); 0045 MessageComposer::ConvertSnippetVariablesJob job; 0046 job.setComposerViewInterface(interface); 0047 b.setSubject(QStringLiteral("Subject!!!!")); 0048 b.setFrom(QStringLiteral("from!!")); 0049 // TODO add CC/BCC/TO 0050 0051 job.setText(original); 0052 QCOMPARE(job.convertVariables(interface, original), expected); 0053 } 0054 0055 void ConvertVariablesJobTest::shouldConvertVariables_data() 0056 { 0057 QTest::addColumn<QString>("original"); 0058 QTest::addColumn<QString>("expected"); 0059 QTest::newRow("empty") << QString() << QString(); 0060 QTest::newRow("novariable") << QStringLiteral("bla bli blo") << QStringLiteral("bla bli blo"); 0061 QTest::newRow("subject") << QStringLiteral("bla bli blo %FULLSUBJECT") << QStringLiteral("bla bli blo Subject!!!!"); 0062 // TODO add more autotests ! 0063 } 0064 0065 #include "moc_convertvariablesjobtest.cpp"