summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-06-04 22:42:30 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2018-06-04 22:42:30 +0200
commit188b21026024cd79a2b6942f5d9d309fd7640371 (patch)
tree0acf97e3b6042ed4b5b0a1cb1093784df21b6a97
parentf8cde3a2f689eec00d0a5f617542cff435ed860c (diff)
downloadbackoffice-188b21026024cd79a2b6942f5d9d309fd7640371.tar.gz
backoffice-188b21026024cd79a2b6942f5d9d309fd7640371.tar.bz2
backoffice-188b21026024cd79a2b6942f5d9d309fd7640371.zip
Adapt JS tests to the latest logic.
-rw-r--r--configure.ac13
-rw-r--r--js/test/main.js28
-rw-r--r--talerbackoffice/tests.py2
3 files changed, 26 insertions, 17 deletions
diff --git a/configure.ac b/configure.ac
index 934db2a..2eee4c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,9 +39,20 @@ AC_CHECK_PROG([tsc],[tsc],[yes],[no])
AM_CONDITIONAL([HAVE_TSC], [test "x$tsc" = xyes])
#
+# Check for Yarn
+#
+AC_MSG_CHECKING([Yarn])
+yarn --version &> /dev/null
+if test $? -ne 0;
+ then
+ AC_MSG_ERROR([Please install Yarn])
+fi
+
+
+#
# Check for minifier
#
-AC_MSG_CHECKING([Checking for jsmin])
+AC_MSG_CHECKING([jsmin])
python3 -m jsmin &> /dev/null
if test $? -ne 0;
then
diff --git a/js/test/main.js b/js/test/main.js
index d54f69f..ab02193 100644
--- a/js/test/main.js
+++ b/js/test/main.js
@@ -30,19 +30,27 @@ const ava = require("ava");
const sinon = require("sinon");
const pd = require("pretty-data");
+/* Adjusts context before each test.
+ * In practice, it (1) mocks the global XHR
+ * object, (2) nullifies addEventListener and
+ * getElementById, (3) makes alert dialogs
+ * appear as AVA logs, and (4) disables native
+ * browser logging. Finally, (5) it imports
+ * the code to be tested. */
ava.test.beforeEach(t => {
-
function xhr_mock() {
t.context.xhr = sinon.useFakeXMLHttpRequest();
t.context.requests = [];
t.context.xhr.onCreate = function(xhr){
t.context.requests.push(xhr);};
global.XMLHttpRequest = t.context.xhr;};
-
function minor_mocks() {
var document = {};
document.addEventListener = ()=>{};
- document.getElementById = ()=>{return {value: "mock"}};
+ document.getElementById = ()=>
+ /* pacifies code that attempts
+ * to change this property anyway. */
+ {return {style: {visibility: "hidden"}}};
global.document = document;
global.alert = console.log;
// disable logging for tests
@@ -53,12 +61,9 @@ ava.test.beforeEach(t => {
t.context.bo = require("../backoffice");
});
-ava.test.afterEach(t => {
- delete global.XMLHttpRequest;
- delete global.alert;
- delete t.context.xhr;
- delete t.context.requests;
-});
+/* Both of following tests just check that the callback
+ * which is in charge of modifying the page is called
+ * with the right arguments. */
ava.test("Tracking a wire transfer", (t) => {
var mock_tracks = {
@@ -78,11 +83,6 @@ ava.test("Tracking a wire transfer", (t) => {
ava.test("Tracking order id", t => {
- /**
- * This test case checks whether the 'overlay' element in the
- * page contains the expected tracks and it is made visible.
- */
-
var cb = sinon.spy();
t.context.bo.track_order(22, cb);
diff --git a/talerbackoffice/tests.py b/talerbackoffice/tests.py
index 4ed870b..d7b3949 100644
--- a/talerbackoffice/tests.py
+++ b/talerbackoffice/tests.py
@@ -38,8 +38,6 @@ class BackofficeTestCase(unittest.TestCase):
# check data is returned verbatim from the backend
self.assertEqual(response.data, b'{}\n')
-
-
@patch("requests.get")
def test_track_transfer(self, mocked_get):
ret = MagicMock()