Commit c4f820d9 authored by Laurent Montel's avatar Laurent Montel 😁

Add more autotest

parent 34dc6dfc
......@@ -52,4 +52,29 @@ void CheckAttachmentJobTest::shouldAssignEmails()
QCOMPARE(job.originalEmails(), lst);
}
void CheckAttachmentJobTest::shouldRemoveDuplicatedEmails()
{
QFETCH(QStringList, originalEmails);
QFETCH(QStringList, result);
CheckAttachmentJob job;
job.setOriginalEmails(originalEmails);
job.start();
QCOMPARE(job.resultList(), result);
}
void CheckAttachmentJobTest::shouldRemoveDuplicatedEmails_data()
{
QTest::addColumn<QStringList>("originalEmails");
QTest::addColumn<QStringList>("result");
QTest::newRow("empty") << QStringList() << QStringList();
QStringList lst{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")};
QTest::newRow("samelist") << lst << lst;
QStringList original{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org"), QStringLiteral("bla@kde.org")};
QStringList result{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")};
QTest::newRow("oneduplicate") << original << result;
}
QTEST_MAIN(CheckAttachmentJobTest)
......@@ -31,6 +31,8 @@ public:
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAssignEmails();
void shouldRemoveDuplicatedEmails();
void shouldRemoveDuplicatedEmails_data();
};
#endif // CHECKATTACHMENTJOBTEST_H
......@@ -21,6 +21,7 @@
#include "duplicateemails/checkduplicateemailsjob.h"
#include "duplicateemails/checkduplicateemailsdialog.h"
#include "sendattachments/checkattachmentdialog.h"
#include "sendattachments/checkattachmentjob.h"
#include <KMessageBox>
#include <KConfigGroup>
......@@ -96,8 +97,10 @@ bool CheckBeforeSendInterface::exec(const MessageComposer::PluginEditorCheckBefo
if (params.hasAttachment()) {
QPointer<CheckAttachmentDialog> dlg = new CheckAttachmentDialog(parentWidget());
const QStringList lst{ params.bccAddresses(), params.toAddresses(), params.ccAddresses() };
//dlg->setListOfEmails();
//TODO
CheckAttachmentJob job;
job.setOriginalEmails(lst);
job.start();
dlg->setEmails(job.resultList());
if (dlg->exec()) {
delete dlg;
return true;
......
......@@ -49,6 +49,11 @@ CheckAttachmentDialog::~CheckAttachmentDialog()
writeConfig();
}
void CheckAttachmentDialog::setEmails(const QStringList &emails)
{
mListWidget->clear();
mListWidget->addItems(emails);
}
void CheckAttachmentDialog::writeConfig()
{
......
......@@ -28,6 +28,8 @@ class CheckAttachmentDialog : public QDialog
public:
explicit CheckAttachmentDialog(QWidget *parent = Q_NULLPTR);
~CheckAttachmentDialog();
void setEmails(const QStringList &emails);
private:
void writeConfig();
void readConfig();
......
......@@ -18,6 +18,7 @@
*/
#include "checkattachmentjob.h"
#include <KEmailAddress>
CheckAttachmentJob::CheckAttachmentJob()
{
......@@ -32,8 +33,15 @@ CheckAttachmentJob::~CheckAttachmentJob()
void CheckAttachmentJob::start()
{
mResultList.clear();
Q_FOREACH(const QString &email, mOriginalEmails) {
Q_FOREACH(const QString &email, mOriginalEmails) {
QString tname, temail;
KEmailAddress::extractEmailAddressAndName(email, temail, tname); // ignore return value
if (!temail.isEmpty()) {
if (!mResultList.contains(temail)) {
mResultList.append(temail);
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment