added front end tests

This commit is contained in:
Abhinav Adduri 2017-07-12 09:00:02 -07:00
parent dad6132342
commit af0c497aab
7 changed files with 13708 additions and 2 deletions

View File

@ -117,7 +117,7 @@ class FileSender extends EventEmitter {
url: responseObj.url,
fileId: responseObj.id,
secretKey: keydata.k,
deleteToken: responseObj.uuid
deleteToken: responseObj.delete
});
}
};

View File

@ -7,7 +7,6 @@ function arrayToHex(iv) {
hexStr += iv[i].toString(16);
}
}
window.hexStr = hexStr;
return hexStr;
}

View File

@ -52,6 +52,7 @@
"lint:js": "eslint .",
"start": "node server/server",
"test": "mocha test/unit && mocha test/server",
"test-browser": "watchify test/frontend/filetest.bundle.js -o test/frontend/bundle.js -d",
"version": "node scripts/version"
}
}

13578
test/frontend/bundle.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Mocha Tests</title>
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css">
<script src="bundle.js"></script>
<meta charset="utf-8"/>
</head>
<body>
<div id="mocha"></div>
<script src="../../node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<!-- load code you want to test here -->
<script src="filesender.test.js"></script>
<script>
mocha.checkLeaks();
mocha.globals(['jQuery']);
mocha.run();
</script>
</body>
</html>

View File

@ -0,0 +1,85 @@
const FileSender = window.FileSender;
const FakeFile = window.FakeFile;
const stubXML = window.stubXML;
const assert = window.assert;
describe('File Sender', function() {
let xhr;
let request;
let server;
before(function() {
xhr = sinon.useFakeXMLHttpRequest();
server = sinon.fakeServer.create();
server.respondImmediately = true;
server.respondWith(
'POST',
'/upload',
function(request) {
request.respond(
200,
{'Content-Type': 'application/json'},
JSON.stringify({url: '1', id: '1', uuid: 'del'})
)
}
)
})
it('Should get a loading event emission', function() {
let file = new FakeFile('hello_world.txt', ['This is some data.'])
let fs = new FileSender(file);
let testLoading = true;
fs.on('loading', isStillLoading => {
assert(!(!testLoading && isStillLoading))
testLoading = isStillLoading
})
return fs.upload()
.then(info => {
assert(!testLoading)
})
.catch(err => {
assert.fail();
});
})
it('Should get a hashing event emission', function() {
let file = new FakeFile('hello_world.txt', ['This is some data.'])
let fs = new FileSender(file);
let testHashing = true;
fs.on('hashing', isStillHashing => {
assert(!(!testHashing && isStillHashing))
testHashing = isStillHashing
})
return fs.upload()
.then(info => {
assert(!testHashing)
})
.catch(err => {
assert.fail();
});
})
it('Should get a encrypting event emission', function() {
let file = new FakeFile('hello_world.txt', ['This is some data.'])
let fs = new FileSender(file);
let testEncrypting = true;
fs.on('encrypting', isStillEncrypting => {
assert(!(!testEncrypting && isStillEncrypting))
testEncrypting = isStillEncrypting
})
return fs.upload()
.then(info => {
assert(!testEncrypting)
})
.catch(err => {
assert.fail();
});
})
});

View File

@ -0,0 +1,18 @@
class FakeFile extends Blob {
constructor(name, data, opt) {
super(data, opt);
this.name = name;
}
}
window.Raven = {
captureException: function(err) {
console.error(err, err.stack);
}
}
window.FakeFile = FakeFile;
window.FileSender = require('../../frontend/src/fileSender');
window.FileReceiver = require('../../frontend/src/fileReceiver');
window.sinon = require('sinon');
window.assert = require('assert');