From 48f0dc6c2a4d5437cc264288e5e8aaf83c0b6d58 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Fri, 5 Feb 2016 11:58:52 +0000 Subject: [PATCH] Issue #13 - Add very basic FTU, r=ferjm --- .travis.yml | 8 ++- docs/user-manual.md | 5 ++ static/index.html | 49 +++++++++++++++++- test/selenium/ftu_test.js | 106 +++++++++++++++++++++++++++++++++++--- 4 files changed, 157 insertions(+), 11 deletions(-) create mode 100644 docs/user-manual.md diff --git a/.travis.yml b/.travis.yml index 3ba467b0..2c758992 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: rust rust: - nightly +addons: + hosts: + - foxbox.local + before_script: - "sh -e /etc/init.d/xvfb start" - "export DISPLAY=:99.0" @@ -10,9 +14,9 @@ before_script: - sleep 5 - nvm install 4.2 - nvm use 4.2 - - npm install selenium-webdriver + - npm install selenium-webdriver mocha script: - cargo build # Linter is also executed here - RUST_BACKTRACE=1 cargo test - - (cargo run > /dev/null &) ; node test/selenium/ftu_test.js + - (cargo run > /dev/null &) ; ./node_modules/.bin/mocha test/selenium/ftu_test.js diff --git a/docs/user-manual.md b/docs/user-manual.md new file mode 100644 index 00000000..b00b2abf --- /dev/null +++ b/docs/user-manual.md @@ -0,0 +1,5 @@ +# Setting up your FoxBox + +* Connect your FoxBox to your internet router, using the ethernet cable provided. +* Browse to [http://foxbox.local/](http://foxbox.local/). +* Follow the instructions there. diff --git a/static/index.html b/static/index.html index 9cb7bc40..3446ab01 100644 --- a/static/index.html +++ b/static/index.html @@ -2,8 +2,55 @@ FoxBox + -

Welcome To FoxBox!

+

Welcome to your FoxBox!

+

+ + +

+

+ + +

+

+ +

+ diff --git a/test/selenium/ftu_test.js b/test/selenium/ftu_test.js index 39bb9e52..830e56de 100644 --- a/test/selenium/ftu_test.js +++ b/test/selenium/ftu_test.js @@ -1,10 +1,100 @@ -var webdriver = require('selenium-webdriver'), - until = require('selenium-webdriver').until; +var assert = require('assert'), + test = require('selenium-webdriver/testing'), + webdriver = require('selenium-webdriver'); -var driver = new webdriver.Builder(). - forBrowser('firefox'). - build(); +test.describe('setup page', function() { + var driver; + this.timeout(8000); + before(function() { + driver = new webdriver.Builder(). + forBrowser('firefox'). + build(); + }); + beforeEach(function() { + driver.get('http://foxbox.local:3000/'); + }); + after(function() { + driver.quit(); + }); -driver.get('http://localhost:3000/'); -driver.wait(until.titleIs('FoxBox'), 10000); -driver.quit(); + test.it('should be titled FoxBox', function () { + return driver.wait(webdriver.until.titleIs('FoxBox'), 5000).then(function(value) { + assert.equal(value, true); + }); + }); + describe('UI to set admin password', function() { + var elts; + beforeEach(function() { + elts = { + pwd1: driver.findElement(webdriver.By.id('pwd1-input')), + pwd2: driver.findElement(webdriver.By.id('pwd2-input')), + set: driver.findElement(webdriver.By.id('set-button')) + }; + }); + test.it('should have the right fields', function () { + var types = { + pwd1: 'password', + pwd2: 'password', + set: 'submit' + } + var promises = Object.keys(elts).map(function(key) { + return elts[key].getAttribute('type').then(function(value) { + assert.equal(value, types[key]); + }); + }); + return Promise.all(promises); + }); + + test.it('should reject non-matching passwords', function () { + return elts.pwd1.sendKeys('asdfasdf').then(function() { + return elts.pwd2.sendKeys('qwerqwer'); + }).then(function() { + return elts.set.click(); + }).then(function() { + return driver.wait(webdriver.until.alertIsPresent(), 5000); + }).then(function() { + return driver.switchTo().alert(); + }).then(function(alert) { + return alert.getText().then(function(text) { + assert.equal(text, 'Passwords don\'t match! Please try again.'); + }).then(function() { + alert.dismiss(); + }); + }); + }); + + test.it('should reject short passwords', function () { + return elts.pwd1.sendKeys('asdf').then(function() { + return elts.pwd2.sendKeys('asdf'); + }).then(function() { + return elts.set.click(); + }).then(function() { + return driver.wait(webdriver.until.alertIsPresent(), 5000); + }).then(function() { + return driver.switchTo().alert(); + }).then(function(alert) { + return alert.getText().then(function(text) { + assert.equal(text, 'Please use a password of at least 8 characters.'); + }).then(function() { + alert.dismiss(); + }); + }); + }); + + test.it('should accept matching, long-enough passwords', function () { + return elts.pwd1.sendKeys('asdfasdf').then(function() { + return elts.pwd2.sendKeys('asdfasdf'); + }).then(function() { + return elts.set.click(); + }).then(function() { + return driver.findElement(webdriver.By.id('thank-you')); + }).then(function(elt) { + return driver.wait(webdriver.until.elementIsVisible(elt), 5000).then(function() { + return elt.getAttribute('innerHTML'); + }).then(function(value) { + assert.equal(value, 'Thank you!'); + }); + }); + }); + }); +});