bashoto-js
Version:
Bashoto Javascript client
128 lines (117 loc) • 5.35 kB
HTML
<html>
<head>
<link href="qunit/qunit.css" rel="stylesheet" type="text/css" />
<script src="qunit/qunit.js"></script>
<!-- Add source files here as necessary. There are the raw source files,
and they have not been compiled of wrapped in a closure. Include them in the
order that they should be included in. If you are following the template's
pattern, the init file MUST be loaded last. -->
<script src="../vendor/jquery.js"></script>
<script src="../src/bashoto.core.js"></script>
<script src="../src/bashoto.topic.js"></script>
<script src="../src/bashoto.init.js"></script>
<script>
</script>
</head>
<body>
<h1 id="qunit-header">Bashoto Unit Tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture"></div>
<script>
(function () {
var TEST_APP_KEY = "b184691a-cd32-4158-ac4d-e5da10f03211";
module('Public API');
/*
test('Bashoto Constructor', function () {
var bashoto = new Bashoto('APP-KEY');
var appKey = bashoto.getAppKey();
equal(appKey, 'APP-KEY',
'App Key was read');
});
*/
/*
test('Bashoto Subscribe', function () {
var bashoto = new Bashoto('APP-KEY');
var topic = bashoto.subscribe();
equal(topic._url, "wss://bashoto-core.herokuapp.com/io/topic/APP-KEY?",
'Default Topic URL Verified');
topic = bashoto.subscribe({},{topic:'test'})
equal(topic._url, "wss://bashoto-core.herokuapp.com/io/topic/APP-KEY?topic=test",
'Test Topic URL Verified');
});
*/
/*
test('Bashoto Locate', function () {
var bashoto = new Bashoto('APP-KEY');
bashoto.locate();
var bashoto = new Bashoto('APP-KEY', {locate: true});
equal('APP-KEY', 'APP-KEY',
'App Key was read');
});
*/
module('Topic API');
/*
test('Get URL Test', function () {
var topic = new Bashoto.Topic('APP-KEY', {}, {topic:'test'});
var url = topic._url;
equal(url, "wss://bashoto-core.herokuapp.com/io/topic/APP-KEY?topic=test",
"there's a url");
});
*/
asyncTest('Messaging', function () {
var opts = {};
var derp = 'derp';
var topic = new Bashoto.Topic(TEST_APP_KEY, {
message: function(msg) {
equal(msg, derp, "HERP === DERP");
topic.close();
start();
},
open: function(open) {
var topic2 = new Bashoto.Topic(TEST_APP_KEY, {
open: function(open) {
topic2.close();
}
}, opts);
topic2.publish(derp);
}
}, opts);
});
//TODO finish adapting this
asyncTest('Local Messaging', function () {
var bashoto = new Bashoto(TEST_APP_KEY);
var mpd = {lat: 40.555, lon: -75.555, range: Bashoto.LOCAL};
var nyc = {lat: 40.555, lon: -75.551, range: Bashoto.LOCAL};
var denver = {lat: 40.555, lon: -105.555, range: Bashoto.LOCAL};
var opts = {};
var derp = 'derp';
var topic = bashoto.subscribe({
message: function(msg) {
equal(msg, derp, "HERP === DERP");
topic.close();
start();
},
open: function(open) {
var topic_denver = bashoto.subscribe({
open: function(open) { topic_denver.close(); },
close: function(close) {
var topic_nyc = bashoto.subscribe({
open: function(open) {
topic_nyc.close();
}
}, nyc);
topic_nyc.publish(derp);
}
}, denver);
topic_denver.publish("underp");
}
}, mpd);
});
} ());
</script>
</body>
</html>