Browse Source

copy JS test files from old JSON-128 branch

JSON-192
roker 3 months ago
parent
commit
cb33137c85
3 changed files with 87 additions and 1 deletions
  1. +14
    -1
      html/index.html
  2. +32
    -0
      html/test-encode-decode.js
  3. +41
    -0
      html/unittests.js

+ 14
- 1
html/index.html View File

@ -6,10 +6,13 @@
<title>Send example calls via jQuery</title>
<style type="text/css">
body { font-family:Helvetica,Arial,Sans-serif;background-color:#cde; }
table { border-collapse:collapse; }
.bigtable { border-collapse:collapse; border:2px black solid; box-shadow:4px 4px 8px #666; background-color:#ffd; margin:1em;}
td, th { border:1px black solid; vertical-align:top; padding:0.5em;}
td.right { border:0px black solid; float:right; }
td.left { border:0px black solid; align:left; }
tr.t { border-bottom:1px black solid; }
.t td,th { border:0px black solid; }
input { white-space:pre }
.smalltable { border-collapse:collapse; border:2px black inset; margin-left:1em; padding:5px;}
.smalltable td { border:none; vertical-align:top; padding:5px;}
@ -19,6 +22,8 @@
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="pEp_functions.js"></script>
<script type="text/javascript" src="interactive.js"></script>
<script type="text/javascript" src="unittests.js"></script>
<script type="text/javascript" src="test-encode-decode.js"></script>
</head>
<body>
@ -53,7 +58,14 @@
</textarea>
</form>
<hr>
<h2>2. Generate documentation</h2>
<h2>2. Open WebSocket connection</h2>
<input type="button" onClick="openWebSocket()" id="openWsBtn" value="Open WebSocket!">
<hr>
<h2>3. Execute JavaScript tests</h2>
<p id='unittest_div'>(you have to activate JavaScript in your browser to see something useful here)</p>
<p>Unittest output: <textarea id='unittest_out'></textarea></p>
<hr>
<h2>4. Generate documentation</h2>
<form id="frm_doc" name="frm_doc">
Select output format:
<select id="doc_format" size="1">
@ -69,6 +81,7 @@
<script type="text/javascript">
init_pEp_functions();
on_select_change();
add_test_buttons();
</script>
</body>


+ 32
- 0
html/test-encode-decode.js View File

@ -0,0 +1,32 @@
"use strict";
async function test_encode_decode()
{
var out = document.getElementById('unittest_out');
var rndName = gen_random_name();
var testAddress = 'enc-dec-test.' + rndName + '@peptest.ch';
var testUsername = 'Test User ' + rndName;
var identity = { "address": testAddress, "user_id": "pEp_own_userId", "username": testUsername };
var ret = await call_json_rpc_function("myself", [identity] );
var newIdent = ret.result.outParams[0];
var fpr = newIdent.fpr;
out.innerHTML = JSON.stringify(newIdent, null, 2);
var msg1 = {
"id":"<pEp." + gen_random_name() + "." + gen_random_name() + "@peptest.ch>",
"shortmsg": "Subject",
"longmsg": "Body",
"attachments": [],
"from": identity,
"to": [ identity ]
};
ret = await call_json_rpc_function("encrypt_message", [msg1, null, "out", 3, 0] );
out.innerHTML += "\n=========\n" + JSON.stringify(ret, null, 2);
await call_json_rpc_function("delete_keypair", [fpr] );
}
unittests.push( {"description": "Encode/Decode", "onclick":"test_encode_decode()" } );

+ 41
- 0
html/unittests.js View File

@ -0,0 +1,41 @@
'use strict';
// all unittests will add themselves here:
var unittests =
[
{"description":"call gen_random_name()", "onclick":"random_name_test()" }
];
var base32_alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
// creates a string of 12 random letters
function gen_random_name()
{
var rndArray = new Uint32Array(12);
window.crypto.getRandomValues(rndArray);
var s = '';
for(var i=0; i<rndArray.length; ++i)
{
s += base32_alphabet[ rndArray[i] % (base32_alphabet.length-1) ];
}
return s;
}
function add_test_buttons()
{
var content = '<table><tr class="t"><th></th><th>Test name</th><th></th></tr>\n';
for(var i=0; i<unittests.length; ++i)
{
var u = unittests[i];
content += '<tr class="t"><td>#' + (i+1) + '</td><td>' + u.description + '</td>'
+ '<td><button type="button" onclick="' + u.onclick + '"> Run! </button></td></tr>\n';
}
content += '</table>';
document.getElementById('unittest_div').innerHTML = content;
}
function random_name_test()
{
document.getElementById('unittest_out').innerHTML = 'pEp_' + gen_random_name() + '@pep.lol';
}

Loading…
Cancel
Save