-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hoff 737: session timeout continue form #464
base: master
Are you sure you want to change the base?
Hoff 737: session timeout continue form #464
Conversation
17b17b4
to
bcf9075
Compare
Nice work I haven't yet reviewed the code. I noticed you linked to a 2018 govuk issues link and with some discussion. It would be interesting to get a view point across government about the design with input from UCD after you've approved and merged your work. |
- allows for customisation of session timeout warning dialog content and exit page content | ||
* Fixes accessibility issues | ||
* Sandbox area for testing hof changes | ||
* Updates patch and minor dependency versions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
configure(req, res, next) { | ||
// reset the session if user chooses to exit on session timeout warning | ||
if (req.form.options.route === '/exit') { | ||
req.sessionModel.reset(); | ||
} | ||
return super.configure(req, res, next); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could add a try and catch without async as there could be issues with the session when resetting
configure(req, res, next) { | |
// reset the session if user chooses to exit on session timeout warning | |
if (req.form.options.route === '/exit') { | |
req.sessionModel.reset(); | |
} | |
return super.configure(req, res, next); | |
} | |
try { | |
// Reset the session if the user chooses to exit on session timeout warning | |
if (req.form.options.route === '/exit') { | |
req.sessionModel.reset(); | |
} | |
return super.configure(req, res, next); | |
} catch (error) { | |
console.error('Error during session reset:', error); | |
next(error); // Pass the error to the next middleware for centralised handling | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the hof-logger I can't remember how that works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added in the try/catch block with the hof logger now
package.json
Outdated
@@ -1,7 +1,7 @@ | |||
{ | |||
"name": "hof", | |||
"description": "A bootstrap for HOF projects", | |||
"version": "21.0.1", | |||
"version": "22.0.0-timeout-warning-beta.13", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you want to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏾 I have amended this now
@@ -21,13 +21,13 @@ | |||
"url": "https://github.com/UKHomeOfficeForms/hof/issues" | |||
}, | |||
"scripts": { | |||
"test": "yarn run unit && yarn run test:cookie-banner && yarn run test:functional && yarn run test:client && yarn run test:lint", | |||
"test": "yarn run unit && yarn run test:jest && yarn run test:functional && yarn run test:client && yarn run test:lint", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are using jest now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quite like how it works when mocking. The existing cookie-banner funtionality tests are already using jest and it seems there is also popularity among the team to move to using jest more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I prefer jest. mocha requires too much setup and is difficult with stubbing
instance.locals(req, res).should.not.have.property('dialogTitle'); | ||
instance.locals(req, res).should.not.have.property('dialogText'); | ||
instance.locals(req, res).should.not.have.property('timeoutContinueButton'); | ||
instance.locals(req, res).should.not.have.property('dialogExitLink'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instance.locals(req, res) is used a lot could you create a function for it
instance.locals(req, res).should.not.have.property('dialogTitle'); | |
instance.locals(req, res).should.not.have.property('dialogText'); | |
instance.locals(req, res).should.not.have.property('timeoutContinueButton'); | |
instance.locals(req, res).should.not.have.property('dialogExitLink'); | |
}); | |
const checkDialogProperties = (expected) => { | |
instance.locals(req, res).should.have.property('dialogTitle').and.deep.equal(expected); | |
instance.locals(req, res).should.have.property('dialogText').and.deep.equal(expected); | |
instance.locals(req, res).should.have.property('timeoutContinueButton').and.deep.equal(expected); | |
instance.locals(req, res).should.have.property('dialogExitLink').and.deep.equal(expected); | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could also do this,
const locals = instance.locals(req, res);
locals.should.have.property('dialogTitle').and.deep.equal(true);
locals.should.have.property('dialogText').and.deep.equal(true);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏾 I have amended this now
@@ -0,0 +1,121 @@ | |||
'use strict'; | |||
|
|||
const Component = require('../../components').sessionTimeoutWarning; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const Component = require('../../components').sessionTimeoutWarning; | |
const { sessionTimeoutWarning: Component } = require('../../components'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have amended this now
}); | ||
|
||
afterEach(() => { | ||
Base.prototype.locals.restore(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your thing works but I read about this being better and simple
Base.prototype.locals.restore(); | |
sinon.restore(); // Ensures all stubs/mocks are reset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏾 I have amended this now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
const sessionTimeoutWarningHtml = fs.readFileSync(path.resolve(__dirname, '../../../frontend/template-partials/views/partials/session-timeout-warning.html'), 'utf8'); | ||
|
||
jest | ||
.dontMock('fs'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think jest is much better than mocha so this is good tbh
jest | ||
.dontMock('fs'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jest | |
.dontMock('fs'); | |
jest.dontMock('fs'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have amended this now
let options; | ||
let originalHTMLDialogElement; | ||
|
||
beforeAll(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beforeAll
, can be dangerous because it only does a setup once and then it runs through the tests so it's not fresh but beforeEach
takes up more resource. I prefer beforeEach
just to be on the safe side but I'm sure it's fine in your scenario
9703336
to
47aabe9
Compare
README.md
Outdated
@@ -945,7 +945,7 @@ Using the translation key `fields.field-name.label` will return different values | |||
|
|||
# HOF Components | |||
|
|||
## Date Component | |||
# Date Component |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be a sub heading rather than a main heading?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏾 I have amended this now, All the other components were also using the main heading levels so I have made them subheadings and also adjusted the levels of their corresponding subheadings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sublime work, big props to you for getting this done. It's been a common request and makes hof more modern 👍
47aabe9
to
4491fd7
Compare
5c80cb5
to
1001e96
Compare
06adfc8
to
a46f3bb
Compare
- configure session timeout warning in frontend/themes/gov-uk/client-js/session-timeout-dialog.js - add frontend/template-partials/partials/session-timeout-warning.html - amend frontend/template-partials/partials/page.html to include session timeout warning in pages with forms. - add styling for session timeout warning - add leave form button in dialog box which resets session and goes to exit page informing user info has not been saved. This is for non save and return forms. - create session timeout component exit page customisable and session timeout warning dialog content customisable - add JSDoc and try/catch block to session timeout warning component - add hof logger to session timeout warning component - add session timeout warning component documentation to readme - amend sub heading levels for components in readme - amend confirmation page so it doesn't show popup - amend pr template name so it is picked up - add tests - update change log - update yarn.lock
a46f3bb
to
db0b465
Compare
What?
Why?
How?
Testing?
Anything Else? (optional)
Check list
here is an example commit
Screenshots (optional)
Default Session timeout warning
Default exit page after user clicks 'Exit this form'