File indexing completed on 2024-05-19 05:05:53

0001 /***************************************************************************
0002  *   Copyright (C) 2022 by Thomas Fischer <fischer@unix-ag.uni-kl.de>      *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, see <https://www.gnu.org/licenses/>. *
0016  ***************************************************************************/
0017 
0018 #include <QtTest>
0019 
0020 #include <field/FieldLineEdit>
0021 #include <File>
0022 #include <Entry>
0023 #include <models/FileModel>
0024 #include <file/SortFilterFileModel>
0025 #include <preferences/SettingsGlobalKeywordsWidget>
0026 
0027 class KBibTeXGUITest : public QObject
0028 {
0029     Q_OBJECT
0030 
0031 private Q_SLOTS:
0032     void initTestCase();
0033 
0034     void sortedFilterFileModelSetSourceModel();
0035     void settingsGlobalKeywordsWidgetAddRemove();
0036 
0037 private:
0038 };
0039 
0040 void KBibTeXGUITest::initTestCase()
0041 {
0042     // nothing
0043 }
0044 
0045 void KBibTeXGUITest::sortedFilterFileModelSetSourceModel()
0046 {
0047     File *bibTeXfile = new File();
0048     // Kirsop, Barbara, and Leslie Chan. (2005) Transforming access to research literature for developing countries. Serials Reviews, 31(4): 246–255.
0049     QSharedPointer<Entry> entry(new Entry(Entry::etArticle, QStringLiteral("kirsop2005accessrelitdevcountries")));
0050     bibTeXfile->append(entry);
0051     entry->insert(Entry::ftTitle, Value() << QSharedPointer<PlainText>(new PlainText(QStringLiteral("Transforming access to research literature for developing countries"))));
0052     entry->insert(Entry::ftAuthor, Value() << QSharedPointer<Person>(new Person(QStringLiteral("Barbara"), QStringLiteral("Kirsop"))) << QSharedPointer<Person>(new Person(QStringLiteral("Leslie"), QStringLiteral("Chan"))));
0053     entry->insert(Entry::ftYear, Value() << QSharedPointer<PlainText>(new PlainText(QStringLiteral("2005"))));
0054     entry->insert(Entry::ftJournal, Value() << QSharedPointer<PlainText>(new PlainText(QStringLiteral("Serials Reviews"))));
0055     entry->insert(Entry::ftVolume, Value() << QSharedPointer<PlainText>(new PlainText(QStringLiteral("31"))));
0056     entry->insert(Entry::ftNumber, Value() << QSharedPointer<PlainText>(new PlainText(QStringLiteral("4"))));
0057     entry->insert(Entry::ftPages, Value() << QSharedPointer<PlainText>(new PlainText(QStringLiteral("246--255"))));
0058 
0059     QPointer<FileModel> model = new FileModel();
0060     model->setBibliographyFile(bibTeXfile);
0061     QPointer<SortFilterFileModel> sortFilterProxyModel = new SortFilterFileModel();
0062     sortFilterProxyModel->setSourceModel(model.data());
0063     QCOMPARE(sortFilterProxyModel->rowCount(), 1);
0064 }
0065 
0066 void KBibTeXGUITest::settingsGlobalKeywordsWidgetAddRemove()
0067 {
0068     QPointer<SettingsGlobalKeywordsWidget> sgkw = new SettingsGlobalKeywordsWidget(nullptr);
0069     bool gotChanged = false;
0070     connect(sgkw, &SettingsGlobalKeywordsWidget::changed, this, [&gotChanged] {
0071         gotChanged = true;
0072     });
0073 
0074     gotChanged = false;
0075     sgkw->addKeyword();
0076     QCOMPARE(gotChanged, true);
0077 
0078     gotChanged = false;
0079     sgkw->removeKeyword();
0080     QCOMPARE(gotChanged, true);
0081 }
0082 
0083 QTEST_MAIN(KBibTeXGUITest)
0084 
0085 #include "kbibtexguitest.moc"