Skip to content

Commit

Permalink
Merge pull request #3 from UKHomeOffice/remove-formatted-field
Browse files Browse the repository at this point in the history
Remove the "-formatted" field
  • Loading branch information
easternbloc committed May 11, 2016
2 parents f42c5e8 + 8e654d4 commit 480aa62
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
7 changes: 0 additions & 7 deletions lib/date-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
var util = require('util');
var _ = require('underscore');
var Parent = require('hmpo-form-wizard').Controller;
var moment = require('moment');

var DateController = function DateController() {
Parent.apply(this, arguments);
};

util.inherits(DateController, Parent);

var dateFormat = 'YYYY-MM-DD';
var prettyDate = 'D MMMM YYYY';

DateController.prototype.process = function process(req) {
_.each(this.options.fields, function processEach(v, k) {
if (
Expand Down Expand Up @@ -60,9 +56,6 @@ DateController.prototype.process = function process(req) {
'';

req.form.values[k] = date;
req.form.values[k + '-formatted'] = date === '' ?
'' :
moment(date, dateFormat).format(prettyDate);
}
}.bind(this));

Expand Down
16 changes: 1 addition & 15 deletions test/spec/spec.date-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Date Controller', function () {
beforeEach(function () {
sinon.spy(EventEmitter.prototype, 'emit');
});

afterEach(function () {
EventEmitter.prototype.emit.restore();
});
Expand Down Expand Up @@ -65,10 +66,6 @@ describe('Date Controller', function () {
req.form.values[key].should.eql('1999-12-01');
});

it('processes fields from the input-date mixin into a single, formatted field', function () {
req.form.values[key + '-formatted'].should.eql('1 December 1999');
});

it('applies the \'date-year\' validator to the year component', function () {
options.fields[key + '-year'].validate.should.contain('date-year');
});
Expand Down Expand Up @@ -101,7 +98,6 @@ describe('Date Controller', function () {

it('does NOT process the unexpected field', function () {
should.not.exist(req.form.values[otherKey]);
should.not.exist(req.form.values[otherKey + '-formatted']);
should.not.exist(req.form.values[otherKey + '-year']);
should.not.exist(req.form.values[otherKey + '-month']);
should.not.exist(req.form.values[otherKey + '-day']);
Expand All @@ -118,7 +114,6 @@ describe('Date Controller', function () {

it('does NOT process it as an input-date field', function () {
req.form.values[key].should.eql('');
should.not.exist(req.form.values[key + '-formatted']);
should.not.exist(req.form.values[key + '-year']);
should.not.exist(req.form.values[key + '-month']);
should.not.exist(req.form.values[key + '-day']);
Expand All @@ -141,7 +136,6 @@ describe('Date Controller', function () {

it('does NOT process it as an input-date field', function () {
req.form.values[key].should.eql('');
should.not.exist(req.form.values[key + '-formatted']);
should.not.exist(req.form.values[key + '-year']);
should.not.exist(req.form.values[key + '-month']);
should.not.exist(req.form.values[key + '-day']);
Expand All @@ -164,7 +158,6 @@ describe('Date Controller', function () {

it('does NOT process it as an input-date field', function () {
req.form.values[key].should.eql('');
should.not.exist(req.form.values[key + '-formatted']);
should.not.exist(req.form.values[key + '-year']);
should.not.exist(req.form.values[key + '-month']);
should.not.exist(req.form.values[key + '-day']);
Expand All @@ -188,7 +181,6 @@ describe('Date Controller', function () {

it('processes to an empty string', function () {
req.form.values[key].should.eql('');
req.form.values[key + '-formatted'].should.eql('');
});

it('applies the date validators to the date components', function () {
Expand All @@ -209,7 +201,6 @@ describe('Date Controller', function () {

it('processes to an empty string', function () {
req.form.values[key].should.eql('');
req.form.values[key + '-formatted'].should.eql('');
});

it('applies the date validators to the date components', function () {
Expand All @@ -230,7 +221,6 @@ describe('Date Controller', function () {

it('processes to an empty string', function () {
req.form.values[key].should.eql('');
req.form.values[key + '-formatted'].should.eql('');
});

it('applies the date validators to the date components', function () {
Expand All @@ -251,7 +241,6 @@ describe('Date Controller', function () {

it('processes to an empty string', function () {
req.form.values[key].should.eql('');
req.form.values[key + '-formatted'].should.eql('');
});

it('does NOT apply the date validators to the date components', function () {
Expand All @@ -272,7 +261,6 @@ describe('Date Controller', function () {

it('pads the month component to two characters in the combined field', function () {
req.form.values[key].should.eql('1999-02-01');
req.form.values[key + '-formatted'].should.eql('1 February 1999');
});
});

Expand All @@ -287,7 +275,6 @@ describe('Date Controller', function () {

it('pads the day component to two characters in the combined field', function () {
req.form.values[key].should.eql('1999-02-01');
req.form.values[key + '-formatted'].should.eql('1 February 1999');
});
});
});
Expand Down Expand Up @@ -339,7 +326,6 @@ describe('Date Controller', function () {

it('processes to an empty string', function () {
req.form.values[key].should.eql('');
req.form.values[key + '-formatted'].should.eql('');
});

it('applies the \'required\' validator to the component fields', function () {
Expand Down

0 comments on commit 480aa62

Please sign in to comment.