-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrulesmodeltest.cpp
45 lines (36 loc) · 1.5 KB
/
rulesmodeltest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstraste.com>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "account/rulesmodel.h"
#include "account/accountmanager.h"
#include "autotests/helperreply.h"
#include "autotests/mockaccount.h"
#include <QtTest/QtTest>
class RulesModelTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase()
{
AccountManager::instance().setTestMode(true);
account = new MockAccount();
AccountManager::instance().addAccount(account);
}
void testModel()
{
QUrl url = account->apiUrl(QStringLiteral("/api/v1/instance/rules"));
account->registerGet(url, new TestReply(QStringLiteral("rules.json"), account));
RulesModel rulesModel;
rulesModel.setAccount(account);
QCOMPARE(rulesModel.rowCount({}), 6);
QCOMPARE(rulesModel.data(rulesModel.index(0, 0), RulesModel::IdRole).toInt(), 1);
QCOMPARE(rulesModel.data(rulesModel.index(0, 0), RulesModel::TextRole).toString(),
QStringLiteral("Sexually explicit or violent media must be marked as sensitive when posting"));
QCOMPARE(rulesModel.data(rulesModel.index(1, 0), RulesModel::IdRole).toInt(), 2);
QCOMPARE(rulesModel.data(rulesModel.index(1, 0), RulesModel::TextRole).toString(),
QStringLiteral("No racism, sexism, homophobia, transphobia, xenophobia, or casteism"));
}
private:
MockAccount *account = nullptr;
};
QTEST_MAIN(RulesModelTest)
#include "rulesmodeltest.moc"