From 52a923ace3be948950ac76bf3a1f34bf6fd7df53 Mon Sep 17 00:00:00 2001 From: Rowan Manning Date: Thu, 28 Nov 2013 13:59:27 +0000 Subject: [PATCH] Write basic tests for task editing --- test/functional/route/index.js | 16 ++++- test/functional/route/task/delete.js | 4 ++ test/functional/route/task/edit.js | 102 +++++++++++++++++++++++++++ test/functional/route/task/index.js | 20 +++--- view/task/edit.html | 2 +- 5 files changed, 133 insertions(+), 11 deletions(-) create mode 100644 test/functional/route/task/edit.js diff --git a/test/functional/route/index.js b/test/functional/route/index.js index 41087f8..fb6a31c 100644 --- a/test/functional/route/index.js +++ b/test/functional/route/index.js @@ -39,13 +39,27 @@ describe('GET /', function () { assert.strictEqual(tasks[2].querySelectorAll('[href="/abc000000000000000000003"]').length, 1); }); - it('should display a delete button for each task', function () { + it('should display an "Edit" button for each task', function () { + var tasks = this.last.dom.querySelectorAll('[data-test=task]'); + assert.strictEqual(tasks[0].querySelectorAll('[href="/abc000000000000000000001/edit"]').length, 1); + assert.strictEqual(tasks[1].querySelectorAll('[href="/abc000000000000000000002/edit"]').length, 1); + assert.strictEqual(tasks[2].querySelectorAll('[href="/abc000000000000000000003/edit"]').length, 1); + }); + + it('should display a "Delete" button for each task', function () { var tasks = this.last.dom.querySelectorAll('[data-test=task]'); assert.strictEqual(tasks[0].querySelectorAll('[href="/abc000000000000000000001/delete"]').length, 1); assert.strictEqual(tasks[1].querySelectorAll('[href="/abc000000000000000000002/delete"]').length, 1); assert.strictEqual(tasks[2].querySelectorAll('[href="/abc000000000000000000003/delete"]').length, 1); }); + it('should display a "Run" button for each task', function () { + var tasks = this.last.dom.querySelectorAll('[data-test=task]'); + assert.strictEqual(tasks[0].querySelectorAll('[href="/abc000000000000000000001/run"]').length, 1); + assert.strictEqual(tasks[1].querySelectorAll('[href="/abc000000000000000000002/run"]').length, 1); + assert.strictEqual(tasks[2].querySelectorAll('[href="/abc000000000000000000003/run"]').length, 1); + }); + it('should display the task result counts if the task has been run', function () { var tasks = this.last.dom.querySelectorAll('[data-test=task]'); assert.match(tasks[0].textContent, /1\s*errors/i); diff --git a/test/functional/route/task/delete.js b/test/functional/route/task/delete.js index bbc674b..cb7f0af 100644 --- a/test/functional/route/task/delete.js +++ b/test/functional/route/task/delete.js @@ -25,6 +25,10 @@ describe('GET //delete', function () { assert.strictEqual(form.getAttribute('method'), 'post'); }); + it('should display a link back to the task page', function () { + assert.greaterThan(this.last.dom.querySelectorAll('[href="/abc000000000000000000001"]').length, 0); + }); + }); describe('POST //delete', function () { diff --git a/test/functional/route/task/edit.js b/test/functional/route/task/edit.js new file mode 100644 index 0000000..0fef712 --- /dev/null +++ b/test/functional/route/task/edit.js @@ -0,0 +1,102 @@ +/* global beforeEach, describe, it */ +/* jshint maxlen: false, maxstatements: false */ +'use strict'; + +var assert = require('proclaim'); + +describe('GET //edit', function () { + + beforeEach(function (done) { + var req = { + method: 'GET', + endpoint: '/abc000000000000000000001/edit' + }; + this.navigate(req, done); + }); + + it('should send a 200 status', function () { + assert.strictEqual(this.last.status, 200); + }); + + it('should have an "Edit URL" form', function () { + var form = this.last.dom.querySelectorAll('[data-test=edit-url-form]')[0]; + assert.isDefined(form); + assert.strictEqual(form.getAttribute('action'), '/abc000000000000000000001/edit'); + assert.strictEqual(form.getAttribute('method'), 'post'); + }); + + it('should display a link back to the task page', function () { + assert.greaterThan(this.last.dom.querySelectorAll('[href="/abc000000000000000000001"]').length, 0); + }); + + describe('"Edit URL" form', function () { + + beforeEach(function () { + this.form = this.last.dom.querySelectorAll('[data-test=edit-url-form]')[0]; + }); + + it('should have a "name" field', function () { + var field = this.form.querySelectorAll('input[name=name]')[0]; + assert.isDefined(field); + assert.strictEqual(field.getAttribute('type'), 'text'); + assert.strictEqual(field.getAttribute('value'), 'NPG Home'); + }); + + it('should have a disabled "url" field', function () { + var field = this.form.querySelectorAll('input[name=url]')[0]; + assert.isDefined(field); + assert.strictEqual(field.getAttribute('type'), 'url'); + assert.strictEqual(field.getAttribute('value'), 'nature.com'); + assert.isDefined(field.getAttribute('disabled')); + }); + + it('should have a disabled "standard" field', function () { + var field = this.form.querySelectorAll('select[name=standard]')[0]; + assert.isDefined(field); + assert.isDefined(field.getAttribute('disabled')); + }); + + it('should have "ignore" fields', function () { + var fields = this.form.querySelectorAll('input[name="ignore[]"]'); + assert.isDefined(fields); + assert.notStrictEqual(fields.length, 0); + }); + + }); + +}); + +describe('POST //edit', function () { + + beforeEach(function (done) { + var req = { + method: 'POST', + endpoint: '/abc000000000000000000001/edit', + body: { + name: 'foo', + ignore: ['bar', 'baz'] + } + }; + this.navigate(req, done); + }); + + it('should send a 200 status', function () { + assert.strictEqual(this.last.status, 200); + }); + + it('should edit the task', function (done) { + this.webservice.task('abc000000000000000000001').get({}, function (err, task) { + assert.strictEqual(task.name, 'foo'); + assert.deepEqual(task.ignore, ['bar', 'baz']); + done(); + }); + }); + + it('should display a success message', function () { + var alert = this.last.dom.querySelectorAll('[data-test=alert]')[0]; + assert.isDefined(alert); + assert.match(alert.textContent, /been saved/i); + }); + +}); + diff --git a/test/functional/route/task/index.js b/test/functional/route/task/index.js index 8970aff..5d6220a 100644 --- a/test/functional/route/task/index.js +++ b/test/functional/route/task/index.js @@ -20,22 +20,24 @@ describe('GET /', function () { assert.strictEqual(this.last.status, 200); }); + it('should display an "Edit" button', function () { + assert.strictEqual(this.last.dom.querySelectorAll('[href="/abc000000000000000000001/edit"]').length, 1); + }); + + it('should display a "Delete" button', function () { + assert.strictEqual(this.last.dom.querySelectorAll('[href="/abc000000000000000000001/delete"]').length, 1); + }); + it('should display a "Run" button', function () { - var elem = this.last.dom.querySelectorAll('[data-test=run-task]'); - assert.strictEqual(elem.length, 1); - assert.strictEqual(elem[0].getAttribute('href'), '/abc000000000000000000001/run'); + assert.strictEqual(this.last.dom.querySelectorAll('[href="/abc000000000000000000001/run"]').length, 1); }); it('should display a "Download CSV" button for the latest result', 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'); + assert.strictEqual(this.last.dom.querySelectorAll('[href="/abc000000000000000000001/def000000000000000000001.csv"]').length, 1); }); it('should display a "Download JSON" button for the latest result', 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'); + assert.strictEqual(this.last.dom.querySelectorAll('[href="/abc000000000000000000001/def000000000000000000001.json"]').length, 1); }); it('should display links to all results', function () { diff --git a/view/task/edit.html b/view/task/edit.html index be11131..8582481 100644 --- a/view/task/edit.html +++ b/view/task/edit.html @@ -4,7 +4,7 @@ {{/content}} {{#edited}} -
+
Success!