-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/46532 the retro input assistant link does not display until o…
…fficial check (#1875) * [admin] bugfix: don't show the retro input assistent until the check window opens * [admin] add tests We want these tests to be unit tests rather than integration tests because the driver for showing it is the date and the checkwindow. If we were to make these ntegration tests we can easily test the output, but if we have to mock the app then we would need to start and stop the app for each test which would be slow. This approach has the benefit that we can test the data presented to the view, without needing the view content itself. The view here is entirely dumb which seems best. * [admin] fix test suite Co-authored-by: Mohsen Qureshi <[email protected]>
- Loading branch information
1 parent
3a55d51
commit a73eecb
Showing
7 changed files
with
199 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,41 @@ | ||
'use strict' | ||
const ejsUtil = require('../lib/ejs-util') | ||
|
||
const accessArrangementsOverviewPresenter = {} | ||
|
||
/** | ||
* Return list of pupils with appropriate styling properties | ||
* @param {Array} pupils | ||
* @param {Array} hl | ||
* @param {Object} availabilityData | ||
* @returns {Array} pupil data | ||
*/ | ||
accessArrangementsOverviewPresenter.getPresentationData = (pupils, availabilityData, hl) => { | ||
return pupils.map(pupil => { | ||
if (hl && hl.includes(pupil.urlSlug)) { | ||
let arrangementsLn = pupil.arrangements.length | ||
if (pupil.showDoB && arrangementsLn === 1) { | ||
arrangementsLn = 2 | ||
const accessArrangementsOverviewPresenter = { | ||
/** | ||
* Return list of pupils with appropriate styling properties | ||
* @param {Array} pupils | ||
* @param {Array} hl | ||
* @param {Object} availabilityData | ||
* @returns {Array} pupil data | ||
*/ | ||
getPresentationData: function getPresentationData (pupils, availabilityData, hl) { | ||
return pupils.map(pupil => { | ||
if (hl && hl.includes(pupil.urlSlug)) { | ||
let arrangementsLn = pupil.arrangements.length | ||
if (pupil.showDoB && arrangementsLn === 1) { | ||
arrangementsLn = 2 | ||
} | ||
pupil.verticalBarStyle = arrangementsLn > 1 ? `height:${235 - 35 * (7 - arrangementsLn)}px` : 'height:0px' | ||
} | ||
pupil.verticalBarStyle = arrangementsLn > 1 ? `height:${235 - 35 * (7 - arrangementsLn)}px` : 'height:0px' | ||
pupil.hasAAEditDisabled = !availabilityData.canEditArrangements || pupil.hasCompletedCheck || pupil.notTakingCheck | ||
return pupil | ||
}) | ||
}, | ||
|
||
/** | ||
* The retro input assistant text gives the user a link to retrospectively apply an access arrangment to a check. | ||
* As this only applies to live checks, we only want to show it when the check is active. | ||
* @param availabilityData | ||
* @return {Promise<string>} | ||
*/ | ||
getRetroInputAssistantText: async function getRetroInputAssistantText (availabilityData) { | ||
let html = '' | ||
if (!availabilityData.hdfSubmitted && availabilityData.checkWindowStarted) { | ||
html = await ejsUtil.render('access-arrangements/retro-input-assistant') | ||
} | ||
pupil.hasAAEditDisabled = !availabilityData.canEditArrangements || pupil.hasCompletedCheck || pupil.notTakingCheck | ||
return pupil | ||
}) | ||
return html | ||
} | ||
} | ||
|
||
module.exports = accessArrangementsOverviewPresenter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
const path = require('path') | ||
const ejs = require('ejs') | ||
const viewsDir = path.join(__dirname, '../views') | ||
|
||
const ejsUtil = { | ||
render: function ejsUtilRender (viewName, data = {}) { | ||
return new Promise((resolve, reject) => { | ||
const filename = path.join(viewsDir, viewName + '.ejs') | ||
ejs.renderFile(filename, data, { cache: true, escape: false }, | ||
function (err, str) { | ||
if (err) return reject(err) | ||
return resolve(str) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = ejsUtil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict' | ||
/* global test expect fail describe */ | ||
|
||
const sut = require('../../../lib/ejs-util') | ||
|
||
describe('ejsUtil', () => { | ||
test('it renders a relative template', async () => { | ||
try { | ||
const html = await sut.render('access-arrangements/retro-input-assistant', {}) | ||
expect(html).toContain('If you need to assign an input assistant after the pupil has taken the official check') | ||
console.log('html', html) | ||
} catch (error) { | ||
fail(error) | ||
} | ||
}) | ||
|
||
test('it does not escape html entities', async () => { | ||
try { | ||
const html = await sut.render('access-arrangements/retro-input-assistant', {}) | ||
expect(html).toContain('<div id="retroAddInputAssistantInfo">') | ||
} catch (error) { | ||
fail(error) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div id="retroAddInputAssistantInfo"> | ||
<p> | ||
If you need to assign an input assistant after the pupil has taken the official check go to | ||
<a href="/access-arrangements/retro-add-input-assistant">Record input assistant used for official check</a>. | ||
</p> | ||
</div> |