Skip to content

Commit

Permalink
feat(per): Display card tags from Person Escort Record
Browse files Browse the repository at this point in the history
This updates the profile to card component to display tags based
on the Person Escort Record instead of the previous assessment answers.

Because the feature is being developed in the background to avoid any
breaking changes this change needs to support the existing method unless
a feature flag is enabled.
  • Loading branch information
teneightfive committed Jul 28, 2020
1 parent 0097c62 commit 43fd58b
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 5 deletions.
32 changes: 28 additions & 4 deletions common/presenters/profile-to-card-component.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
const { filter } = require('lodash')

const { FEATURE_FLAGS } = require('../../config')
const i18n = require('../../config/i18n')
const filters = require('../../config/nunjucks/filters')

const assessmentToTagList = require('./assessment-to-tag-list')
const frameworkFlagsToTagList = require('./framework-flags-to-tag-list')

function profileToCardComponent({
showImage = true,
showMeta = true,
showTags = true,
} = {}) {
return function item(profile) {
profile = profile || {}
const { href, assessment_answers: assessmentAnswers, person = {} } = profile
const {
assessment_answers: assessmentAnswers,
href,
person = {},
person_escort_record: personEscortRecord,
} = profile || {}
const {
id,
gender,
Expand Down Expand Up @@ -54,8 +60,26 @@ function profileToCardComponent({
}

if (showTags) {
card.tags = {
items: assessmentToTagList(assessmentAnswers, href),
// TODO: Remove feature flag condition once PER is enabled everywhere
if (FEATURE_FLAGS.PERSON_ESCORT_RECORD) {
const { flags, status } = personEscortRecord || {}
const isComplete =
personEscortRecord && !['not_started', 'in_progress'].includes(status)

if (isComplete) {
card.tags = {
items: frameworkFlagsToTagList(flags, href),
}
} else {
card.insetText = {
classes: 'govuk-inset-text--compact',
text: i18n.t('person-escort-record::flags.incomplete'),
}
}
} else {
card.tags = {
items: assessmentToTagList(assessmentAnswers, href),
}
}
}

Expand Down
140 changes: 139 additions & 1 deletion common/presenters/profile-to-card-component.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
const proxyquire = require('proxyquire').noCallThru()

const i18n = require('../../config/i18n')
const filters = require('../../config/nunjucks/filters')

const profileToCardComponent = require('./profile-to-card-component')
const profileToCardComponent = proxyquire('./profile-to-card-component', {
'../../config': {
FEATURE_FLAGS: {
PERSON_ESCORT_RECORD: false,
},
},
})

const mockProfile = {
id: '12345',
Expand Down Expand Up @@ -341,6 +349,136 @@ describe('Presenters', function () {
])
})
})

context('with Person Escort Record feature flag', function () {
const frameworkFlagsToTagListStub = sinon
.stub()
.returns(['1', '2', '3'])
const profileToCardComponentWithPER = proxyquire(
'./profile-to-card-component',
{
'../../config': {
FEATURE_FLAGS: {
PERSON_ESCORT_RECORD: true,
},
},
'./framework-flags-to-tag-list': frameworkFlagsToTagListStub,
}
)

context('with no Person Escort Record', function () {
beforeEach(function () {
transformedResponse = profileToCardComponentWithPER()(mockProfile)
})

it('should not contain tags', function () {
expect(transformedResponse).not.to.have.property('tags')
})

it('should not contain inset text message', function () {
expect(transformedResponse).to.have.property('insetText')
expect(transformedResponse.insetText).to.deep.equal({
classes: 'govuk-inset-text--compact',
text: '__translated__',
})
})

it('should translate inset text message', function () {
expect(i18n.t).to.have.been.calledWithExactly(
'person-escort-record::flags.incomplete'
)
})
})

context('with Person Escort Record', function () {
context('with `not_started` PER', function () {
beforeEach(function () {
transformedResponse = profileToCardComponentWithPER()({
...mockProfile,
person_escort_record: {
status: 'not_started',
},
})
})

it('should not contain tags', function () {
expect(transformedResponse).not.to.have.property('tags')
})

it('should not contain inset text message', function () {
expect(transformedResponse).to.have.property('insetText')
expect(transformedResponse.insetText).to.deep.equal({
classes: 'govuk-inset-text--compact',
text: '__translated__',
})
})

it('should translate inset text message', function () {
expect(i18n.t).to.have.been.calledWithExactly(
'person-escort-record::flags.incomplete'
)
})
})

context('with `in_progress` PER', function () {
beforeEach(function () {
transformedResponse = profileToCardComponentWithPER()({
...mockProfile,
person_escort_record: {
status: 'in_progress',
},
})
})

it('should not contain tags', function () {
expect(transformedResponse).not.to.have.property('tags')
})

it('should not contain inset text message', function () {
expect(transformedResponse).to.have.property('insetText')
expect(transformedResponse.insetText).to.deep.equal({
classes: 'govuk-inset-text--compact',
text: '__translated__',
})
})

it('should translate inset text message', function () {
expect(i18n.t).to.have.been.calledWithExactly(
'person-escort-record::flags.incomplete'
)
})
})

context('with `completed` PER', function () {
beforeEach(function () {
transformedResponse = profileToCardComponentWithPER()({
...mockProfile,
person_escort_record: {
status: 'completed',
flags: ['foo', 'bar'],
},
})
})

it('should contain tags', function () {
expect(transformedResponse).to.have.property('tags')
expect(transformedResponse.tags).to.deep.equal({
items: ['1', '2', '3'],
})
})

it('should call frameworkFlagsToTagList presenter', function () {
expect(
frameworkFlagsToTagListStub
).to.have.been.calledWithExactly(['foo', 'bar'], '/move/12345')
})

it('should not contain inset text message', function () {
expect(transformedResponse).not.to.have.property('insetText')
})
})
})
})
})

context('with meta disabled', function () {
Expand Down

0 comments on commit 43fd58b

Please sign in to comment.