mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 03:37:47 +00:00
Expand AccountManager tests with more rigorous model testing
This commit is contained in:
parent
aabe60cdf1
commit
732b1cdada
1 changed files with 69 additions and 9 deletions
|
@ -12,20 +12,80 @@ class AccountManagerTest : public QObject
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void testNothing()
|
void testNothing()
|
||||||
{
|
{
|
||||||
AccountManager profileManager;
|
AccountManager accountManager;
|
||||||
QAbstractItemModelTester modelTester(&profileManager);
|
QAbstractItemModelTester modelTester(&accountManager);
|
||||||
|
|
||||||
QCOMPARE(profileManager.rowCount({}), 0);
|
const QSignalSpy accountsChangedSpy(&accountManager, &AccountManager::accountsChanged);
|
||||||
profileManager.load();
|
QVERIFY(accountsChangedSpy.isValid());
|
||||||
|
|
||||||
|
const QSignalSpy accountAddedSpy(&accountManager, &AccountManager::accountAdded);
|
||||||
|
QVERIFY(accountAddedSpy.isValid());
|
||||||
|
|
||||||
|
QCOMPARE(accountManager.rowCount({}), 0);
|
||||||
|
accountManager.load();
|
||||||
|
QCOMPARE(accountsChangedSpy.count(), 0); // no accounts were changed
|
||||||
|
QCOMPARE(accountAddedSpy.count(), 0); // no accounts were added
|
||||||
|
|
||||||
// There should be no profiles, not even a dummy one
|
// There should be no profiles, not even a dummy one
|
||||||
QCOMPARE(profileManager.rowCount({}), 0);
|
QCOMPARE(accountManager.rowCount({}), 0);
|
||||||
QCOMPARE(profileManager.numAccounts(), 0);
|
QCOMPARE(accountManager.numAccounts(), 0);
|
||||||
QVERIFY(!profileManager.hasAnyAccounts());
|
QVERIFY(!accountManager.hasAnyAccounts());
|
||||||
|
|
||||||
// These functions shouldn't crash and return empty when there's no acccounts
|
// These functions shouldn't crash and return empty when there's no acccounts
|
||||||
QCOMPARE(profileManager.getByUuid(QString{}), nullptr);
|
QCOMPARE(accountManager.getByUuid(QString{}), nullptr);
|
||||||
QVERIFY(!profileManager.canDelete(nullptr));
|
QVERIFY(!accountManager.canDelete(nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
void testAccountManagement_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<bool>("isSapphire");
|
||||||
|
|
||||||
|
QTest::addRow("se") << false;
|
||||||
|
QTest::addRow("sapphire") << true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testAccountManagement()
|
||||||
|
{
|
||||||
|
AccountManager accountManager;
|
||||||
|
QAbstractItemModelTester modelTester(&accountManager);
|
||||||
|
|
||||||
|
const QSignalSpy accountsChangedSpy(&accountManager, &AccountManager::accountsChanged);
|
||||||
|
QVERIFY(accountsChangedSpy.isValid());
|
||||||
|
|
||||||
|
const QSignalSpy accountAddedSpy(&accountManager, &AccountManager::accountAdded);
|
||||||
|
QVERIFY(accountAddedSpy.isValid());
|
||||||
|
|
||||||
|
QCOMPARE(accountManager.rowCount({}), 0);
|
||||||
|
accountManager.load();
|
||||||
|
QCOMPARE(accountsChangedSpy.count(), 0);
|
||||||
|
QCOMPARE(accountAddedSpy.count(), 0);
|
||||||
|
QVERIFY(!accountManager.hasAnyAccounts());
|
||||||
|
|
||||||
|
QFETCH(bool, isSapphire);
|
||||||
|
|
||||||
|
if (isSapphire) {
|
||||||
|
accountManager.createSapphireAccount(QStringLiteral("foo.com"), QStringLiteral("foo"));
|
||||||
|
} else {
|
||||||
|
accountManager.createSquareEnixAccount(QStringLiteral("foo"), static_cast<int>(Account::GameLicense::WindowsStandalone), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
QCOMPARE(accountsChangedSpy.count(), 1);
|
||||||
|
QCOMPARE(accountAddedSpy.count(), 1);
|
||||||
|
QCOMPARE(accountManager.rowCount({}), 1);
|
||||||
|
QCOMPARE(accountManager.numAccounts(), 1);
|
||||||
|
QVERIFY(accountManager.hasAnyAccounts());
|
||||||
|
|
||||||
|
auto account = accountManager.data(accountManager.index(0, 0), AccountManager::AccountRole).value<Account *>();
|
||||||
|
QVERIFY(!accountManager.canDelete(account));
|
||||||
|
|
||||||
|
// TODO: maybe deleteAccount shouldn't work when canDelete == false?
|
||||||
|
accountManager.deleteAccount(account);
|
||||||
|
|
||||||
|
QCOMPARE(accountsChangedSpy.count(), 2); // this signal should be called
|
||||||
|
QCOMPARE(accountAddedSpy.count(), 1); // but not here, because nothing was added obviously
|
||||||
|
QCOMPARE(accountManager.rowCount({}), 0);
|
||||||
|
QCOMPARE(accountManager.numAccounts(), 0);
|
||||||
|
QVERIFY(!accountManager.hasAnyAccounts());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue