@@ -27,7 +27,7 @@
28#include <QtTest>
28#include <QtTest>
30−QList<QVariantMap> properties;
30+QHash<QString, QList<QVariantMap>> mockProperties;
32class LauncherModelASTest : public QObject
32class LauncherModelASTest : public QObject
@@ -47,22 +47,30 @@ private Q_SLOTS:
47 item.insert("icon", "fake.svg");
47 item.insert("icon", "fake.svg");
48 item.insert("count", 0);
48 item.insert("count", 0);
49 item.insert("countVisible", false);
49 item.insert("countVisible", false);
50+ item.insert("pinned", true);
50 list.append(item);
51 list.append(item);
51 item["id"] = "appId2";
52 item["id"] = "appId2";
52 item["name"] = "Item 2";
53 item["name"] = "Item 2";
53 list.append(item);
54 list.append(item);
54− properties = list;
55+ mockProperties["user1"] = list;
57− bool isInSync(LauncherModel *model) {
58+ bool isInSync(LauncherModel *model, const QList<QVariantMap> &properties) {
58− // Verify after startup the items are in there
59+ QList<QVariantMap> list;
60+ // Strip unpinned if onlyPinned is set
61+ Q_FOREACH (const QVariantMap &map, properties) {
62+ if (!model->onlyPinned() || map.value("pinned").toBool()) {
59− bool inSync = model->rowCount() == properties.count();
67+ bool inSync = model->rowCount() == list.count();
60− for (int i = 0; i < model->rowCount(); i++) {
68+ for (int i = 0; inSync && i < model->rowCount(); i++) {
61− inSync &= model->get(i)->appId() == properties.at(i).value("id").toString();
69+ inSync &= model->get(i)->appId() == list.at(i).value("id").toString();
62− inSync &= model->get(i)->name() == properties.at(i).value("name").toString();
70+ inSync &= model->get(i)->name() == list.at(i).value("name").toString();
63− inSync &= model->get(i)->icon() == properties.at(i).value("icon").toString();
71+ inSync &= model->get(i)->icon() == list.at(i).value("icon").toString();
64− inSync &= model->get(i)->count() == properties.at(i).value("count").toInt();
72+ inSync &= model->get(i)->count() == list.at(i).value("count").toInt();
65− inSync &= model->get(i)->countVisible() == properties.at(i).value("countVisible").toBool();
73+ inSync &= model->get(i)->countVisible() == list.at(i).value("countVisible").toBool();
67 return inSync;
75 return inSync;
@@ -74,9 +82,9 @@ private Q_SLOTS:
74 // We didn't set a user yet. model should be empty
82 // We didn't set a user yet. model should be empty
75 QCOMPARE(model->rowCount(), 0);
83 QCOMPARE(model->rowCount(), 0);
77− model->setUser("dummy");
85+ model->setUser("user1");
79− QCOMPARE(isInSync(model), true);
87+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
80 model->deleteLater();
88 model->deleteLater();
@@ -85,8 +93,8 @@ private Q_SLOTS:
85 QTest::addColumn<QString>("changedUser");
93 QTest::addColumn<QString>("changedUser");
86 QTest::addColumn<bool>("inSync");
94 QTest::addColumn<bool>("inSync");
88− QTest::newRow("this user changed") << "dummy" << "dummy" << true;
96+ QTest::newRow("this user changed") << "user1" << "user1" << true;
89− QTest::newRow("other user changed") << "dummy" << "fred" << false;
97+ QTest::newRow("other user changed") << "user1" << "user2" << false;
92 void testASChangedUpdatesModel() {
100 void testASChangedUpdatesModel() {
@@ -97,42 +105,67 @@ private Q_SLOTS:
97 LauncherModel* model = new LauncherModel(this);
105 LauncherModel* model = new LauncherModel(this);
98 model->setUser(modelUser);
106 model->setUser(modelUser);
100− int oldCount = properties.count();
108+ int oldCount = mockProperties[modelUser].count();
101 QCOMPARE(model->rowCount(), oldCount);
109 QCOMPARE(model->rowCount(), oldCount);
103− QList<QVariantMap> newList = properties;
111+ QList<QVariantMap> newList;
104 QVariantMap newEntry;
112 QVariantMap newEntry;
105 newEntry.insert("id", "newappId");
113 newEntry.insert("id", "newappId");
106 newEntry.insert("name", "New app");
114 newEntry.insert("name", "New app");
107 newEntry.insert("icon", "some-icon.svg");
115 newEntry.insert("icon", "some-icon.svg");
108 newEntry.insert("count", 0);
116 newEntry.insert("count", 0);
109 newEntry.insert("countVisible", false);
117 newEntry.insert("countVisible", false);
118+ newEntry.insert("pinned", true);
110 newList.append(newEntry);
119 newList.append(newEntry);
111 model->m_accounts->simulatePropertyChange(changedUser, "LauncherItems", QVariant::fromValue(newList));
120 model->m_accounts->simulatePropertyChange(changedUser, "LauncherItems", QVariant::fromValue(newList));
113− QCOMPARE(isInSync(model), inSync);
122+ QCOMPARE(isInSync(model, mockProperties[modelUser]), true);
123+ QCOMPARE(isInSync(model, mockProperties[changedUser]), inSync);
115 model->deleteLater();
125 model->deleteLater();
118 void testUpdateCount() {
128 void testUpdateCount() {
119 LauncherModel* model = new LauncherModel(this);
129 LauncherModel* model = new LauncherModel(this);
120− model->setUser("dummy");
130+ model->setUser("user1");
122 QCOMPARE(model->get(0)->countVisible(), false);
132 QCOMPARE(model->get(0)->countVisible(), false);
123 QCOMPARE(model->get(0)->count(), 0);
133 QCOMPARE(model->get(0)->count(), 0);
125− QList<QVariantMap> newList = properties;
135+ QList<QVariantMap> newList = mockProperties["user1"];
126 QVariantMap entry = newList.at(0);
136 QVariantMap entry = newList.at(0);
127 entry["countVisible"] = true;
137 entry["countVisible"] = true;
128 entry["count"] = 55;
138 entry["count"] = 55;
129 newList[0] = entry;
139 newList[0] = entry;
130− model->m_accounts->simulatePropertyChange("dummy", "LauncherItems", QVariant::fromValue(newList));
140+ model->m_accounts->simulatePropertyChange("user1", "LauncherItems", QVariant::fromValue(newList));
132− QCOMPARE(isInSync(model), true);
142+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
134 model->deleteLater();
144 model->deleteLater();
147+ void testOnlyPinned() {
148+ LauncherModel *model = new LauncherModel(this);
149+ model->setUser("user1");
150+ model->setOnlyPinned(true);
152+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
154+ // Let's unpin one item
155+ QList<QVariantMap> newList = mockProperties["user1"];
156+ QVariantMap entry = newList.at(0);
157+ entry["pinned"] = false;
159+ model->m_accounts->simulatePropertyChange("user1", "LauncherItems", QVariant::fromValue(newList));
160+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
162+ // Now toggle onlyPinned and make sure the model keeps up
163+ model->setOnlyPinned(false);
164+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
166+ model->setOnlyPinned(true);
167+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
138QTEST_GUILESS_MAIN(LauncherModelASTest)
171QTEST_GUILESS_MAIN(LauncherModelASTest)