File indexing completed on 2024-12-22 05:00:58

0001 /*
0002   SPDX-FileCopyrightText: 2014-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "cryptostateindicatorwidgettest.h"
0008 #include "src/editor/widgets/cryptostateindicatorwidget.h"
0009 #include <QLabel>
0010 #include <QTest>
0011 CryptoStateIndicatorWidgetTest::CryptoStateIndicatorWidgetTest(QObject *parent)
0012     : QObject(parent)
0013 {
0014 }
0015 
0016 CryptoStateIndicatorWidgetTest::~CryptoStateIndicatorWidgetTest() = default;
0017 
0018 void CryptoStateIndicatorWidgetTest::shouldHaveDefaultValue()
0019 {
0020     CryptoStateIndicatorWidget w;
0021     w.show();
0022     QVERIFY(QTest::qWaitForWindowExposed(&w));
0023     auto signature = w.findChild<QLabel *>(QStringLiteral("signatureindicator"));
0024     QVERIFY(signature);
0025     auto encryption = w.findChild<QLabel *>(QStringLiteral("encryptionindicator"));
0026     QVERIFY(encryption);
0027     QVERIFY(signature->isVisible());
0028     QVERIFY(encryption->isVisible());
0029 }
0030 
0031 void CryptoStateIndicatorWidgetTest::shouldBeNotVisibleWhenShowAlwaysIsFalse()
0032 {
0033     CryptoStateIndicatorWidget w;
0034     w.setShowAlwaysIndicator(false);
0035     w.show();
0036     auto signature = w.findChild<QLabel *>(QStringLiteral("signatureindicator"));
0037     auto encryption = w.findChild<QLabel *>(QStringLiteral("encryptionindicator"));
0038     QVERIFY(!signature->isVisible());
0039     QVERIFY(!encryption->isVisible());
0040     w.updateSignatureAndEncrypionStateIndicators(true, true);
0041 
0042     QVERIFY(!signature->isVisible());
0043     QVERIFY(!encryption->isVisible());
0044 }
0045 
0046 void CryptoStateIndicatorWidgetTest::shouldVisibleWhenChangeStatus()
0047 {
0048     CryptoStateIndicatorWidget w;
0049     w.setShowAlwaysIndicator(true);
0050     w.show();
0051     QVERIFY(QTest::qWaitForWindowExposed(&w));
0052     auto signature = w.findChild<QLabel *>(QStringLiteral("signatureindicator"));
0053     auto encryption = w.findChild<QLabel *>(QStringLiteral("encryptionindicator"));
0054     w.updateSignatureAndEncrypionStateIndicators(true, false);
0055     QVERIFY(signature->isVisible());
0056     QVERIFY(!encryption->isVisible());
0057 
0058     w.updateSignatureAndEncrypionStateIndicators(false, true);
0059     QVERIFY(!signature->isVisible());
0060     QVERIFY(encryption->isVisible());
0061 
0062     w.updateSignatureAndEncrypionStateIndicators(true, true);
0063     QVERIFY(signature->isVisible());
0064     QVERIFY(encryption->isVisible());
0065 
0066     w.updateSignatureAndEncrypionStateIndicators(false, false);
0067     QVERIFY(!signature->isVisible());
0068     QVERIFY(!encryption->isVisible());
0069 }
0070 
0071 QTEST_MAIN(CryptoStateIndicatorWidgetTest)
0072 
0073 #include "moc_cryptostateindicatorwidgettest.cpp"