on xenial help sign in
Replace the old mocks for the notification-qml-tests... make the SwipeToAct widget-test pass.
commitbb75bba73d1cfb76aa6c850285838593826042a7 authorMirco Müller <mirco.mueller@canonical.com> dateThu 23 Oct 2014, 18:01 (12 years ago) parent71c42ed
11 files changed+281−33
cmake/modules/QmlTest.cmake+1−1 tests/mocks/Unity/Notifications/CMakeLists.txt+15−1 tests/mocks/Unity/Notifications/MockActionModel.cpp+72 tests/mocks/Unity/Notifications/MockActionModel.h+51 tests/mocks/Unity/Notifications/MockNotificationTypes.cpp+26 tests/mocks/Unity/Notifications/MockNotificationTypes.h+36 tests/mocks/Unity/Notifications/notification.js−23 tests/mocks/Unity/Notifications/plugin.cpp+31 tests/mocks/Unity/Notifications/plugin.h+35 tests/mocks/Unity/Notifications/qmldir+2−1 tests/qmltests/Notifications/tst_Notifications.qml+12−7
cmake/modules/QmlTest.cmake+1−1
@@ -118,7 +118,7 @@ macro(add_qml_test_internal SUBPATH COMPONENT_NAME ITERATIONS)
118118
119119 set(qmltest_command
120120 env ${test_env} ${qmltest_ENVIRONMENT}
121− ${qmltestrunner_exe} -eventdelay 500 -input ${CMAKE_CURRENT_SOURCE_DIR}/${qmltest_FILE}.qml
121+ ${qmltestrunner_exe} -input ${CMAKE_CURRENT_SOURCE_DIR}/${qmltest_FILE}.qml
122122 ${qmltestrunner_imports}
123123 ${ITERATIONS_STRING}
124124 -o ${CMAKE_BINARY_DIR}/${qmltest_TARGET}.xml,xunitxml
tests/mocks/Unity/Notifications/CMakeLists.txt+15−1
@@ -1 +1,15 @@
1−add_unity8_mock(Unity.Notifications 1.0 Unity/Notifications)
1+include_directories(
2+ ${CMAKE_CURRENT_SOURCE_DIR}
3+)
4+
5+set(MockNotificationsPlugin_SOURCES
6+ plugin.cpp
7+ MockNotificationTypes.cpp
8+ MockActionModel.cpp
9+)
10+
11+add_library(MockNotificationsPlugin MODULE ${MockNotificationsPlugin_SOURCES})
12+
13+qt5_use_modules(MockNotificationsPlugin Core Quick)
14+
15+add_unity8_mock(Unity.Notifications 1.0 Unity/Notifications TARGETS MockNotificationsPlugin)
tests/mocks/Unity/Notifications/MockActionModel.cppnew file+72
@@ -0,0 +1,72 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Mirco Mueller <mirco.mueller@canonical.com>
18+ */
19+
20+#include "MockActionModel.h"
21+
22+struct ActionModelPrivate {
23+ QList<QString> labels;
24+ QList<QString> ids;
25+};
26+
27+ActionModel::ActionModel(QObject *parent) : QStringListModel(parent), p(new ActionModelPrivate) {
28+ insertAction("ok_id", "Ok");
29+ insertAction("cancel_id", "Cancel");
30+}
31+
32+ActionModel::~ActionModel() {
33+}
34+
35+int ActionModel::rowCount(const QModelIndex &index) const {
36+ return p->labels.size();
37+}
38+
39+QVariant ActionModel::data(const QModelIndex &index, int role) const {
40+ if (!index.isValid())
41+ return QVariant();
42+
43+ switch(role) {
44+ case RoleActionLabel:
45+ return QVariant(p->labels[index.row()]);
46+
47+ case RoleActionId:
48+ return QVariant(p->ids[index.row()]);
49+
50+ default:
51+ return QVariant();
52+ }
53+}
54+
55+QHash<int, QByteArray> ActionModel::roleNames() const {
56+ QHash<int, QByteArray> roles;
57+
58+ roles.insert(RoleActionLabel, "label");
59+ roles.insert(RoleActionId, "id");
60+
61+ return roles;
62+}
63+
64+Q_INVOKABLE QVariant ActionModel::data(int row, int role) const
65+{
66+ return data(index(row, 0), role);
67+}
68+
69+void ActionModel::insertAction(const QString &id, const QString &label) {
70+ p->ids.push_back(id);
71+ p->labels.push_back(label);
72+}
tests/mocks/Unity/Notifications/MockActionModel.hnew file+51
@@ -0,0 +1,51 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Mirco Mueller <mirco.mueller@canonical.com>
18+ */
19+
20+#ifndef MOCK_ACTION_MODEL_H
21+#define MOCK_ACTION_MODEL_H
22+
23+#include <QStringListModel>
24+
25+struct ActionModelPrivate;
26+
27+class ActionModel : public QStringListModel {
28+ Q_OBJECT
29+
30+public:
31+ ActionModel(QObject *parent=nullptr);
32+ virtual ~ActionModel();
33+
34+ virtual int rowCount(const QModelIndex &index) const;
35+ virtual QVariant data(const QModelIndex &index, int role) const;
36+ virtual QHash<int, QByteArray> roleNames() const;
37+
38+ Q_ENUMS(ActionsRoles)
39+ enum ActionsRoles {
40+ RoleActionLabel = Qt::UserRole + 1,
41+ RoleActionId = Qt::UserRole + 2
42+ };
43+ Q_INVOKABLE QVariant data(int row, int role) const;
44+
45+ void insertAction(const QString &id, const QString &label);
46+
47+private:
48+ QScopedPointer<ActionModelPrivate> p;
49+};
50+
51+#endif // MOCK_ACTION_MODEL_H
tests/mocks/Unity/Notifications/MockNotificationTypes.cppnew file+26
@@ -0,0 +1,26 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Mirco Mueller <mirco.mueller@canonical.com>
18+ */
19+
20+#include "MockNotificationTypes.h"
21+
22+MockNotification::MockNotification(QObject *parent) : QObject(parent) {
23+}
24+
25+MockNotification::~MockNotification() {
26+}
tests/mocks/Unity/Notifications/MockNotificationTypes.hnew file+36
@@ -0,0 +1,36 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Mirco Mueller <mirco.mueller@canonical.com>
18+ */
19+
20+#ifndef MOCK_NOTIFICATION_TYPES_H
21+#define MOCK_NOTIFICATION_TYPES_H
22+
23+#include <QObject>
24+
25+class MockNotification : public QObject {
26+ Q_OBJECT
27+ Q_ENUMS(Type)
28+
29+public:
30+ MockNotification(QObject *parent=nullptr);
31+ virtual ~MockNotification();
32+
33+ enum Type { PlaceHolder, Confirmation, Ephemeral, Interactive, SnapDecision };
34+};
35+
36+#endif // MOCK_NOTIFICATION_TYPES_H
tests/mocks/Unity/Notifications/notification.jsdeleted−23
@@ -1,23 +0,0 @@
1−/*
2− * Copyright (C) 2013 Canonical, Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−.pragma library
18−
19−var Confirmation = 0;
20−var Ephemeral = 1;
21−var Interactive = 2;
22−var SnapDecision = 3;
23−var PlaceHolder = 4;
tests/mocks/Unity/Notifications/plugin.cppnew file+31
@@ -0,0 +1,31 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Mirco Mueller <mirco.mueller@canonical.com>
18+ */
19+
20+#include "plugin.h"
21+#include "MockActionModel.h"
22+#include "MockNotificationTypes.h"
23+
24+#include <QtQml/qqml.h>
25+
26+void TestNotificationPlugin::registerTypes(const char* uri)
27+{
28+ // @uri Unity.Notifications
29+ qmlRegisterUncreatableType<MockNotification>(uri, 1, 0, "Notification", "Notification objects can only be created by the plugin");
30+ qmlRegisterType<ActionModel>(uri, 1, 0, "ActionModel");
31+}
tests/mocks/Unity/Notifications/plugin.hnew file+35
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright 2014 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Mirco Mueller <mirco.mueller@canonical.com>
18+ */
19+
20+
21+#ifndef TESTNOTIFICATION_PLUGIN_H
22+#define TESTNOTIFICATION_PLUGIN_H
23+
24+#include <QtQml/QQmlExtensionPlugin>
25+
26+class TestNotificationPlugin : public QQmlExtensionPlugin
27+{
28+ Q_OBJECT
29+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
30+
31+public:
32+ void registerTypes(const char* uri);
33+};
34+
35+#endif // TESTNOTIFICATION_PLUGIN_H
tests/mocks/Unity/Notifications/qmldir+2−1
@@ -1,3 +1,4 @@
11module Unity.Notifications
2−Notification 1.0 notification.js
2+plugin MockNotificationsPlugin
33typeinfo Notifications.qmltypes
4+
tests/qmltests/Notifications/tst_Notifications.qml+12−7
@@ -42,6 +42,7 @@ Item {
4242
4343 ListModel {
4444 id: mockModel
45+ dynamicRoles: true
4546
4647 signal actionInvoked(string actionId)
4748
@@ -92,7 +93,7 @@ Item {
9293 icon: "../graphics/avatars/amanda.png",
9394 secondaryIcon: "incoming-call",
9495 actions: [{ id: "ok_id", label: "Ok"},
95− { id: "cancel_id", label: "Cancel"}]
96+ { id: "cancel_id", label: "Cancel"}]
9697 }
9798
9899 mockModel.append(n)
@@ -266,6 +267,10 @@ Item {
266267 }
267268 }
268269
270+ ActionModel {
271+ id: myActionModel
272+ }
273+
269274 UnityTestCase {
270275 id: root
271276 name: "NotificationRendererTest"
@@ -305,8 +310,7 @@ Item {
305310 body: "Frank Zappa\n+44 (0)7736 027340",
306311 icon: "../graphics/avatars/amanda.png",
307312 secondaryIcon: "../graphics/applicationIcons/facebook.png",
308− actions: [{ id: "ok_id", label: "Ok"},
309− { id: "cancel_id", label: "Cancel"}],
313+ actions: myActionModel,
310314 summaryVisible: true,
311315 bodyVisible: true,
312316 iconVisible: true,
@@ -536,12 +540,13 @@ Item {
536540 if(data.hasSwipeToAct) {
537541 var swipeButton = findChild(buttonRow, "notify_swipe_button")
538542 var slider = findChild(swipeButton, "slider")
539− var swipeMouseArea = findChild(buttonRow, "swipeMouseArea")
543+ var swipeMouseArea = findChild(swipeButton, "swipeMouseArea")
540544 var x = swipeMouseArea.width / 2
541545 var y = swipeMouseArea.height / 2
542− mousePress(swipeMouseArea, x, y, Qt.LeftButton, Qt.NoModifier, 0)
543− mouseMove(swipeMouseArea, x + units.gu(15), y)
544− mouseRelease(swipeMouseArea, x + units.gu(15), y)
546+ //mouseDrag(swipeButton, x, y, -(swipeMouseArea.width / 2), 0)
547+ tryCompareFunction(function() { mouseDrag(slider, x, y, (swipeMouseArea.width / 2) - slider.width, 0); return actionSpy.signalArguments.length > 0; }, true);
548+ compare(actionSpy.signalArguments[0][0], data.actions.data(1, ActionModel.RoleActionId), "got wrong id for positive action")
549+ actionSpy.clear()
545550 } else {
546551 var buttonCancel = findChild(buttonRow, "notify_button1")
547552 var buttonAccept = findChild(buttonRow, "notify_button0")