Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 16bac91e authored by Laurent Montel's avatar Laurent Montel 😁

improve unittest. Don't allow to show twice item

parent 384f526c
......@@ -37,6 +37,25 @@ void EmailEditDialogTest::shouldHaveDefaultValue()
EmailEditDialog dlg;
KListWidget *listwidget = qFindChild<KListWidget *>(&dlg, QLatin1String("emailListBox"));
QVERIFY(listwidget);
QCOMPARE(listwidget->count(), 0);
}
void EmailEditDialogTest::shouldAddItems()
{
EmailEditDialog dlg;
KListWidget *listwidget = qFindChild<KListWidget *>(&dlg, QLatin1String("emailListBox"));
const QStringList lst = QStringList() << QLatin1String("foo") << QLatin1String("bla") << QLatin1String("bli");
dlg.setEmailList(lst);
QCOMPARE(listwidget->count(), lst.count());
}
void EmailEditDialogTest::shouldDontAddTwiceItem()
{
EmailEditDialog dlg;
KListWidget *listwidget = qFindChild<KListWidget *>(&dlg, QLatin1String("emailListBox"));
const QStringList lst = QStringList() << QLatin1String("foo") << QLatin1String("bla") << QLatin1String("bli") << QLatin1String("bli");
dlg.setEmailList(lst);
QCOMPARE(listwidget->count(), (lst.count()-1));
}
QTEST_KDEMAIN(EmailEditDialogTest, GUI)
......@@ -32,6 +32,8 @@ public:
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAddItems();
void shouldDontAddTwiceItem();
};
......
......@@ -362,9 +362,13 @@ void EmailEditDialog::setEmailList(const QStringList &list)
QStringList::ConstIterator it;
bool preferred = true;
QStringList::ConstIterator end(items.constEnd());
QStringList emails;
for (it = items.constBegin(); it != end; ++it) {
new EmailItem(*it, mEmailListBox, preferred);
preferred = false;
if (!emails.contains(*it)) {
new EmailItem(*it, mEmailListBox, preferred);
emails << *it;
preferred = false;
}
}
}
......
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