@hmcts/one-per-page
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -0,1 +1,12 @@ | ||
<a name="1.2.0"></a> | ||
# 1.2.0 (2017-10-19) | ||
* Add new Reference type that is a readonly field ([0e97fa2](https://github.com/hmcts/one-per-page/commit/0e97fa2)) | ||
* Allow steps to define functions that are scoped local ([c6f4d9a](https://github.com/hmcts/one-per-page/commit/c6f4d9a)) | ||
* Expose new ref fields and demo them in the example app ([138b846](https://github.com/hmcts/one-per-page/commit/138b846)) | ||
* Fix bad value on country page (hang over from a test) ([38fd008](https://github.com/hmcts/one-per-page/commit/38fd008)) | ||
* Test the @hmcts/one-per-page/forms interface ([69987ca](https://github.com/hmcts/one-per-page/commit/69987ca)) | ||
<a name="1.1.0"></a> | ||
@@ -2,0 +13,0 @@ # 1.1.0 (2017-10-13) |
@@ -12,2 +12,4 @@ const config = require('config'); | ||
const Entry = require('./steps/Entry.step'); | ||
const RespondentTitle = require('./steps/respondent/RespondentTitle.step'); | ||
const RespondentName = require('./steps/respondent/RespondentName.step'); | ||
const ExitNorthernIreland = require('./steps/exits/ExitNorthernIreland.step'); | ||
@@ -31,2 +33,4 @@ const Exit = require('./steps/exits/Done.step'); | ||
new Entry(), | ||
new RespondentTitle(), | ||
new RespondentName(), | ||
new Sessions(), | ||
@@ -33,0 +37,0 @@ new Name(), |
@@ -25,3 +25,3 @@ const { Question, goTo, branch } = require('@hmcts/one-per-page'); | ||
goTo(this.journey.ExitNorthernIreland).if(livesInNI), | ||
goTo(this.journey.Name) | ||
goTo(this.journey.RespondentTitle) | ||
); | ||
@@ -28,0 +28,0 @@ } |
{ | ||
"name": "@hmcts/one-per-page", | ||
"description": "One question per page apps made easy", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "./src/main.js", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
const { form } = require('./form'); | ||
const { field } = require('./field'); | ||
const { ref } = require('./ref'); | ||
const parsers = require('./fieldParsers'); | ||
const arrayField = name => field(name, parsers.arrayParser); | ||
arrayField.ref = (step, name) => ref(step, name, parsers.arrayParser); | ||
const textField = name => field(name, parsers.textParser); | ||
textField.ref = (step, name) => ref(step, name, parsers.textParser); | ||
const nonEmptyTextField = name => field(name, parsers.nonEmptyTextParser); | ||
nonEmptyTextField.ref = (step, name) => | ||
ref(step, name, parsers.nonEmptyTextParser); | ||
module.exports = { form, field, arrayField, textField, nonEmptyTextField }; |
@@ -9,2 +9,13 @@ const BaseStep = require('./BaseStep'); | ||
const notLocals = [ | ||
'_router', | ||
'journey', | ||
'constructor', | ||
'form', | ||
'next', | ||
'locals', | ||
'middleware', | ||
'handler' | ||
]; | ||
class Page extends BaseStep { | ||
@@ -21,3 +32,15 @@ constructor() { | ||
get locals() { | ||
return this.res.locals; | ||
const myKeys = [ | ||
...Reflect.ownKeys(this), | ||
...Reflect.ownKeys(Object.getPrototypeOf(this)) | ||
]; | ||
const classLocals = myKeys | ||
.filter(key => !(notLocals.includes(key))) | ||
.reduce((obj, key) => { | ||
obj[key] = this[key]; | ||
return obj; | ||
}, {}); | ||
return Object.assign({}, classLocals, this.res.locals); | ||
} | ||
@@ -24,0 +47,0 @@ |
@@ -100,2 +100,23 @@ const Page = require('./../../src/steps/Page'); | ||
}); | ||
it('has access to arbitrary functions on the step', () => { | ||
const page = new class extends Page { | ||
get url() { | ||
return '/my/page'; | ||
} | ||
get template() { | ||
return 'page_views/class_locals'; | ||
} | ||
get foo() { | ||
return 'Foo'; | ||
} | ||
get bar() { | ||
return 'Bar'; | ||
} | ||
}(); | ||
return testStep(page) | ||
.get() | ||
.expect(OK, 'Foo Bar\n'); | ||
}); | ||
}); | ||
@@ -129,2 +150,5 @@ | ||
} | ||
get foo() { | ||
return 'Foo'; | ||
} | ||
}(); | ||
@@ -142,2 +166,6 @@ const request = testStep(page) | ||
}); | ||
it('has access to arbitrary functions on the step', () => { | ||
return request.html($ => expect($('#funcKey')).$text('Foo is Foo')); | ||
}); | ||
} | ||
@@ -144,0 +172,0 @@ }); |
@@ -7,4 +7,5 @@ { | ||
}, | ||
"sessionKey": "Foo is {{ session.foo }}" | ||
"sessionKey": "Foo is {{ session.foo }}", | ||
"funcKey": "Foo is {{ foo }}" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
432308
156
3860