summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-06-18 20:42:29 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-06-26 12:17:30 +0200
commitcdb42f0d6b47a60ceb647e3ac6a6ce66352dbae4 (patch)
tree40f76de30181eb1036d44516e5dd05488c8c31dc /tests
parent4de5748e25678dce9c5a344afc5fd40508c0860f (diff)
[test] minimal qml tests
just a minimal boilerplate. the idea is to import the qml files and assert that the states/widgets change accordingly if we mock the backend status. - Closes: #300
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore10
-rw-r--r--tests/test_ui.cpp52
-rw-r--r--tests/tst_smoke.qml28
3 files changed, 90 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..65af933
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,10 @@
+build/*
+*.h
+*.sh
+*.moc
+*.o
+*.stash
+Makefile
+test_ui
+moc_handlers.cpp
+moc_qjsonmodel.cpp
diff --git a/tests/test_ui.cpp b/tests/test_ui.cpp
new file mode 100644
index 0000000..f9f960a
--- /dev/null
+++ b/tests/test_ui.cpp
@@ -0,0 +1,52 @@
+// test_ui.cpp
+#include <QtQuickTest>
+#include <QQmlEngine>
+#include <QQmlContext>
+
+#include "../gui/qjsonmodel.h"
+#include "../lib/libgoshim.h"
+
+class Helper : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit Helper(QObject *parent = 0);
+
+public slots:
+ Q_INVOKABLE QString refreshContext();
+};
+
+Helper::Helper(QObject *parent) : QObject(parent)
+{
+}
+
+Q_INVOKABLE QString Helper::refreshContext()
+{
+ return QString(RefreshContext());
+}
+
+class Setup : public QObject
+{
+ Q_OBJECT
+
+public:
+ Setup() {}
+
+public slots:
+ void qmlEngineAvailable(QQmlEngine *engine)
+ {
+ QQmlContext *ctx = engine->rootContext();
+ QJsonModel *model = new QJsonModel;
+ Helper *helper = new Helper(this);
+
+ InitializeTestBitmaskContext();
+
+ ctx->setContextProperty("jsonModel", model);
+ ctx->setContextProperty("helper", helper);
+ }
+};
+
+QUICK_TEST_MAIN_WITH_SETUP(ui, Setup)
+
+#include "test_ui.moc"
diff --git a/tests/tst_smoke.qml b/tests/tst_smoke.qml
new file mode 100644
index 0000000..19904a6
--- /dev/null
+++ b/tests/tst_smoke.qml
@@ -0,0 +1,28 @@
+import QtQuick 2.3
+import QtTest 1.0
+
+
+TestCase {
+ name: "SmokeTests"
+
+ property var ctx
+
+ function refresh() {
+ ctx = JSON.parse(helper.refreshContext())
+ }
+
+ function test_helper() {
+ compare(Boolean(helper), true, "does helper exist?")
+ }
+
+ function test_model() {
+ compare(Boolean(jsonModel), true, "does model exist?")
+ }
+
+ function test_loadCtx() {
+ refresh()
+ compare(ctx.appName, "RiseupVPN", "can read appName?")
+ compare(ctx.tosURL, "https://riseup.net/tos", "can read tosURL?")
+ compare(ctx.status, "off", "is initial status off?")
+ }
+}