Skip to content

Commit

Permalink
test(library): expand the manual tests for the library
Browse files Browse the repository at this point in the history
  • Loading branch information
bitjson committed Sep 29, 2016
1 parent d5ca673 commit 6dc82aa
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 32 deletions.
8 changes: 6 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,14 @@ npm run gen-tests

This will create a new cordova project in the `cordova-plugin-test-projects` directory next to this repo, install `cordova-plugin-qrscanner`, and configure the [Cordova Plugin Test Framework](https://github.com/apache/cordova-plugin-test-framework). Once the platform tests are generated, the following commands are available:

- `npm run test:ios`
- `npm run test:browser`
- `npm run test:android`
- `npm run test:browser`
- `npm run test:ios`

Both Automatic Tests (via Cordova Plugin Test Framework's built-in [Jasmine](https://github.com/jasmine/jasmine)) and Manual Tests are available. Automatic tests confirm the existence and expected structure of the javascript API, and manual tests should be used to confirm functionality on each platform.

The manual tests for the library are available without the cordova test project:

- `npm run test:library`

The build for this repo currently only confirms javascript style and syntax with [jshint](https://github.com/jshint/jshint). Pull requests with additional automated test methods are welcome!
2 changes: 1 addition & 1 deletion src/browser/src/createQRScannerInternal.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ module.exports = function(){
if(sendError){
error(6); // SCAN_CANCELED
}
}
};
};
thisScanCycle();
}, error);
Expand Down
113 changes: 84 additions & 29 deletions tests/library/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,118 @@
<script src="../../dist/cordova-plugin-qrscanner-lib.min.js"></script>
<script>
function prepare(){
QRScanner.prepare(function(err, status){
if(err){
console.error(err._message);
} else {
console.log('QRScanner is initialized. Status:');
console.log(status);
}
});
QRScanner.prepare();
}
function scan(){
QRScanner.scan(
function(err, result){
window.alert('result: "' + result + '", error: ' + err)
if(err) {
console.log('scan error:', result);
} else {
window.alert('result: ' + result);
}
});
}
function cancelScan(){
QRScanner.cancelScan();
}
function frontCamera(){
QRScanner.useFrontCamera(function(err, status){
err && console.error(err);
console.log(status);
});
QRScanner.useFrontCamera();
}
function backCamera(){
QRScanner.useBackCamera(function(err, status){
err && console.error(err);
console.log(status);
});
QRScanner.useBackCamera();
}
function show(){
QRScanner.show(function(status){
console.log(status);
});
QRScanner.show();
}
function hide(){
QRScanner.hide(function(status){
console.log(status);
});
QRScanner.hide();
}
function pausePreview(){
QRScanner.pausePreview(function(status){
console.log(status);
});
QRScanner.pausePreview();
}
function resumePreview(){
QRScanner.resumePreview(function(status){
console.log(status);
QRScanner.resumePreview();
}
function destroy(){
QRScanner.destroy();
}
function getStatus(){
QRScanner.getStatus(console.log);
}
function testAll(){
console.log('Destroying QRScanner to test everything...');
QRScanner.destroy();
console.log('Preparing QRScanner...');
QRScanner.prepare(function(err, status){
if(err){
console.error(err._message);
} else {
console.log('QRScanner is initialized. Status:');
console.log(status);
console.log('Showing QRScanner...');
QRScanner.show(function(){
console.log('Starting scan...');
QRScanner.scan(function(err, result){
if(err){
console.log(err);
console.log('Scan canceled successfully.');
console.log('Destroying QRScanner...');
QRScanner.destroy(function(status){
console.log('QRScanner destroyed. Status:');
console.log(status);
});
}
});
window.setTimeout(function(){
console.log('Pausing preview...');
QRScanner.pausePreview(function(){
window.setTimeout(function(){
console.log('Resuming preview...');
QRScanner.resumePreview(function(){
// shouldn't work if less than 2 cameras, but shouldn't break everything
console.log('Switching cameras if available...');
QRScanner.useFrontCamera(function(err, status){
console.log('Status:');
console.log(status);
QRScanner.useBackCamera(function(err, status){
// shouldn't work, but shouldn't break everything
console.log('Making sure the lighting functions don\'t break things...');
QRScanner.enableLight();
QRScanner.disableLight();
console.log('Get status:');
QRScanner.getStatus(function(status){
console.log(status);
console.log('Canceling scan...');
QRScanner.cancelScan(function(status){
console.log('Final status:');
console.log(status);
});
});

});
});
});
}, 1000);
});
}, 3000);
});
}
});
}
</script>
</head>
<body>
<button onclick="scan()"><h1>prepare</h1></button>
<button onclick="testAll()"><h1>testAll</h1></button>
<button onclick="prepare()"><h1>prepare</h1></button>
<button onclick="scan()"><h1>scan</h1></button>
<button onclick="cancelScan()"><h1>cancelScan</h1></button>
<button onclick="frontCamera()"><h1>useFrontCamera</h1></button>
<button onclick="backCamera()"><h1>useBackCamera</h1></button>
<button onclick="show()"><h1>show</h1></button>
<button onclick="hide()"><h1>hide</h1></button>
<button onclick="pausePreview()"><h1>pausePreview</h1></button>
<button onclick="resumePreview()"><h1>resumePreview</h1></button>
<button onclick="destroy()"><h1>destroy</h1></button>
</body>
</html>

0 comments on commit 6dc82aa

Please sign in to comment.