Changeset View
Changeset View
Standalone View
Standalone View
src/core/autotests/accountschannelsmodeltest.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (c) 2020 Olivier de Gaalon <olivier.jg@gmail.com> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or modify | ||||
5 | it under the terms of the GNU Library General Public License as published | ||||
6 | by the Free Software Foundation; either version 2 of the License or | ||||
7 | ( at your option ) version 3 or, at the discretion of KDE e.V. | ||||
8 | ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. | ||||
9 | | ||||
10 | This library is distributed in the hope that it will be useful, | ||||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | Library General Public License for more details. | ||||
14 | | ||||
15 | You should have received a copy of the GNU Library General Public License | ||||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "accountschannelsmodeltest.h" | ||||
22 | | ||||
23 | #include "accountmanager.h" | ||||
24 | #include "model/accountschannelsmodel.h" | ||||
25 | #include "model/roomfilterproxymodel.h" | ||||
26 | #include "rocketchataccount.h" | ||||
27 | #include "ruqola.h" | ||||
28 | | ||||
29 | #include <QAbstractItemModelTester> | ||||
30 | #include <QStandardPaths> | ||||
31 | #include <QTest> | ||||
32 | | ||||
33 | QTEST_MAIN(AccountsChannelsModelTest) | ||||
34 | | ||||
35 | AccountsChannelsModelTest::AccountsChannelsModelTest(QObject *parent) | ||||
36 | : QObject(parent) | ||||
37 | { | ||||
38 | } | ||||
39 | | ||||
40 | void AccountsChannelsModelTest::initTestCase() | ||||
41 | { | ||||
42 | QStandardPaths::setTestModeEnabled(true); | ||||
43 | } | ||||
44 | | ||||
45 | void AccountsChannelsModelTest::accountsAndChannels() | ||||
46 | { | ||||
47 | AccountsChannelsModel model; | ||||
48 | QAbstractItemModelTester tester(&model, QAbstractItemModelTester::FailureReportingMode::QtTest); | ||||
49 | | ||||
50 | QCOMPARE(model.rowCount(), 1); // Ruqola creates one account by default | ||||
51 | QCOMPARE(model.data(model.index(1, 0)).toString(), QStringLiteral("")); | ||||
52 | QCOMPARE(model.rowCount(model.index(1, 0)), 0); | ||||
53 | | ||||
54 | const auto newAcctName = QStringLiteral("Test Account"); | ||||
55 | const auto acct = new RocketChatAccount; | ||||
56 | Ruqola::self()->accountManager()->addAccount(acct); | ||||
57 | const auto newAcctIndex = model.index(1, 0); | ||||
58 | QCOMPARE(model.rowCount(), 2); | ||||
59 | QVERIFY(!model.hasChildren(newAcctIndex)); | ||||
60 | QCOMPARE(model.data(newAcctIndex).toString(), QString()); | ||||
61 | acct->setAccountName(newAcctName); | ||||
62 | QCOMPARE(model.data(newAcctIndex).toString(), newAcctName); | ||||
63 | | ||||
64 | Ruqola::self()->setCurrentAccount(newAcctName); | ||||
65 | | ||||
66 | const auto newRoomId = QStringLiteral("RoomId"); | ||||
67 | const auto newRoomName = QStringLiteral("Room Name"); | ||||
68 | acct->roomModel()->addRoom(newRoomId, newRoomName); | ||||
69 | QCOMPARE(model.rowCount(newAcctIndex), 0); // Room not yet open | ||||
70 | | ||||
71 | // FIXME: RoomModel should probably emit dataChanged to allow the sort/filter to update | ||||
72 | acct->roomModel()->findRoom(newRoomId)->setOpen(true); | ||||
73 | QEXPECT_FAIL("", "RoomModel missing dataChanged", Continue); | ||||
74 | QCOMPARE(model.rowCount(newAcctIndex), 1); | ||||
75 | // ... workaround for the above | ||||
76 | acct->roomFilterProxyModel()->invalidate(); | ||||
77 | // ... and try again | ||||
78 | QCOMPARE(model.rowCount(newAcctIndex), 1); | ||||
79 | | ||||
80 | const auto newRoomIndex = model.index(0, 0, newAcctIndex); | ||||
81 | QVERIFY(!model.hasChildren(newRoomIndex)); | ||||
82 | QCOMPARE(model.data(newRoomIndex).toString(), newRoomName); | ||||
83 | | ||||
84 | // TODO: RoomsModel currently has no API for removing rooms | ||||
85 | | ||||
86 | Ruqola::self()->accountManager()->removeAccount(newAcctName); | ||||
87 | QCOMPARE(model.rowCount(), 1); // Only the default account remains | ||||
88 | } |