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

0001 /*
0002    SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "messageattachmentdelegatehelperfiletest.h"
0008 
0009 #include <QStyleOptionViewItem>
0010 #include <QTest>
0011 
0012 QTEST_MAIN(MessageDelegateHelperFileTest)
0013 
0014 MessageDelegateHelperFileTest::MessageDelegateHelperFileTest(QObject *parent)
0015     : QObject(parent)
0016 {
0017 }
0018 
0019 void MessageDelegateHelperFileTest::shouldLayoutMultipleFiles()
0020 {
0021 #if 0 // PORT IT
0022     // GIVEN a helper and a message with two attachments
0023     MessageAttachmentDelegateHelperFile helper;
0024     QStyleOptionViewItem option;
0025     QWidget fakeWidget;
0026     option.widget = &fakeWidget;
0027     Message message;
0028 
0029     // One attachment
0030     MessageAttachment msgAttach1;
0031     const QString title1 = QStringLiteral("This is the title");
0032     msgAttach1.setTitle(title1);
0033     const QString description1 = QStringLiteral("A description");
0034     msgAttach1.setDescription(description1);
0035     msgAttach1.setLink(QStringLiteral("http://www.kde.org"));
0036 
0037     // A second attachment
0038     MessageAttachment msgAttach2;
0039     const QString title2 = QStringLiteral("Another title");
0040     msgAttach2.setTitle(title2);
0041     const QString description2 = QStringLiteral("Another description");
0042     msgAttach2.setDescription(description2);
0043     msgAttach2.setLink(QStringLiteral("http://www.kdab.com"));
0044 
0045     message.setAttachements({msgAttach1, msgAttach2});
0046 
0047     // WHEN
0048     const QVector<MessageAttachmentDelegateHelperFile::FileLayout> layouts = helper.doLayout(&message, option);
0049 
0050     // THEN
0051     QCOMPARE(layouts.count(), 2);
0052     const MessageAttachmentDelegateHelperFile::FileLayout layout1 = layouts.at(0);
0053     QCOMPARE(layout1.title, title1);
0054     QCOMPARE(layout1.description, description1);
0055     QCOMPARE(layout1.y, 0);
0056     QVERIFY(layout1.height > 0);
0057     const MessageAttachmentDelegateHelperFile::FileLayout layout2 = layouts.at(1);
0058     QCOMPARE(layout2.title, title2);
0059     QCOMPARE(layout2.description, description2);
0060     QVERIFY(layout2.y >= layout1.y + layout1.height);
0061 #endif
0062 }
0063 
0064 #include "moc_messageattachmentdelegatehelperfiletest.cpp"