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: mocking the homep


From: gnunet
Subject: [GNUnet-SVN] [taler-backoffice] branch master updated: mocking the homepage for JS tests
Date: Wed, 10 Jan 2018 17:15:47 +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 a34256e  mocking the homepage for JS tests
a34256e is described below

commit a34256eaf1e48659e728a146b876236335734c37
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Jan 10 17:15:20 2018 +0100

    mocking the homepage for JS tests
---
 js/backoffice.js                                   | 15 +++----
 js/package.json                                    |  2 +
 js/test/main.js                                    | 47 +++++++++++++++++++++-
 .../backoffice/templates/backoffice.html           |  2 +-
 4 files changed, 53 insertions(+), 13 deletions(-)

diff --git a/js/backoffice.js b/js/backoffice.js
index ed3792c..7382969 100644
--- a/js/backoffice.js
+++ b/js/backoffice.js
@@ -29,7 +29,6 @@ var FRACTION = 100000000;
 var TIMESTAMP = 0;
 var START = 0;
 var DELTA = 5
-var INSTANCE = null;
 var LAST = 0;
 
 function amount_to_string(amount){
@@ -109,7 +108,7 @@ function make_marker(wtid){
 function track_transfer(exchange, wtid){
   var loader = document.getElementsByClassName("loader")[0]; 
   loader.style.visibility = "visible";
-  var qs = 
`/track/transfer?exchange=${exchange}&wtid=${wtid}&instance=${INSTANCE}`;
+  var qs = 
`/track/transfer?exchange=${exchange}&wtid=${wtid}&instance=${get_instance()}`;
   var req = new XMLHttpRequest();
   req.open("GET", qs, true);
   req.onload = function(){
@@ -140,15 +139,15 @@ function track_transfer(exchange, wtid){
 
 function track_order(order_id){
   var req = new XMLHttpRequest();
-  req.open("GET", `/track/order?order_id=${order_id}&instance=${INSTANCE}`, 
true);
+  req.open("GET", 
`/track/order?order_id=${order_id}&instance=${get_instance()}`, true);
   req.onload = function(){
     if (4 == req.readyState){
       if(200 == req.status){
         var tracks = JSON.parse(req.responseText); 
         if(!tracks)
           console.log("Got invalid JSON");
-        if(0 == tracks.length){
-          console.log("Got no tracks AND status == 200.  Should not be here.");
+        if(0 == tracks.length || !tracks.length){
+          console.log("Got no tracks and status == 200.  Should not be here.");
           return;
         }
         for(var i=0; i<tracks.length; i++){
@@ -328,7 +327,6 @@ function clean_results(){
  * selected one.
  */
 function change_instance(){
-  INSTANCE = null;
   clean_results();
   get_history();
 }
@@ -338,12 +336,9 @@ function change_instance(){
  * "next page" of all the proposals known to the merchant.
  */
 function get_history(scroll){
-  if (!INSTANCE)
-    INSTANCE = get_instance();
-
   var loader = document.getElementsByClassName("loader")[0]; 
   loader.style.visibility = "visible";
-  var qs = `/history?instance=${INSTANCE}&delta=${DELTA}`;
+  var qs = `/history?instance=${get_instance()}&delta=${DELTA}`;
   if(scroll){
     START = LAST;
     qs += `&start=${START}`;
diff --git a/js/package.json b/js/package.json
index d183f63..d0d29d7 100644
--- a/js/package.json
+++ b/js/package.json
@@ -7,6 +7,8 @@
     "test": "echo \"Error: no test specified\" && exit 1"
   },
   "devDependencies": {
+    "jsdom": "^11.5.1",
+    "swig": "^1.4.2",
     "ava": "^0.24.0",
     "sinon": "^4.1.4"},
   "repository": {
diff --git a/js/test/main.js b/js/test/main.js
index 48a2510..b714a82 100644
--- a/js/test/main.js
+++ b/js/test/main.js
@@ -1,5 +1,35 @@
+/*
+  @licstart  The following is the entire license notice for the
+  JavaScript code in this page.
+
+  Copyright (C) 2018 Taler Systems SA.
+
+  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.
+
+  @licend  The above is the entire license notice for the
+  JavaScript code in this page.
+
+  @author Marcello Stanisci
+*/
+
 const ava = require("ava");
 const sinon = require("sinon");
+const swig = require("swig");
+const jsdom = require("jsdom");
 
 ava.test.beforeEach(t => {
   // Global XHR mock
@@ -11,8 +41,15 @@ ava.test.beforeEach(t => {
   global.XMLHttpRequest = t.context.xhr;
 
   // Global 'document' mock
-  global.document = {};
-  global.document.addEventListener = function(){};
+  var template = swig.compileFile(
+    __dirname + "/" + "../../" +
+    "talerbackoffice/backoffice/" +
+    "templates/backoffice.html");
+  var html = template({instances: ["mock-instance"]});
+  // fixme: 'document' must be a *parsed* DOM!
+  var dom = new jsdom.JSDOM(html);
+  dom.window.document.addEventListener = function(){};
+  global.document = dom.window.document;
   global.alert = console.log;
 
   // Load back-office code (slows down..)
@@ -29,6 +66,12 @@ ava.test.afterEach(t => {
   delete t.context.requests;
 });
 
+ava.test("Tracking order id", (t) => {
+  t.context.bo.track_order(22);
+  t.context.requests[0].respond(200, "application/json", "{}");
+  t.pass();
+});
+
 ava.test("Order id not found", (t) => {
   /**
    * FIXME: improve the reaction to a order id not found.
diff --git a/talerbackoffice/backoffice/templates/backoffice.html 
b/talerbackoffice/backoffice/templates/backoffice.html
index 6c4a21e..873c961 100644
--- a/talerbackoffice/backoffice/templates/backoffice.html
+++ b/talerbackoffice/backoffice/templates/backoffice.html
@@ -1,4 +1,4 @@
-{% extends "templates/base.html" %}
+{% extends "base.html" %}
 {% block main %}
   <h1>Backoffice</h1>
   <p>This page simulates a backoffice facility.  Through it,

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



reply via email to

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