File indexing completed on 2024-12-22 04:46:03
0001 /* 0002 SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "testdata.h" 0008 #include "managerdatapaths.h" 0009 #include "rocketchataccount.h" 0010 #include "ruqola.h" 0011 0012 #include <QFile> 0013 #include <QPixmap> 0014 #include <QStandardPaths> 0015 #include <QTest> 0016 0017 void initTestAccount() 0018 { 0019 QStandardPaths::setTestModeEnabled(true); 0020 Ruqola::self()->rocketChatAccount()->setAccountName(QStringLiteral("accountName")); 0021 } 0022 0023 MessageAttachment testAttachment() 0024 { 0025 MessageAttachment msgAttach; 0026 msgAttach.setAttachmentType(MessageAttachment::Image); 0027 const QString title = QStringLiteral("This is the title"); 0028 msgAttach.setTitle(title); 0029 const QString description = QStringLiteral("A description"); 0030 msgAttach.setDescription(description); 0031 QPixmap pix(50, 100); 0032 pix.fill(Qt::white); 0033 // Save the pixmap directly into the cache so that no download happens 0034 const QString cachePath = ManagerDataPaths::self()->path(ManagerDataPaths::Cache, Ruqola::self()->rocketChatAccount()->accountName()); 0035 QDir().mkpath(cachePath); 0036 const QString link = QStringLiteral("/testfile.png"); 0037 const QString pixFileName = cachePath + link; 0038 pix.save(pixFileName, "png"); 0039 msgAttach.setLink(link); 0040 msgAttach.setImageUrlPreview(link); 0041 return msgAttach; 0042 } 0043 0044 QUrl avatarLink() 0045 { 0046 // Save the pixmap directly into the cache so that no download happens 0047 const QString cachePath = ManagerDataPaths::self()->path(ManagerDataPaths::Cache, Ruqola::self()->rocketChatAccount()->accountName()); 0048 QDir().mkpath(cachePath); 0049 const QString link = QStringLiteral("/avatarpix.png"); 0050 const QString pixFileName = cachePath + link; 0051 0052 if (!QFileInfo::exists(pixFileName)) { 0053 const QString srcPath = QFINDTESTDATA("../../../../src/icons/32-apps-ruqola.png"); 0054 Q_ASSERT(!srcPath.isEmpty()); 0055 if (!QFile::copy(srcPath, pixFileName)) { 0056 qWarning() << "Couldn't copy" << srcPath << "to" << pixFileName; 0057 } 0058 } 0059 0060 return QUrl(QLatin1String("https://example.com") + link); 0061 }