4831: More testing stuff.
authorTom Clegg <tom@curoverse.com>
Wed, 31 Dec 2014 04:18:08 +0000 (23:18 -0500)
committerTom Clegg <tom@curoverse.com>
Wed, 31 Dec 2014 04:18:08 +0000 (23:18 -0500)
apps/backstage/Makefile
apps/backstage/test/functional/dashboard.js
apps/backstage/test/unit/filter.js
apps/backstage/test/webdriver-client.js

index 65f375d607037d540b9807bcfc0f63e412c4bdf1..305f19b2bee3d697c04ad2109ee6010be725f0b8 100644 (file)
@@ -1,6 +1,6 @@
 NPMBIN:=$(shell npm bin)
 
-all: npmdeps build-dist
+all: npmdeps build
 
 clean:
        rm -rvf dist
@@ -9,12 +9,20 @@ npmdeps:
        for x in bootstrap bower browserify chai chai-jquery jquery mithril mithril-query mocha mocha-phantomjs sinon; do [ -d "$(NPMBIN)/../$$x" ] || npm install $$x --save-dev; done
 
 # This uses --debug to enable source maps.
-build-dist:
+build: build-app build-test build-css
+build-app:
        mkdir -p dist
        $(NPMBIN)/browserify --debug -o dist/app.js app/app.js
+build-test:
+       mkdir -p dist
        $(NPMBIN)/browserify --debug -o dist/test.js test/runner.js
+build-css:
+       mkdir -p dist
        rsync -a $(NPMBIN)/../bootstrap/dist/ dist/bootstrap/
 
-server: build-dist
+server: build
        [ -e $(NPMBIN)/harp ] || npm install harp
        $(NPMBIN)/harp server --port 9000
+
+test: build-test build-css
+       $(NPMBIN)/mocha-phantomjs test.html
index 95418c5bac7fd1c7eb45df130ca7efb8e50eb846..df95f64aae0c31d296f222dcca54479482a44a22 100644 (file)
@@ -1,11 +1,12 @@
-require(['chai', 'test/webdriver-client'], function(chai, c) {
-    var assert = chai.assert;
-    describe('Dashboard page', function() {
-        before(function() {
-            c.init().url('http://localhost:5555');
-        });
-        it('has a nav', function() {
-            assert(c.isVisible('nav'));
-        });
+var chai = require('chai')
+, wd = require('webdriver-client')
+, c = chai;
+
+suite('Dashboard page', function() {
+    setup(function() {
+        wd.url('http://localhost:5555');
+    });
+    test('has a nav', function() {
+        c.assert(wd.isVisible('nav'));
     });
 });
index dc1b6be114c9ab21c73a70112c010b78a9c7b09d..375647157d7b730c16c5fdac170f4b7c13213246 100644 (file)
@@ -4,15 +4,37 @@ var mq = require('mithril-query')
 , s = sinon;
 
 suite('Filter', function() {
-    test("changing input fires currentFilter", function() {
-        var tested = new Filter.AnyText();
-        var cfSpy = sinon.spy();
-        var ctrl = {currentFilter: cfSpy};
-        var v = tested.view(ctrl);
-        s.assert.notCalled(cfSpy);
-        mq(v).setValue('input', 'qux');
-        s.assert.calledOnce(cfSpy);
-        s.assert.calledOn(cfSpy, ctrl);
-        s.assert.calledWith(cfSpy, 'any', 'ilike', '%qux%');
+    function setup(filterClass) {
+        var f = {};
+        f.tested = new filterClass({attr: 'fakeAttr'});
+        f.cfSpy = sinon.spy();
+        f.ctrl = {currentFilter: f.cfSpy};
+        f.rendered = f.tested.view(f.ctrl);
+        f.domfrag = mq(f.rendered);
+        return f;
+    }
+    suite('AnyText', function() {
+        test.skip("default is existing filter value", function() {
+            // TODO
+        });
+        test("fires currentFilter on input change", function() {
+            f = setup(Filter.AnyText);
+            // XXX: should call once to retrieve current filter value
+            // s.assert.calledWith(f.cfSpy);
+            f.domfrag.setValue('input', 'qux');
+            // Should call again to set new filter value
+            s.assert.calledWith(f.cfSpy, 'any', 'ilike', '%qux%');
+        });
+    });
+    suite('ObjectType', function() {
+        test.skip("default is existing filter value", function() {
+            // TODO
+        });
+        test("fires currentFilter on selection", function() {
+            f = setup(Filter.ObjectType);
+            f.domfrag.click('li a');
+            s.assert.calledOn(f.cfSpy, f.ctrl);
+            s.assert.calledWith(f.cfSpy, 'fakeAttr', 'is_a', 'arvados#collection');
+        });
     });
 });
index dc40522f321093d539de8523cb3b2b16c4b3133d..752a79757f1b9c38d97ac64ab7449cd677d055e0 100644 (file)
@@ -1,13 +1,13 @@
-define(['webdriverjs'], function(webdriverjs) {
-    var client = webdriverjs.remote({
-        desiredCapabilities: {
-            // http://code.google.com/p/selenium/wiki/DesiredCapabilities
-            browserName: 'phantomjs'
-        },
-        // webdriverjs has a lot of output which is generally useless
-        // However, if anything goes wrong, remove this to see more details
-        // logLevel: 'silent'
-    });
-    client.init();
-    return client;
+var webdriverjs = require('webdriverjs');
+
+var client = webdriverjs.remote({
+    desiredCapabilities: {
+        // http://code.google.com/p/selenium/wiki/DesiredCapabilities
+        browserName: 'phantomjs'
+    },
+    // webdriverjs has a lot of output which is generally useless
+    // However, if anything goes wrong, remove this to see more details
+    // logLevel: 'silent'
 });
+client.init();
+module.exports = client;