From 188b21026024cd79a2b6942f5d9d309fd7640371 Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Mon, 4 Jun 2018 22:42:30 +0200 Subject: Adapt JS tests to the latest logic. --- configure.ac | 13 ++++++++++++- js/test/main.js | 28 ++++++++++++++-------------- talerbackoffice/tests.py | 2 -- 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 @@ -38,10 +38,21 @@ AX_COMPARE_VERSION([$VERSION],[lt],[6.0], [AC_MSG_ERROR([Please install pip3>=6. 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() -- cgit v1.2.3