File indexing completed on 2025-01-05 04:49:49

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "templateparseremailaddressrequesterakonaditest.h"
0008 #include "../templateparseremailaddressrequesterakonadi.h"
0009 #include <Akonadi/EmailAddressRequester>
0010 #include <QHBoxLayout>
0011 #include <QSignalSpy>
0012 #include <QTest>
0013 
0014 TemplateParserEmailAddressRequesterAkonadiTest::TemplateParserEmailAddressRequesterAkonadiTest(QObject *parent)
0015     : QObject(parent)
0016 {
0017 }
0018 
0019 void TemplateParserEmailAddressRequesterAkonadiTest::shouldHaveDefaultValues()
0020 {
0021     TemplateParserEmailAddressRequesterAkonadi w;
0022 
0023     auto mainLayout = w.findChild<QHBoxLayout *>(QStringLiteral("mainLayout"));
0024     QVERIFY(mainLayout);
0025     QCOMPARE(mainLayout->contentsMargins(), QMargins());
0026 
0027     auto mLineEdit = w.findChild<Akonadi::EmailAddressRequester *>(QStringLiteral("EmailAddressRequester"));
0028     QVERIFY(mLineEdit);
0029     QVERIFY(mLineEdit->text().isEmpty());
0030 }
0031 
0032 void TemplateParserEmailAddressRequesterAkonadiTest::shouldAssignValue()
0033 {
0034     TemplateParserEmailAddressRequesterAkonadi w;
0035     auto mLineEdit = w.findChild<Akonadi::EmailAddressRequester *>(QStringLiteral("EmailAddressRequester"));
0036     const QString str{QStringLiteral("foo")};
0037     w.setText(str);
0038     QCOMPARE(w.text(), str);
0039     QCOMPARE(mLineEdit->text(), str);
0040 }
0041 
0042 void TemplateParserEmailAddressRequesterAkonadiTest::shouldClearValue()
0043 {
0044     TemplateParserEmailAddressRequesterAkonadi w;
0045     auto mLineEdit = w.findChild<Akonadi::EmailAddressRequester *>(QStringLiteral("EmailAddressRequester"));
0046     const QString str{QStringLiteral("foo")};
0047     w.setText(str);
0048     QCOMPARE(w.text(), str);
0049     w.clear();
0050     QVERIFY(w.text().isEmpty());
0051     QVERIFY(mLineEdit->text().isEmpty());
0052 }
0053 
0054 void TemplateParserEmailAddressRequesterAkonadiTest::shouldEmitSignal()
0055 {
0056     TemplateParserEmailAddressRequesterAkonadi w;
0057     QSignalSpy spy(&w, &TemplateParser::TemplateParserEmailAddressRequesterBase::textChanged);
0058     w.setText(QStringLiteral("foo"));
0059     QCOMPARE(spy.size(), 1);
0060     w.clear();
0061     QCOMPARE(spy.size(), 2);
0062     w.setText(QStringLiteral("foo"));
0063     QCOMPARE(spy.size(), 3);
0064 }
0065 
0066 QTEST_MAIN(TemplateParserEmailAddressRequesterAkonadiTest)
0067 
0068 #include "moc_templateparseremailaddressrequesterakonaditest.cpp"