Add spinner to the checkup page and test websockets

pull/1/head
yflory 4 years ago
parent d43cb509dc
commit b0e0a8dc75

@ -20,6 +20,12 @@ html, body {
padding-top: 15px;
}
.pending {
border: 1px solid white;
.fa {
margin-right: 20px;
}
}
.success {
border: 1px solid green;
}

@ -21,8 +21,10 @@ define([], function () {
});
};
assert.run = function (cb) {
assert.run = function (cb, progress) {
progress = progress || function () {};
var count = ASSERTS.length;
var total = ASSERTS.length;
var done = function (err) {
count--;
if (err) { failMessages.push(err); }
@ -38,6 +40,7 @@ define([], function () {
ASSERTS.forEach(function (f, index) {
f(function (err) {
//console.log("test " + index);
progress(index, total);
done(err, index);
}, index);
});

@ -6,5 +6,6 @@
<script data-bootload="main.js" data-main="/common/boot.js" src="/bower_components/requirejs/require.js"></script>
</head>
<body>
<div id="cp-progress"></div>
<iframe-placeholder>

@ -11,12 +11,15 @@ define([
'/common/common-hash.js',
'/common/common-util.js',
'/common/pinpad.js',
'/common/outer/network-config.js',
'/bower_components/netflux-websocket/netflux-client.js',
'/bower_components/tweetnacl/nacl-fast.min.js',
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
'less!/customize/src/less2/pages/page-checkup.less',
], function ($, ApiConfig, Assertions, h, Messages, DomReady,
nThen, SFCommonO, Login, Hash, Util, Pinpad) {
nThen, SFCommonO, Login, Hash, Util, Pinpad,
NetConfig, Netflux) {
var assert = Assertions();
var trimSlashes = function (s) {
@ -77,7 +80,28 @@ define([
});
}, _alert("Sandbox domain is not available"));
// Write/ready access to /block/
// Test Websocket
var evWSError = Util.mkEvent(true);
assert(function (cb) {
var ws = new WebSocket(NetConfig.getWebsocketURL());
var to = setTimeout(function () {
console.error('Websocket TIMEOUT');
evWSError.fire();
cb('TIMEOUT (5 seconds)');
}, 5000);
ws.onopen = function () {
clearTimeout(to);
cb(true);
};
ws.onerror = function (err) {
clearTimeout(to);
console.error('Websocket error', err);
evWSError.fire();
cb('WebSocket error: check your console');
};
}, _alert("Websocket is not available"));
// Test login block
assert(function (cb) {
var bytes = new Uint8Array(Login.requiredBytes);
@ -101,6 +125,11 @@ define([
exists = true;
}));
}).nThen(function (waitFor) {
// If WebSockets aren't working, don't wait forever here
evWSError.reg(function () {
waitFor.abort();
cb("No WebSocket (test number 6)");
});
// Create proxy
Login.loadUserObject(opt, waitFor(function (err, rt) {
if (err) {
@ -167,7 +196,7 @@ define([
cb(true);
});
}, _alert("Login Block is not working (write/read/remove)"));
}, _alert("Login block is not working (write/read/remove)"));
var row = function (cells) {
return h('tr', cells.map(function (cell) {
@ -185,6 +214,8 @@ define([
]);
};
var completed = 0;
var $progress = $('#cp-progress');
assert.run(function (state) {
var errors = state.errors;
var failed = errors.length;
@ -206,6 +237,17 @@ define([
h('div.failures', errors.map(failureReport)),
]);
$progress.remove();
$('body').prepend(report);
}, function (i, total) {
console.log('test '+ i +' completed');
completed++;
Messages.assert_numberOfTestsCompleted = "{0} / {1} tests completed.";
$progress.html('').append(h('div.report.pending.summary', [
h('p', [
h('i.fa.fa-spinner.fa-pulse'),
h('span', Messages._getKey('assert_numberOfTestsCompleted', [completed, total]))
])
]));
});
});

Loading…
Cancel
Save