gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-backoffice] branch master updated: checking /track/t


From: gnunet
Subject: [GNUnet-SVN] [taler-backoffice] branch master updated: checking /track/transaction rendereing from the JS
Date: Thu, 11 Jan 2018 12:39:40 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository backoffice.

The following commit(s) were added to refs/heads/master by this push:
     new cba3fa0  checking /track/transaction rendereing from the JS
cba3fa0 is described below

commit cba3fa0f0280c6bc4a79c4a6233a9f7a47906a03
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Jan 11 12:39:17 2018 +0100

    checking /track/transaction rendereing from the JS
---
 js/backoffice.js | 46 ++++++++++++++++++++++++++++++++--------------
 js/package.json  |  2 ++
 js/test/main.js  | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 78 insertions(+), 16 deletions(-)

diff --git a/js/backoffice.js b/js/backoffice.js
index 7382969..1c1b1fa 100644
--- a/js/backoffice.js
+++ b/js/backoffice.js
@@ -6,17 +6,19 @@
 
   The JavaScript code in this page is free software: you can
   redistribute it and/or modify it under the terms of the GNU
-  Lesser General Public License (GNU LGPL) as published by the Free Software
-  Foundation, either version 2.1 of the License, or (at your option)
-  any later version.  The code is distributed WITHOUT ANY WARRANTY;
-  without even the implied warranty of MERCHANTABILITY or FITNESS
-  FOR A PARTICULAR PURPOSE.  See the GNU LGPL for more details.
-
-  As additional permission under GNU LGPL version 2.1 section 7, you
-  may distribute non-source (e.g., minimized or compacted) forms of
-  that code without the copy of the GNU LGPL normally required by
-  section 4, provided you include this license notice and a URL
-  through which recipients can access the Corresponding Source.
+  Lesser General Public License (GNU LGPL) as published by the
+  Free Software Foundation, either version 2.1 of the License, or
+  (at your option) any later version.  The code is distributed
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU LGPL for more details.
+
+  As additional permission under GNU LGPL version 2.1 section 7,
+  you may distribute non-source (e.g., minimized or compacted)
+  forms of that code without the copy of the GNU LGPL normally
+  required by section 4, provided you include this license notice
+  and a URL through which recipients can access the Corresponding
+  Source.
 
   @licend  The above is the entire license notice
   for the JavaScript code in this page.
@@ -31,10 +33,17 @@ var START = 0;
 var DELTA = 5
 var LAST = 0;
 
+/**
+ * This function *could* "type check" 'amount',
+ * but once 'amount' got here it is already "too late",
+ * because this means that the merchant *backend* gave
+ * it wrong.
+ */
 function amount_to_string(amount){
   var number = Number(amount.value) + (Number(amount.fraction)/FRACTION);
   return `${number.toFixed(2)} ${amount.currency}`;
 }
+module.exports.amount_to_string = amount_to_string;
 
 function close_popup(){
 
@@ -64,10 +73,13 @@ function amount_sum(a1, a2){
 
 function parse_date(date){
 
-  var split = date.match(/Date\((.*)\)/);
+  var split = date.match(/Date\(([0-9]+)\)/);
+  if (!split){
+    console.error("Malformed date gotten from backend");
+  }
   var seconds;
   if(isNaN(seconds = Number(split[1]))){
-    console.error("Malformed date gotten from backend");
+    console.error("Malformed date: no secs given");
     return;
   }
   var d = new Date(seconds * 1000);
@@ -152,6 +164,12 @@ function track_order(order_id){
         }
         for(var i=0; i<tracks.length; i++){
           var entry = tracks[i];
+          /**
+           * 'track_content' contains the tracks (WTID/Amount/Date) about
+           * *one* order.  It is contained in the 'overlay', which renders
+           * it in a "box" in the middle of the screen.  This "box" is then
+           * toggleable as visible/hidden.
+           */
           var overlay = document.getElementsByClassName("overlay")[0];
           var track_content = 
document.getElementsByClassName("track-content")[0];
           var table = document.evaluate("table/tbody",
@@ -164,7 +182,7 @@ function track_order(order_id){
           console.log("Subject", subject);
 
           row.innerHTML = `<td class="wtid">
-                             <a onclick='track_transfer("${entry.exchange}", 
"${entry.wtid}")'
+                             <a 
onclick="track_transfer(\'${entry.exchange_url}\', \'${entry.wtid}\')"
                                 href="#${i}">${subject.substring(0, 20)}...</a>
                            </td> 
                            <td 
class="amount">${amount_to_string(entry.amount)}</td>
diff --git a/js/package.json b/js/package.json
index d0d29d7..454daff 100644
--- a/js/package.json
+++ b/js/package.json
@@ -7,6 +7,8 @@
     "test": "echo \"Error: no test specified\" && exit 1"
   },
   "devDependencies": {
+    "pretty-data": "^0.40.0",
+    "xpath": "^0.0.27",
     "jsdom": "^11.5.1",
     "swig": "^1.4.2",
     "ava": "^0.24.0",
diff --git a/js/test/main.js b/js/test/main.js
index 2d6d618..13ec0d5 100644
--- a/js/test/main.js
+++ b/js/test/main.js
@@ -30,6 +30,8 @@ const ava = require("ava");
 const sinon = require("sinon");
 const swig = require("swig");
 const jsdom = require("jsdom");
+const xpath = require("xpath");
+const pd = require("pretty-data");
 
 ava.test.beforeEach(t => {
 
@@ -52,6 +54,9 @@ ava.test.beforeEach(t => {
 
   function minor_mocks() {
     global.alert = console.log;
+    global.XPathResult = xpath.XPathResult;
+    // disable logging for tests
+    global.console.log = function(){};
   };
 
   xhr_mock();
@@ -70,9 +75,46 @@ ava.test.afterEach(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.
+   */
+
   t.context.bo.track_order(22);
-  t.context.requests[0].respond(200, "application/json", "{}");
-  t.pass();
+
+  // mocking a "/track/transaction" response from the backend
+  var mock_tracks = [
+    {wtid: "mock wtid",
+     exchange_url: "http://exchange.mock/";,
+     amount: {value: 2, fraction: 0, currency: "MOCK"},
+     execution_time: "mock /Date(0)/"}];
+
+  t.context.requests[0].respond
+    (200, "application/json",
+     JSON.stringify(mock_tracks));
+
+  var overlay = document.getElementById("popup1");
+  t.true(overlay.style.visibility == "visible");
+
+  var rendered_tracks = document.evaluate
+    ("div/div/table/tbody/tr[2]",
+     overlay,
+     null,
+     XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
+     null).snapshotItem(0);
+  var expected_html =
+    "<tr>" +
+      "<td class=\"wtid\">" +
+        "<a onclick=\"track_transfer('http://exchange.mock/', " +
+                                    "'mock wtid')\" " +
+           "href=\"#0\">mock wtid http://exc...</a>" +
+      "</td>" +
+      "<td class=\"amount\">2.00 MOCK</td>" +
+      "<td class=\"date\">1 Jan 1970, 01:00</td>" +
+      "</tr>";
+
+  t.true(pd.pd.xmlmin(rendered_tracks.outerHTML) == expected_html);
 });
 
 ava.test("Order id not found", (t) => {

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]