-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> <html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>konashi web bluetooth tests</title> | ||
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.0.1.css"> | ||
</head> | ||
<body> | ||
<div id="qunit"></div> | ||
<div id="qunit-fixture"></div> | ||
<script src="https://code.jquery.com/qunit/qunit-2.0.1.js"></script> | ||
<script src="../js/konashi.js"></script> | ||
<script src="mock.js"></script> | ||
<script src="tests.js"></script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
(() => { | ||
|
||
class MockDevice { | ||
constructor() { | ||
this.gatt = new MockGatt(); | ||
} | ||
} | ||
|
||
class MockGatt { | ||
connect() { | ||
return new Promise((resolve, reject) => { | ||
resolve(this); | ||
}); | ||
} | ||
|
||
getPrimaryService(uuid) { | ||
return new MockKonashiService(); | ||
} | ||
} | ||
|
||
class MockKonashiService { | ||
constructor() { | ||
} | ||
getCharacteristic(uuid) { | ||
return new Promise((resolve, reject) => { | ||
return resolve(new MockC12c()); | ||
}); | ||
} | ||
} | ||
|
||
class MockC12c { | ||
readValue() { | ||
return new Promise((resolve, reject) => { | ||
var buff = new ArrayBuffer(1); | ||
buff[0] = 1; | ||
resolve(new DataView(buff)); | ||
}); | ||
} | ||
|
||
writeValue() { | ||
return new Promise((resolve, reject) => { | ||
var buff = new ArrayBuffer(1); | ||
buff[0] = 1; | ||
resolve(new DataView(buff)); | ||
}); | ||
} | ||
} | ||
|
||
var bluetooth = {}; | ||
|
||
bluetooth.requestDevice = function(options) { | ||
return new Promise((resolve, reject) => { | ||
resolve(new MockDevice()); | ||
}); | ||
}; | ||
|
||
navigator.bluetooth = bluetooth; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
QUnit.test('.find', (assert) => { | ||
return Konashi.find(true, {}).then((_k) => { | ||
assert.ok(_k instanceof Konashi); | ||
}); | ||
}); | ||
|
||
Konashi.find(true).then((k) => { | ||
|
||
QUnit.module('.pinMode', () => { | ||
QUnit.test('INPUT', (assert) => { | ||
return k.pinMode(k.PIO0, k.INPUT) | ||
.then(() => k.pinMode(k.PIO1, k.INPUT)) | ||
.then(() => k.pinMode(k.PIO2, k.INPUT)) | ||
.then(() => k.pinMode(k.PIO3, k.INPUT)) | ||
.then(() => k.pinMode(k.PIO4, k.INPUT)) | ||
.then(() => { | ||
assert.ok(true); | ||
}); | ||
}); | ||
QUnit.test('OUTPUT', (assert) => { | ||
return k.pinMode(k.PIO0, k.OUTPUT) | ||
.then(() => k.pinMode(k.PIO1, k.OUTPUT)) | ||
.then(() => k.pinMode(k.PIO2, k.OUTPUT)) | ||
.then(() => k.pinMode(k.PIO3, k.OUTPUT)) | ||
.then(() => k.pinMode(k.PIO4, k.OUTPUT)) | ||
.then(() => { | ||
assert.ok(true); | ||
}); | ||
}); | ||
QUnit.test('INPUT & OUTPUT', (assert) => { | ||
return k.pinMode(k.PIO0, k.INPUT) | ||
.then(() => k.pinMode(k.PIO1, k.OUTPUT)) | ||
.then(() => k.pinMode(k.PIO2, k.INPUT)) | ||
.then(() => k.pinMode(k.PIO3, k.OUTPUT)) | ||
.then(() => k.pinMode(k.PIO4, k.INPUT)) | ||
.then(() => { | ||
assert.ok(true); | ||
}); | ||
}); | ||
}); // .pinMode | ||
|
||
|
||
}); | ||
|