@@ -5,13 +5,13 @@ import { enhanceTimeline } from './enhanceTimeline';
5
5
6
6
const identity = < A > ( a : A ) : A => a ;
7
7
8
- const elements : FEElement [ ] = [
8
+ const elementsWithNoSections : FEElement [ ] = [
9
9
{
10
10
_type : 'model.dotcomrendering.pageElements.TimelineBlockElement' ,
11
11
elementId : 'mock-id' ,
12
12
sections : [
13
13
{
14
- title : 'mock section title ' ,
14
+ title : '' ,
15
15
events : [
16
16
{
17
17
title : 'mock event title' ,
@@ -73,9 +73,76 @@ const elements: FEElement[] = [
73
73
} ,
74
74
] ;
75
75
76
+ const elementsWithOneSection : FEElement [ ] = [
77
+ {
78
+ _type : 'model.dotcomrendering.pageElements.TimelineBlockElement' ,
79
+ elementId : 'mock-id' ,
80
+ sections : [
81
+ {
82
+ title : 'Section 1' ,
83
+ events : [
84
+ {
85
+ title : 'mock event title' ,
86
+ date : '1st January 2024' ,
87
+ body : [ ] ,
88
+ // Showcase image
89
+ main : images [ 0 ] ,
90
+ } ,
91
+ {
92
+ title : 'mock event title' ,
93
+ date : '5th January 2024' ,
94
+ body : [ ] ,
95
+ // Half width image
96
+ main : images [ 3 ] ,
97
+ } ,
98
+ ] ,
99
+ } ,
100
+ ] ,
101
+ } ,
102
+ ] ;
103
+
104
+ const elementsWithMultipleSections : FEElement [ ] = [
105
+ {
106
+ _type : 'model.dotcomrendering.pageElements.TimelineBlockElement' ,
107
+ elementId : 'mock-id' ,
108
+ sections : [
109
+ {
110
+ title : 'Section 1' ,
111
+ events : [
112
+ {
113
+ title : 'Event 1 title' ,
114
+ date : '1st January 2024' ,
115
+ body : [ ] ,
116
+ } ,
117
+ {
118
+ title : 'Event 2 title' ,
119
+ date : '5th January 2024' ,
120
+ body : [ ] ,
121
+ } ,
122
+ ] ,
123
+ } ,
124
+ {
125
+ title : 'Section 2' ,
126
+ events : [
127
+ {
128
+ title : 'Event 3 title' ,
129
+ date : '1st March 2024' ,
130
+ body : [ ] ,
131
+ } ,
132
+ {
133
+ title : 'Event 4 title' ,
134
+ date : '5th March 2024' ,
135
+ body : [ ] ,
136
+ } ,
137
+ ] ,
138
+ } ,
139
+ ] ,
140
+ } ,
141
+ ] ;
142
+
76
143
describe ( 'enhanceTimeline' , ( ) => {
77
144
it ( 'keeps a main media with a role that is valid' , ( ) => {
78
- const enhanced = enhanceTimeline ( identity ) ( elements ) ;
145
+ const enhanced = enhanceTimeline ( identity ) ( elementsWithNoSections ) ;
79
146
assert . equal (
80
147
enhanced [ 0 ] ?. _type ,
81
148
'model.dotcomrendering.pageElements.DCRTimelineBlockElement' ,
@@ -87,7 +154,7 @@ describe('enhanceTimeline', () => {
87
154
} ) ;
88
155
89
156
it ( 'drops a main media with a role that is not valid' , ( ) => {
90
- const enhanced = enhanceTimeline ( identity ) ( elements ) ;
157
+ const enhanced = enhanceTimeline ( identity ) ( elementsWithNoSections ) ;
91
158
assert . equal (
92
159
enhanced [ 0 ] ?. _type ,
93
160
'model.dotcomrendering.pageElements.DCRTimelineBlockElement' ,
@@ -99,7 +166,7 @@ describe('enhanceTimeline', () => {
99
166
} ) ;
100
167
101
168
it ( 'keeps a main media without a role' , ( ) => {
102
- const enhanced = enhanceTimeline ( identity ) ( elements ) ;
169
+ const enhanced = enhanceTimeline ( identity ) ( elementsWithNoSections ) ;
103
170
assert . equal (
104
171
enhanced [ 0 ] ?. _type ,
105
172
'model.dotcomrendering.pageElements.DCRTimelineBlockElement' ,
@@ -110,7 +177,7 @@ describe('enhanceTimeline', () => {
110
177
expect ( timelineEvent ?. main ) . toBeDefined ( ) ;
111
178
} ) ;
112
179
it ( 'keeps a body element with a role that is valid' , ( ) => {
113
- const enhanced = enhanceTimeline ( identity ) ( elements ) ;
180
+ const enhanced = enhanceTimeline ( identity ) ( elementsWithNoSections ) ;
114
181
assert . equal (
115
182
enhanced [ 0 ] ?. _type ,
116
183
'model.dotcomrendering.pageElements.DCRTimelineBlockElement' ,
@@ -122,7 +189,7 @@ describe('enhanceTimeline', () => {
122
189
} ) ;
123
190
124
191
it ( 'drops a body element with a role that is not valid' , ( ) => {
125
- const enhanced = enhanceTimeline ( identity ) ( elements ) ;
192
+ const enhanced = enhanceTimeline ( identity ) ( elementsWithNoSections ) ;
126
193
assert . equal (
127
194
enhanced [ 0 ] ?. _type ,
128
195
'model.dotcomrendering.pageElements.DCRTimelineBlockElement' ,
@@ -134,7 +201,7 @@ describe('enhanceTimeline', () => {
134
201
} ) ;
135
202
136
203
it ( 'keeps a body element without a role' , ( ) => {
137
- const enhanced = enhanceTimeline ( identity ) ( elements ) ;
204
+ const enhanced = enhanceTimeline ( identity ) ( elementsWithNoSections ) ;
138
205
assert . equal (
139
206
enhanced [ 0 ] ?. _type ,
140
207
'model.dotcomrendering.pageElements.DCRTimelineBlockElement' ,
@@ -151,4 +218,29 @@ describe('enhanceTimeline', () => {
151
218
} ,
152
219
] ) ;
153
220
} ) ;
221
+
222
+ it ( 'enhances a timeline with one section appropriately' , ( ) => {
223
+ const enhanced = enhanceTimeline ( identity ) ( elementsWithOneSection ) ;
224
+ assert . equal (
225
+ enhanced [ 0 ] ?. _type ,
226
+ 'model.dotcomrendering.pageElements.DCRSectionedTimelineBlockElement' ,
227
+ ) ;
228
+
229
+ const timelineSection = enhanced [ 0 ] . sections [ 0 ] ;
230
+ assert . notEqual ( timelineSection , undefined ) ;
231
+ expect ( timelineSection ?. title ) . toEqual ( 'Section 1' ) ;
232
+ } ) ;
233
+
234
+ it ( 'enhances a timeline with multiple sections appropriately' , ( ) => {
235
+ const enhanced = enhanceTimeline ( identity ) (
236
+ elementsWithMultipleSections ,
237
+ ) ;
238
+ assert . equal (
239
+ enhanced [ 0 ] ?. _type ,
240
+ 'model.dotcomrendering.pageElements.DCRSectionedTimelineBlockElement' ,
241
+ ) ;
242
+
243
+ const timelineSections = enhanced [ 0 ] . sections ;
244
+ expect ( timelineSections ) . toHaveLength ( 2 ) ;
245
+ } ) ;
154
246
} ) ;
0 commit comments