@hmcts/one-per-page
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -0,1 +1,8 @@ | ||
<a name="3.1.2"></a> | ||
## 3.1.2 (2018-03-07) | ||
* Ensure forms filled from temp values are validated on GET requests ([093509f](https://github.com/hmcts/one-per-page/commit/093509f)) | ||
<a name="3.1.1"></a> | ||
@@ -2,0 +9,0 @@ ## 3.1.1 (2018-03-07) |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/hmcts/one-per-page#readme", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"main": "./src/main.js", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -9,6 +9,8 @@ const { notDefined } = require('../util/checks'); | ||
const fieldsProp = Symbol('fields'); | ||
const filled = Symbol('filledFromTemp'); | ||
class FilledForm { | ||
constructor(fieldValues = {}) { | ||
constructor(fieldValues = {}, filledFromTemp = false) { | ||
this[fieldsProp] = fieldValues; | ||
this[filled] = filledFromTemp; | ||
@@ -82,3 +84,3 @@ Object.entries(this.fields).forEach(([key, field]) => { | ||
get isFilled() { | ||
return Object.values(this.fields) | ||
return this[filled] || Object.values(this.fields) | ||
.some(field => field.isFilled); | ||
@@ -85,0 +87,0 @@ } |
@@ -37,3 +37,3 @@ const { notDefined } = require('../util/checks'); | ||
); | ||
return filledForm(fieldValues); | ||
return filledForm(fieldValues, tempValues.isSome()); | ||
} | ||
@@ -40,0 +40,0 @@ } |
@@ -187,3 +187,26 @@ const { expect, sinon } = require('../util/chai'); | ||
}); | ||
describe('#isFilled', () => { | ||
it('returns true if any field has values', () => { | ||
const filled = text.parse('foo', { foo: 'A Value' }); | ||
const f = new FilledForm({ foo: filled }); | ||
expect(f.isFilled).to.be.true; | ||
}); | ||
it('returns true if filled from temp', () => { | ||
const notFilled = text.parse('foo', {}); | ||
const f = new FilledForm({ foo: notFilled }, true); | ||
expect(f.isFilled).to.be.true; | ||
}); | ||
it('returns false otherwise', () => { | ||
const notFilled = text.parse('foo', {}); | ||
const f = new FilledForm({ foo: notFilled }); | ||
expect(f.isFilled).to.be.false; | ||
}); | ||
}); | ||
}); | ||
}); |
1316527
8278