Add UI Testing Framework and Simple UI Test

Added a Testem configuration that launches a Qunit page with an iFrame that builds and loads our mock-dev page and can interact with it and run tests on it.

Wrote a simple test that accepts the terms and conditions and transitions to the next page.

I am not doing any fancy redux-hooks for the async waiting, I've simply added a `tests/integration/helpers.js` file with a `wait()` function that returns a promise that should wait long enough.

Long term we should hook into the app lifecycle by some means for testing, so we only wait the right amount of time, and wait long enough for slower processes to complete, but this may work for the time being, just enough to run some basic automated browser tests.
This commit is contained in:
Dan Finlay 2016-07-22 15:43:30 -07:00
parent bf5f1df20e
commit b724dd009c
6 changed files with 63 additions and 0 deletions

1
.gitignore vendored
View File

@ -12,3 +12,4 @@ package
builds/
notes.txt
app/.DS_Store
development/bundle.js

View File

@ -0,0 +1,5 @@
function wait() {
return new Promise(function(resolve, reject) {
setTimeout(resolve, 500)
})
}

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>QUnit Example</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.0.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="https://code.jquery.com/qunit/qunit-2.0.0.js"></script>
<script src="./jquery-3.1.0.min.js"></script>
<script src="helpers.js"></script>
<script src="tests.js"></script>
<iframe src="/development/index.html" height="500px" width="360px">
<p>Your browser does not support iframes</p>
</iframe>
</body>
</html>

4
test/integration/jquery-3.1.0.min.js vendored Normal file

File diff suppressed because one or more lines are too long

22
test/integration/tests.js Normal file
View File

@ -0,0 +1,22 @@
QUnit.test('agree to terms', function (assert) {
var done = assert.async()
// Select the mock app root
var app = $('iframe').contents().find('#app-content .mock-app-root')
// Agree to terms
app.find('button').click()
// Wait for view to transition:
wait().then(function() {
var title = app.find('h1').text()
assert.equal(title, 'MetaMask', 'title screen')
var buttons = app.find('button')
assert.equal(buttons.length, 2, 'two buttons: create and restore')
done()
})
})

10
testem.yml Normal file
View File

@ -0,0 +1,10 @@
launch_in_dev:
- Chrome
- Firefox
framework:
- QUnit
test_page: "test/integration/index.html"
before_tests: "browserify ./mock-dev.js -o ./development/bundle.js"
after_tests: "rm ./development/bundle.js"
src_files: "./mock-dev.js"