Skip to content

Commit 801154e

Browse files
authored
Merge pull request #1411 from ministryofjustice/APS-195
APS-195: Add links to Timeline events
2 parents 0f46304 + 1afe3d7 commit 801154e

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

integration_tests/pages/apply/showPage.ts

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ export default class ShowPage extends Page {
125125
timelineEvents[index].createdBy.name,
126126
)
127127
}
128+
cy.get('.govuk-link').should('have.attr', { time: timelineEvents[index].associatedUrls[0].url })
129+
cy.get('.govuk-link').should('contain', timelineEvents[index].associatedUrls[0].type)
128130
cy.get('time').should('contain', DateFormats.isoDateTimeToUIDateTime(timelineEvents[index].occurredAt))
129131
})
130132
})

server/testutils/factories/timelineEvent.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export default Factory.define<TimelineEvent>(() => ({
2525
] as const),
2626
content: Math.random() < 0.5 ? faker.lorem.sentences() : undefined,
2727
createdBy: userFactory.build(),
28+
associatedUrls: [{ type: 'application', url: faker.internet.url() }],
2829
}))

server/utils/applications/utils.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,30 @@ describe('utils', () => {
667667
describe('mapTimelineEventsForUi', () => {
668668
it('maps the events into the format required by the MoJ UI Timeline component', () => {
669669
const timelineEvents = timelineEventFactory.buildList(1)
670+
expect(mapTimelineEventsForUi(timelineEvents)).toEqual([
671+
{
672+
datetime: {
673+
timestamp: timelineEvents[0].occurredAt,
674+
date: DateFormats.isoDateTimeToUIDateTime(timelineEvents[0].occurredAt),
675+
},
676+
label: {
677+
text: eventTypeTranslations[timelineEvents[0].type],
678+
},
679+
content: timelineEvents[0].content,
680+
createdBy: timelineEvents[0].createdBy.name,
681+
associatedUrls: [
682+
{
683+
type: timelineEvents[0].associatedUrls[0].type,
684+
url: timelineEvents[0].associatedUrls[0].url,
685+
},
686+
],
687+
},
688+
])
689+
})
690+
691+
it('maps the events into the format required by the MoJ UI Timeline component without associatedUrls', () => {
692+
const timelineEvents = timelineEventFactory.buildList(1, { associatedUrls: undefined })
693+
670694
expect(mapTimelineEventsForUi(timelineEvents)).toEqual([
671695
{
672696
datetime: {

server/utils/applications/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ const mapTimelineEventsForUi = (timelineEvents: Array<TimelineEvent>): Array<UiT
297297
date: DateFormats.isoDateTimeToUIDateTime(timelineEvent.occurredAt),
298298
},
299299
content: timelineEvent.content,
300+
associatedUrls: timelineEvent.associatedUrls,
300301
}
301302
if (timelineEvent.createdBy?.name) {
302303
return {

server/views/applications/partials/_timeline.njk

+25-14
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,33 @@
2929

3030
<div class="moj-timeline__header">
3131
<h3 class="moj-timeline__title">{{event.label.text}}</h3>
32-
{% if event.createdBy %}
33-
<p class="moj-timeline__byline">by {{event.createdBy}}</p>
32+
{% if event.createdBy %}
33+
<p class="moj-timeline__byline">by {{event.createdBy}}</p>
3434
{%endif%}
35-
</div>
35+
</div>
3636

37-
<p class="moj-timeline__date">
38-
<time datetime="{{event.datetime.timestamp}}">{{event.datetime.date}}</time>
39-
</p>
37+
<p class="moj-timeline__date">
38+
<time datetime="{{event.datetime.timestamp}}">{{event.datetime.date}}</time>
39+
</p>
4040

41-
{% if event.content %}
42-
<div class="moj-timeline__description">
43-
<p>{{event.content}}</p>
44-
</div>
45-
{%endif%}
41+
{% if event.content %}
42+
<div class="moj-timeline__description">
43+
<p>{{event.content}}</p>
44+
</div>
45+
{%endif%}
46+
{% if event.associatedUrls %}
47+
{% for associatedUrl in event.associatedUrls %}
48+
<div class="moj-timeline__description">
49+
<ul class="govuk-list govuk-list--bullet">
50+
<li>
51+
<a class="govuk-link" href="{{associatedUrl.url}}">View {{associatedUrl.type}}</a>
52+
</li>
53+
</ul>
54+
</div>
55+
{% endfor %}
56+
{%endif%}
57+
</div>
58+
{% endfor %}
4659
</div>
47-
{% endfor %}
48-
</div>
4960

50-
{% endmacro %}
61+
{% endmacro %}

0 commit comments

Comments
 (0)