diff --git a/test/functional/helper/navigate.js b/test/functional/helper/navigate.js index 8bfed8f..68f008d 100644 --- a/test/functional/helper/navigate.js +++ b/test/functional/helper/navigate.js @@ -30,14 +30,20 @@ function createNavigator (baseUrl, store) { store.response = res; store.status = res.statusCode; - jsdom.env( - store.body, - function (err, window) { - store.window = window; - store.dom = window.document; - callback(); - } - ); + if (opts.nonDom) { + store.window = null; + store.dom = null; + callback(); + } else { + jsdom.env( + store.body, + function (err, window) { + store.window = window; + store.dom = window.document; + callback(); + } + ); + } }); diff --git a/test/functional/route/result/download.js b/test/functional/route/result/download.js new file mode 100644 index 0000000..fb805ea --- /dev/null +++ b/test/functional/route/result/download.js @@ -0,0 +1,53 @@ +/* global beforeEach, describe, it */ +/* jshint maxlen: false, maxstatements: false */ +'use strict'; + +var assert = require('proclaim'); + +describe('GET //.csv', function () { + + beforeEach(function (done) { + var req = { + method: 'GET', + endpoint: '/abc000000000000000000001/def000000000000000000001.csv', + nonDom: true + }; + this.navigate(req, done); + }); + + it('should send a 200 status', function () { + assert.strictEqual(this.last.status, 200); + }); + + it('should output CSV results', function () { + assert.match(this.last.body, /^"code", "message", "type"/); + }); + +}); + +describe('GET //.json', function () { + + beforeEach(function (done) { + var req = { + method: 'GET', + endpoint: '/abc000000000000000000001/def000000000000000000001.json', + nonDom: true + }; + this.navigate(req, done); + }); + + it('should send a 200 status', function () { + assert.strictEqual(this.last.status, 200); + }); + + it('should output JSON results', function () { + var json = this.last.body; + assert.strictEqual(json.task.name, 'NPG Home'); + assert.strictEqual(json.task.url, 'nature.com'); + assert.strictEqual(json.count.error, 1); + assert.strictEqual(json.count.warning, 2); + assert.strictEqual(json.count.notice, 3); + assert.isArray(json.results); + }); + +}); diff --git a/test/functional/route/result/index.js b/test/functional/route/result/index.js new file mode 100644 index 0000000..5fcade8 --- /dev/null +++ b/test/functional/route/result/index.js @@ -0,0 +1,55 @@ +/* global beforeEach, describe, it */ +/* jshint maxlen: false, maxstatements: false */ +'use strict'; + +var assert = require('proclaim'); + +describe('GET //', function () { + + beforeEach(function (done) { + var req = { + method: 'GET', + endpoint: '/abc000000000000000000001/def000000000000000000001' + }; + this.navigate(req, done); + }); + + it('should send a 200 status', function () { + assert.strictEqual(this.last.status, 200); + }); + + it('should display a "Download CSV" button', function () { + var elem = this.last.dom.querySelectorAll('[data-test=download-csv]'); + assert.strictEqual(elem.length, 1); + assert.strictEqual(elem[0].getAttribute('href'), '/abc000000000000000000001/def000000000000000000001.csv'); + }); + + it('should display a "Download JSON" button', function () { + var elem = this.last.dom.querySelectorAll('[data-test=download-json]'); + assert.strictEqual(elem.length, 1); + assert.strictEqual(elem[0].getAttribute('href'), '/abc000000000000000000001/def000000000000000000001.json'); + }); + + it('should display a link back to the task', function () { + assert.isDefined(this.last.dom.querySelectorAll('[href="/abc000000000000000000001"]')[0]); + }); + + it('should display errors', function () { + var elem = this.last.dom.querySelectorAll('[data-test=task-errors]')[0]; + assert.isDefined(elem); + assert.match(elem.textContent, /errors \( 1 \)/i); + }); + + it('should display warnings', function () { + var elem = this.last.dom.querySelectorAll('[data-test=task-warnings]')[0]; + assert.isDefined(elem); + assert.match(elem.textContent, /warnings \( 2 \)/i); + }); + + it('should display notices', function () { + var elem = this.last.dom.querySelectorAll('[data-test=task-notices]')[0]; + assert.isDefined(elem); + assert.match(elem.textContent, /notices \( 3 \)/i); + }); + +});