@@ -27,7 +27,7 @@
2727
2828#include <QtTest>
2929
30−QList<QVariantMap> properties;
30+QHash<QString, QList<QVariantMap>> mockProperties;
3131
3232class LauncherModelASTest : public QObject
3333{
@@ -47,22 +47,30 @@ private Q_SLOTS:
4747 item.insert("icon", "fake.svg");
4848 item.insert("count", 0);
4949 item.insert("countVisible", false);
50+ item.insert("pinned", true);
5051 list.append(item);
5152 item["id"] = "appId2";
5253 item["name"] = "Item 2";
5354 list.append(item);
54− properties = list;
55+ mockProperties["user1"] = list;
5556 }
5657
57− bool isInSync(LauncherModel *model) {
58− // Verify after startup the items are in there
59− bool inSync = model->rowCount() == properties.count();
60− for (int i = 0; i < model->rowCount(); i++) {
61− inSync &= model->get(i)->appId() == properties.at(i).value("id").toString();
62− inSync &= model->get(i)->name() == properties.at(i).value("name").toString();
63− inSync &= model->get(i)->icon() == properties.at(i).value("icon").toString();
64− inSync &= model->get(i)->count() == properties.at(i).value("count").toInt();
65− inSync &= model->get(i)->countVisible() == properties.at(i).value("countVisible").toBool();
58+ bool isInSync(LauncherModel *model, const QList<QVariantMap> &properties) {
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()) {
63+ list << map;
64+ }
65+ }
66+
67+ bool inSync = model->rowCount() == list.count();
68+ for (int i = 0; inSync && i < model->rowCount(); i++) {
69+ inSync &= model->get(i)->appId() == list.at(i).value("id").toString();
70+ inSync &= model->get(i)->name() == list.at(i).value("name").toString();
71+ inSync &= model->get(i)->icon() == list.at(i).value("icon").toString();
72+ inSync &= model->get(i)->count() == list.at(i).value("count").toInt();
73+ inSync &= model->get(i)->countVisible() == list.at(i).value("countVisible").toBool();
6674 }
6775 return inSync;
6876 }
@@ -74,9 +82,9 @@ private Q_SLOTS:
7482 // We didn't set a user yet. model should be empty
7583 QCOMPARE(model->rowCount(), 0);
7684
77− model->setUser("dummy");
85+ model->setUser("user1");
7886
79− QCOMPARE(isInSync(model), true);
87+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
8088 model->deleteLater();
8189 }
8290
@@ -85,8 +93,8 @@ private Q_SLOTS:
8593 QTest::addColumn<QString>("changedUser");
8694 QTest::addColumn<bool>("inSync");
8795
88− QTest::newRow("this user changed") << "dummy" << "dummy" << true;
89− QTest::newRow("other user changed") << "dummy" << "fred" << false;
96+ QTest::newRow("this user changed") << "user1" << "user1" << true;
97+ QTest::newRow("other user changed") << "user1" << "user2" << false;
9098 }
9199
92100 void testASChangedUpdatesModel() {
@@ -97,42 +105,67 @@ private Q_SLOTS:
97105 LauncherModel* model = new LauncherModel(this);
98106 model->setUser(modelUser);
99107
100− int oldCount = properties.count();
108+ int oldCount = mockProperties[modelUser].count();
101109 QCOMPARE(model->rowCount(), oldCount);
102110
103− QList<QVariantMap> newList = properties;
111+ QList<QVariantMap> newList;
104112 QVariantMap newEntry;
105113 newEntry.insert("id", "newappId");
106114 newEntry.insert("name", "New app");
107115 newEntry.insert("icon", "some-icon.svg");
108116 newEntry.insert("count", 0);
109117 newEntry.insert("countVisible", false);
118+ newEntry.insert("pinned", true);
110119 newList.append(newEntry);
111120 model->m_accounts->simulatePropertyChange(changedUser, "LauncherItems", QVariant::fromValue(newList));
112121
113− QCOMPARE(isInSync(model), inSync);
122+ QCOMPARE(isInSync(model, mockProperties[modelUser]), true);
123+ QCOMPARE(isInSync(model, mockProperties[changedUser]), inSync);
114124
115125 model->deleteLater();
116126 }
117127
118128 void testUpdateCount() {
119129 LauncherModel* model = new LauncherModel(this);
120− model->setUser("dummy");
130+ model->setUser("user1");
121131
122132 QCOMPARE(model->get(0)->countVisible(), false);
123133 QCOMPARE(model->get(0)->count(), 0);
124134
125− QList<QVariantMap> newList = properties;
135+ QList<QVariantMap> newList = mockProperties["user1"];
126136 QVariantMap entry = newList.at(0);
127137 entry["countVisible"] = true;
128138 entry["count"] = 55;
129139 newList[0] = entry;
130− model->m_accounts->simulatePropertyChange("dummy", "LauncherItems", QVariant::fromValue(newList));
140+ model->m_accounts->simulatePropertyChange("user1", "LauncherItems", QVariant::fromValue(newList));
131141
132− QCOMPARE(isInSync(model), true);
142+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
133143
134144 model->deleteLater();
135145 }
146+
147+ void testOnlyPinned() {
148+ LauncherModel *model = new LauncherModel(this);
149+ model->setUser("user1");
150+ model->setOnlyPinned(true);
151+
152+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
153+
154+ // Let's unpin one item
155+ QList<QVariantMap> newList = mockProperties["user1"];
156+ QVariantMap entry = newList.at(0);
157+ entry["pinned"] = false;
158+ newList[0] = entry;
159+ model->m_accounts->simulatePropertyChange("user1", "LauncherItems", QVariant::fromValue(newList));
160+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
161+
162+ // Now toggle onlyPinned and make sure the model keeps up
163+ model->setOnlyPinned(false);
164+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
165+
166+ model->setOnlyPinned(true);
167+ QCOMPARE(isInSync(model, mockProperties["user1"]), true);
168+ }
136169};
137170
138171QTEST_GUILESS_MAIN(LauncherModelASTest)