@ons/design-system 72.2.0 → 72.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,381 +4,371 @@ import * as cheerio from 'cheerio';
4
4
 
5
5
  import axe from '../../tests/helpers/axe';
6
6
  import { renderComponent } from '../../tests/helpers/rendering';
7
-
8
- const EXAMPLE_DOCUMENT_LIST_BASIC = {
9
- title: {
10
- text: 'Crime and justice',
11
- url: '#0',
12
- },
13
- description: 'Some description',
14
- };
15
-
16
- const EXAMPLE_DOCUMENT_LIST_WITH_THUMBNAIL = {
17
- ...EXAMPLE_DOCUMENT_LIST_BASIC,
18
- thumbnail: {
19
- smallSrc: '/example-small.png',
20
- largeSrc: '/example-large.png',
21
- },
22
- };
23
-
24
- const EXAMPLE_DOCUMENT_LIST_WITH_METADATA_FILE = {
25
- ...EXAMPLE_DOCUMENT_LIST_BASIC,
26
- metadata: {
27
- file: {
28
- fileType: 'PDF',
29
- fileSize: '499KB',
30
- filePages: '1 page',
31
- },
32
- },
33
- };
34
-
35
- const EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT = {
36
- ...EXAMPLE_DOCUMENT_LIST_BASIC,
37
- metadata: {
38
- object: {
39
- text: 'Poster',
40
- url: '#0',
41
- ref: 'some ref',
42
- },
43
- },
44
- };
45
-
46
- const EXAMPLE_DOCUMENT_LIST_WITH_MULTIPLE = {
47
- ...EXAMPLE_DOCUMENT_LIST_BASIC,
48
- id: 'some-id',
49
- thumbnail: {
50
- smallSrc: '/example-small.png',
51
- largeSrc: '/example-large.png',
52
- },
53
- metadata: {
54
- object: {
55
- text: 'Poster',
56
- url: '#0',
57
- ref: 'some ref',
58
- },
59
- file: {
60
- fileType: 'PDF',
61
- fileSize: '499KB',
62
- filePages: '1 page',
63
- },
64
- date: {
65
- iso: '2022-01-01',
66
- short: '1 January 2022',
67
- showPrefix: true,
68
- prefix: 'Released',
69
- },
70
- },
71
- };
72
-
73
- describe('macro: document list', () => {
74
- describe('global configuration', () => {
75
- it('passes jest-axe checks', async () => {
7
+ import {
8
+ EXAMPLE_DOCUMENT_LIST_BASIC,
9
+ EXAMPLE_DOCUMENT_LIST_WITH_THUMBNAIL,
10
+ EXAMPLE_DOCUMENT_LIST_WITH_METADATA_FILE,
11
+ EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT,
12
+ EXAMPLE_DOCUMENT_LIST_WITH_METADATA_DATE,
13
+ EXAMPLE_DOCUMENT_LIST_WITH_MULTIPLE,
14
+ } from './_test-examples';
15
+
16
+ describe('FOR: Macro: Document list', () => {
17
+ describe('GIVEN: Params: required', () => {
18
+ describe('WHEN: required parameters are provided within a document', () => {
76
19
  const $ = cheerio.load(
77
20
  renderComponent('document-list', {
78
- id: 'some-id',
79
21
  documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC],
80
22
  }),
81
23
  );
82
-
83
- const results = await axe($.html());
84
- expect(results).toHaveNoViolations();
24
+ test('THEN: passes jest-axe checks', async () => {
25
+ const results = await axe($.html());
26
+ expect(results).toHaveNoViolations();
27
+ });
28
+
29
+ test('THEN: renders the same number of documents items as the number passed in', () => {
30
+ expect($('.ons-document-list__item').length).toBe(3);
31
+ });
32
+ test('THEN: has expected url for the title', () => {
33
+ expect($('.ons-document-list__item-title a').attr('href')).toBe('#0');
34
+ });
85
35
  });
36
+ });
86
37
 
87
- it('has the provided `id` attribute', () => {
88
- const $ = cheerio.load(
89
- renderComponent('document-list', {
90
- id: 'some-id',
91
- documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC],
92
- }),
93
- );
94
-
95
- expect($('#some-id').length).toBe(1);
38
+ describe('GIVEN: Params: description', () => {
39
+ describe('WHEN: description is provided', () => {
40
+ test('THEN: has expected description', () => {
41
+ const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_BASIC] }));
42
+ const title = $('.ons-document-list__item-description').html().trim();
43
+ expect(title).toBe('Some description');
44
+ });
96
45
  });
46
+ });
97
47
 
98
- it('has custom classes applied', () => {
99
- const $ = cheerio.load(
100
- renderComponent('document-list', {
101
- classes: 'custom-class',
102
- documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC],
103
- }),
104
- );
105
-
106
- expect($('.ons-document-list').hasClass('custom-class')).toBe(true);
48
+ describe('GIVEN: Params: id', () => {
49
+ describe('WHEN: id is provided', () => {
50
+ test('THEN: has the provided id attribute', () => {
51
+ const $ = cheerio.load(
52
+ renderComponent('document-list', {
53
+ id: 'some-id',
54
+ documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC],
55
+ }),
56
+ );
57
+ expect($('#some-id').length).toBe(1);
58
+ });
107
59
  });
60
+ });
108
61
 
109
- it('outputs the correct number of document items', () => {
110
- const $ = cheerio.load(
111
- renderComponent('document-list', {
112
- documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC],
113
- }),
114
- );
62
+ describe('GIVEN: Params: classes', () => {
63
+ describe('WHEN: additional style classes are provided', () => {
64
+ test('THEN: renders with additional classes provided', () => {
65
+ const $ = cheerio.load(
66
+ renderComponent('document-list', {
67
+ classes: 'custom-class',
68
+ documents: [EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC, EXAMPLE_DOCUMENT_LIST_BASIC],
69
+ }),
70
+ );
71
+ expect($('.ons-document-list').hasClass('custom-class')).toBe(true);
72
+ });
73
+ });
74
+ describe('WHEN: addtional style classes are provided within document', () => {
75
+ test('THEN: renders with additional classes provided', () => {
76
+ const $ = cheerio.load(
77
+ renderComponent('document-list', {
78
+ documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, classes: 'custom-class' }],
79
+ }),
80
+ );
81
+ expect($('.ons-document-list__item').hasClass('custom-class')).toBe(true);
82
+ });
83
+ });
84
+ });
85
+ describe('GIVEN: Params: attributes', () => {
86
+ describe('WHEN: attributes are provided', () => {
87
+ test('THEN: renders with provided HTML attributes', () => {
88
+ const $ = cheerio.load(
89
+ renderComponent('document-list', {
90
+ documents: [EXAMPLE_DOCUMENT_LIST_BASIC],
91
+ attributes: {
92
+ a: 123,
93
+ b: 456,
94
+ },
95
+ }),
96
+ );
97
+ expect($('.ons-document-list').attr('a')).toBe('123');
98
+ expect($('.ons-document-list').attr('b')).toBe('456');
99
+ });
100
+ });
101
+ describe('WHEN: attributes are provided within document', () => {
102
+ test('THEN: renders with provided HTML attributes', () => {
103
+ const $ = cheerio.load(
104
+ renderComponent('document-list', {
105
+ documents: [
106
+ {
107
+ ...EXAMPLE_DOCUMENT_LIST_BASIC,
108
+ attributes: {
109
+ a: 123,
110
+ b: 456,
111
+ },
112
+ },
113
+ ],
114
+ }),
115
+ );
116
+ expect($('.ons-document-list__item').attr('a')).toBe('123');
117
+ expect($('.ons-document-list__item').attr('b')).toBe('456');
118
+ });
119
+ });
120
+ });
115
121
 
116
- expect($('.ons-document-list__item').length).toBe(3);
122
+ describe('GIVEN: Params: headingLevel', () => {
123
+ describe('WHEN: headingLevel is provided', () => {
124
+ test('THEN: the heading tag is set to the level provided', () => {
125
+ const $ = cheerio.load(
126
+ renderComponent('document-list', {
127
+ headingLevel: 1,
128
+ documents: [EXAMPLE_DOCUMENT_LIST_BASIC],
129
+ }),
130
+ );
131
+ const headingLevel = $('.ons-document-list__item-title')[0].tagName;
132
+ expect(headingLevel).toBe('h1');
133
+ });
117
134
  });
135
+ });
118
136
 
119
- it('has the correct container if `fullWidth`', () => {
120
- const $ = cheerio.load(
121
- renderComponent('document-list', {
122
- documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true, fullWidth: true }],
123
- }),
124
- );
137
+ describe('GIVEN: Params: featured', () => {
138
+ describe('WHEN: featured is set for a document', () => {
139
+ test('THEN: applies the featured class to the document item', () => {
140
+ const $ = cheerio.load(
141
+ renderComponent('document-list', {
142
+ documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true }],
143
+ }),
144
+ );
125
145
 
126
- expect($('.ons-container').length).toBe(1);
146
+ expect($('.ons-document-list__item--featured').length).toBe(1);
147
+ });
127
148
  });
149
+ });
128
150
 
129
- it('has the correct container class if `fullWidth` and `wide`', () => {
130
- const $ = cheerio.load(
131
- renderComponent('document-list', {
132
- documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true, fullWidth: true, wide: true }],
133
- }),
134
- );
151
+ describe('GIVEN: Params: fullWidth', () => {
152
+ describe('WHEN: fullWidth is set for a document', () => {
153
+ test('THEN: document item does not have the container class', () => {
154
+ const $ = cheerio.load(
155
+ renderComponent('document-list', {
156
+ documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, fullWidth: true }],
157
+ }),
158
+ );
135
159
 
136
- expect($('.ons-container--wide').length).toBe(1);
160
+ expect($('.ons-document-list__item > .ons-container').length).toBe(0);
161
+ });
137
162
  });
138
163
 
139
- it('has the correct container class if `featured`', () => {
164
+ describe('WHEN: fullWidth is set for a featured document', () => {
140
165
  const $ = cheerio.load(
141
166
  renderComponent('document-list', {
142
- documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true }],
167
+ documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true, fullWidth: true }],
143
168
  }),
144
169
  );
170
+ test('THEN: applies full width class to document item', () => {
171
+ expect($('.ons-document-list__item--full-width').length).toBe(1);
172
+ });
145
173
 
146
- expect($('.ons-document-list__item--featured').length).toBe(1);
174
+ test('THEN: document item has the container class', () => {
175
+ expect($('.ons-document-list__item > .ons-container').length).toBe(1);
176
+ });
147
177
  });
178
+ });
148
179
 
149
- it('has the correct class for `showMetadataFirst`', () => {
150
- const $ = cheerio.load(
151
- renderComponent('document-list', {
152
- documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, showMetadataFirst: true }],
153
- }),
154
- );
180
+ describe('GIVEN: Params: wide', () => {
181
+ describe('WHEN: wide is set for a document', () => {
182
+ test('THEN: does not render with the wide container class', () => {
183
+ const $ = cheerio.load(
184
+ renderComponent('document-list', {
185
+ documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, wide: true }],
186
+ }),
187
+ );
155
188
 
156
- expect($('.ons-document-list__item-header--reverse').length).toBe(1);
189
+ expect($('.ons-container--wide').length).toBe(0);
190
+ });
157
191
  });
158
-
159
- it('overrides the heading title tag when `headingLevel` is provided', () => {
192
+ describe('WHEN: wide is set for a featured document with fullWidth', () => {
160
193
  const $ = cheerio.load(
161
194
  renderComponent('document-list', {
162
- headingLevel: 1,
163
- documents: [EXAMPLE_DOCUMENT_LIST_BASIC],
195
+ documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, featured: true, fullWidth: true, wide: true }],
164
196
  }),
165
197
  );
166
- const headingLevel = $('.ons-document-list__item-title')[0].tagName;
167
- expect(headingLevel).toBe('h1');
168
- });
169
-
170
- it('has expected `title`', () => {
171
- const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_BASIC] }));
172
- const title = $('.ons-document-list__item-title a').html().trim();
173
- expect(title).toBe('Crime and justice');
174
- });
198
+ test('THEN: applies the wide class to the container', () => {
199
+ expect($('.ons-container').hasClass('ons-container--wide')).toBe(true);
200
+ });
175
201
 
176
- it('has expected `url` for the title', () => {
177
- const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_BASIC] }));
178
- expect($('.ons-document-list__item-title a').attr('href')).toBe('#0');
202
+ test('THEN: document item has container--wide class', () => {
203
+ expect($('.ons-document-list__item > .ons-container--wide').length).toBe(1);
204
+ });
179
205
  });
206
+ });
180
207
 
181
- it('has expected `description`', () => {
182
- const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_BASIC] }));
183
- const title = $('.ons-document-list__item-description').html().trim();
184
- expect(title).toBe('Some description');
208
+ describe('GIVEN: Params: showMetadataFirst', () => {
209
+ describe('WHEN: showMetadataFirst is set for a document', () => {
210
+ test('THEN: applies the reverse class to document header to display the metadata before the title', () => {
211
+ const $ = cheerio.load(
212
+ renderComponent('document-list', {
213
+ documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, showMetadataFirst: true }],
214
+ }),
215
+ );
216
+ expect($('.ons-document-list__item-header--reverse').length).toBe(1);
217
+ });
185
218
  });
186
219
  });
187
220
 
188
- describe('mode: with thumbnail', () => {
189
- it('passes jest-axe checks', async () => {
221
+ describe('GIVEN: Params: thumbnail', () => {
222
+ describe('WHEN: thumbnail is provided for a document', () => {
190
223
  const $ = cheerio.load(
191
224
  renderComponent('document-list', {
192
- id: 'some-id',
193
225
  documents: [EXAMPLE_DOCUMENT_LIST_WITH_THUMBNAIL],
194
226
  }),
195
227
  );
196
228
 
197
- const results = await axe($.html());
198
- expect(results).toHaveNoViolations();
199
- });
200
-
201
- it('has expected `srcset` attribute', () => {
202
- const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_WITH_THUMBNAIL] }));
203
-
204
- const srcset = $('.ons-document-list__image-link img').attr('srcset');
205
- expect(srcset).toBe('/example-small.png 1x, /example-large.png 2x');
206
- });
229
+ test('THEN: passes jest-axe checks', async () => {
230
+ const results = await axe($.html());
231
+ expect(results).toHaveNoViolations();
232
+ });
207
233
 
208
- it('has expected `src` attribute', () => {
209
- const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_WITH_THUMBNAIL] }));
234
+ test('THEN: has expected srcset attribute', () => {
235
+ const srcset = $('.ons-document-list__image-link img').attr('srcset');
236
+ expect(srcset).toBe('/example-small.png 1x, /example-large.png 2x');
237
+ });
210
238
 
211
- const src = $('.ons-document-list__image-link img').attr('src');
212
- expect(src).toBe('/example-small.png');
239
+ test('THEN: has expected src attribute', () => {
240
+ const src = $('.ons-document-list__image-link img').attr('src');
241
+ expect(src).toBe('/example-small.png');
242
+ });
213
243
  });
214
244
 
215
- it('has the placeholder class if `thumbnail` is true', () => {
216
- const $ = cheerio.load(
217
- renderComponent('document-list', {
218
- documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, thumbnail: true }],
219
- }),
220
- );
221
-
222
- expect($('.ons-document-list__image-link').hasClass('ons-document-list__image-link--placeholder')).toBe(true);
245
+ describe('WHEN: thumbnail is not provided but is set to true', () => {
246
+ test('THEN: has a placeholder class', () => {
247
+ const $ = cheerio.load(
248
+ renderComponent('document-list', {
249
+ documents: [{ ...EXAMPLE_DOCUMENT_LIST_BASIC, thumbnail: true }],
250
+ }),
251
+ );
252
+ expect($('.ons-document-list__image-link').hasClass('ons-document-list__image-link--placeholder')).toBe(true);
253
+ });
223
254
  });
224
255
  });
225
256
 
226
- describe('mode: with metadata `file` configuration', () => {
227
- it('passes jest-axe checks', async () => {
228
- const $ = cheerio.load(
229
- renderComponent('document-list', {
230
- documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_FILE],
231
- }),
232
- );
233
-
234
- const results = await axe($.html());
235
- expect(results).toHaveNoViolations();
236
- });
237
-
238
- it('has visually hidden `file` information after the title', () => {
257
+ describe('GIVEN: Params: file', () => {
258
+ describe('WHEN: file configuration is provided within a document metadata', () => {
239
259
  const $ = cheerio.load(
240
260
  renderComponent('document-list', {
241
261
  documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_FILE],
242
262
  }),
243
263
  );
244
264
 
245
- const hiddenText = $('.ons-document-list__item-title a .ons-u-vh').text().trim();
246
- expect(hiddenText).toBe(', PDF document download, 499KB, 1 page');
247
- });
265
+ test('THEN: passes jest-axe checks', async () => {
266
+ const results = await axe($.html());
267
+ expect(results).toHaveNoViolations();
268
+ });
248
269
 
249
- it('has `file` information displayed', () => {
250
- const $ = cheerio.load(
251
- renderComponent('document-list', {
252
- documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_FILE],
253
- }),
254
- );
270
+ test('THEN: has visually hidden file information after the title', () => {
271
+ const hiddenText = $('.ons-document-list__item-title a .ons-u-vh').text().trim();
272
+ expect(hiddenText).toBe(', PDF document download, 499KB, 1 page');
273
+ });
255
274
 
256
- const hiddenText = $('.ons-document-list__item-attribute').text().trim();
257
- expect(hiddenText).toBe('PDF, 499KB, 1 page');
275
+ test('THEN: has file information', () => {
276
+ const fileInfo = $('.ons-document-list__item-attribute').text().trim();
277
+ expect(fileInfo).toBe('PDF, 499KB, 1 page');
278
+ });
258
279
  });
259
280
  });
260
281
 
261
- describe('mode: with metadata `object` configuration', () => {
262
- it('passes jest-axe checks', async () => {
282
+ describe('GIVEN: Params: object', () => {
283
+ describe('WHEN: object configuration is provided within a document metadata', () => {
263
284
  const $ = cheerio.load(
264
285
  renderComponent('document-list', {
265
286
  documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT],
266
287
  }),
267
288
  );
268
289
 
269
- const results = await axe($.html());
270
- expect(results).toHaveNoViolations();
271
- });
272
-
273
- it('has the provided `url`', () => {
274
- const $ = cheerio.load(
275
- renderComponent('document-list', {
276
- documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT],
277
- }),
278
- );
290
+ test('THEN: passes jest-axe checks', async () => {
291
+ const results = await axe($.html());
292
+ expect(results).toHaveNoViolations();
293
+ });
279
294
 
280
- const url = $('.ons-document-list__attribute-link').attr('href');
281
- expect(url).toBe('#0');
282
- });
295
+ test('THEN: has the provided url', () => {
296
+ const url = $('.ons-document-list__attribute-link').attr('href');
297
+ expect(url).toBe('#0');
298
+ });
283
299
 
284
- it('has expected `text`', () => {
285
- const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT] }));
286
- const text = $('.ons-document-list__attribute-link > span').text().trim();
287
- expect(text).toBe('Poster:');
288
- });
300
+ test('THEN: has expected text', () => {
301
+ const text = $('.ons-document-list__attribute-link > span').text().trim();
302
+ expect(text).toBe('Poster:');
303
+ });
289
304
 
290
- it('has expected `ref`', () => {
291
- const $ = cheerio.load(renderComponent('document-list', { documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_OBJECT] }));
292
- const text = $('.ons-document-list__attribute-link + span').text().trim();
293
- expect(text).toBe('some ref');
305
+ test('THEN: has expected ref', () => {
306
+ const text = $('.ons-document-list__attribute-link + span').text().trim();
307
+ expect(text).toBe('some ref');
308
+ });
294
309
  });
295
310
  });
296
311
 
297
- describe('mode: with metadata `date` configuration', () => {
298
- it('passes jest-axe checks', async () => {
312
+ describe('GIVEN: Params: date', () => {
313
+ describe('WHEN: date configuration is provided within a document metadata', () => {
299
314
  const $ = cheerio.load(
300
315
  renderComponent('document-list', {
301
- documents: [
302
- {
303
- ...EXAMPLE_DOCUMENT_LIST_BASIC,
304
- metadata: {
305
- date: {
306
- iso: '2022-01-01',
307
- short: '1 January 2022',
308
- },
309
- },
310
- },
311
- ],
316
+ documents: [EXAMPLE_DOCUMENT_LIST_WITH_METADATA_DATE],
312
317
  }),
313
318
  );
314
319
 
315
- const results = await axe($.html());
316
- expect(results).toHaveNoViolations();
317
- });
320
+ test('THEN: passes jest-axe checks', async () => {
321
+ const results = await axe($.html());
322
+ expect(results).toHaveNoViolations();
323
+ });
318
324
 
319
- it('has the default `prefix` text', () => {
320
- const $ = cheerio.load(
321
- renderComponent('document-list', {
322
- documents: [
323
- {
324
- ...EXAMPLE_DOCUMENT_LIST_BASIC,
325
- metadata: {
326
- date: {
327
- iso: '2022-01-01',
328
- short: '1 January 2022',
329
- },
330
- },
331
- },
332
- ],
333
- }),
334
- );
325
+ test('THEN: has the default prefix text', () => {
326
+ const text = $('.ons-document-list__item-attribute > span').text().trim();
327
+ expect(text).toBe('Published:');
328
+ });
335
329
 
336
- const text = $('.ons-document-list__item-attribute > span').text().trim();
337
- expect(text).toBe('Published:');
338
- });
330
+ test('THEN: has the visually hidden class for prefix text', () => {
331
+ expect($('.ons-document-list__item-attribute > span').hasClass('ons-u-vh')).toBe(true);
332
+ });
339
333
 
340
- it('has the visually hidden class for `prefix` text', () => {
341
- const $ = cheerio.load(
342
- renderComponent('document-list', {
343
- documents: [
344
- {
345
- ...EXAMPLE_DOCUMENT_LIST_BASIC,
346
- metadata: {
347
- date: {
348
- iso: '2022-01-01',
349
- short: '1 January 2022',
350
- },
351
- },
352
- },
353
- ],
354
- }),
355
- );
356
- expect($('.ons-document-list__item-attribute > span').hasClass('ons-u-vh')).toBe(true);
334
+ test('THEN: has the correct datetime attribute value', () => {
335
+ expect($('time').attr('datetime')).toBe('2022-01-01');
336
+ });
337
+
338
+ test('THEN: has the correct time value', () => {
339
+ const time = $('.ons-document-list__item-attribute time').text().trim();
340
+ expect(time).toBe('1 January 2022');
341
+ });
357
342
  });
343
+ });
358
344
 
359
- it('has the provided `prefix` text', () => {
360
- const $ = cheerio.load(
361
- renderComponent('document-list', {
362
- documents: [
363
- {
364
- ...EXAMPLE_DOCUMENT_LIST_BASIC,
365
- metadata: {
366
- date: {
367
- prefix: 'Released',
368
- iso: '2022-01-01',
369
- short: '1 January 2022',
345
+ describe('GIVEN: Params: prefix', () => {
346
+ describe('WHEN: prefix is provided in the date metadata configuration for a document', () => {
347
+ test('THEN: has the provided prefix text', () => {
348
+ const $ = cheerio.load(
349
+ renderComponent('document-list', {
350
+ documents: [
351
+ {
352
+ ...EXAMPLE_DOCUMENT_LIST_BASIC,
353
+ metadata: {
354
+ date: {
355
+ prefix: 'Released',
356
+ iso: '2022-01-01',
357
+ short: '1 January 2022',
358
+ },
370
359
  },
371
360
  },
372
- },
373
- ],
374
- }),
375
- );
376
-
377
- const text = $('.ons-document-list__item-attribute > span').text().trim();
378
- expect(text).toBe('Released:');
361
+ ],
362
+ }),
363
+ );
364
+ const text = $('.ons-document-list__item-attribute > span').text().trim();
365
+ expect(text).toBe('Released:');
366
+ });
379
367
  });
368
+ });
380
369
 
381
- it('has the correct class for `showPrefix`', () => {
370
+ describe('GIVEN: Params: showprefix', () => {
371
+ describe('WHEN: showprefix is set in the date metadata configuration for a document', () => {
382
372
  const $ = cheerio.load(
383
373
  renderComponent('document-list', {
384
374
  documents: [
@@ -396,80 +386,41 @@ describe('macro: document list', () => {
396
386
  }),
397
387
  );
398
388
 
399
- expect($('.ons-document-list__item-attribute > span').hasClass('ons-u-fw-b')).toBe(true);
400
- });
401
-
402
- it('has the correct datetime attribute value', () => {
403
- const $ = cheerio.load(
404
- renderComponent('document-list', {
405
- documents: [
406
- {
407
- ...EXAMPLE_DOCUMENT_LIST_BASIC,
408
- metadata: {
409
- date: {
410
- iso: '2022-01-01',
411
- short: '1 January 2022',
412
- },
413
- },
414
- },
415
- ],
416
- }),
417
- );
418
- expect($('time').attr('datetime')).toBe('2022-01-01');
419
- });
389
+ test('THEN: applies bold font class to the prefix text', () => {
390
+ expect($('.ons-document-list__item-attribute > span').hasClass('ons-u-fw-b')).toBe(true);
391
+ });
420
392
 
421
- it('has the correct `time` value', () => {
422
- const $ = cheerio.load(
423
- renderComponent('document-list', {
424
- documents: [
425
- {
426
- ...EXAMPLE_DOCUMENT_LIST_BASIC,
427
- metadata: {
428
- date: {
429
- iso: '2022-01-01',
430
- short: '1 January 2022',
431
- },
432
- },
433
- },
434
- ],
435
- }),
436
- );
393
+ test('THEN: does not has the visually hidden class for prefix text', () => {
394
+ expect($('.ons-document-list__item-attribute > span').hasClass('ons-u-vh')).toBe(false);
395
+ });
437
396
 
438
- const time = $('.ons-document-list__item-attribute time').text().trim();
439
- expect(time).toBe('1 January 2022');
397
+ test('THEN: has the default prefix text', () => {
398
+ const text = $('.ons-document-list__item-attribute > span').text().trim();
399
+ expect(text).toBe('Published:');
400
+ });
440
401
  });
441
402
  });
442
403
 
443
- describe('mode: with all parameters', () => {
444
- it('passes jest-axe checks', async () => {
445
- const $ = cheerio.load(
446
- renderComponent('document-list', {
447
- documents: [EXAMPLE_DOCUMENT_LIST_WITH_MULTIPLE],
448
- }),
449
- );
450
-
451
- const results = await axe($.html());
452
- expect(results).toHaveNoViolations();
453
- });
454
-
455
- it('has the correct document thumbnail class', async () => {
404
+ describe('GIVEN: Params: metadata', () => {
405
+ describe('WHEN: when document has metadata with all available configurations', () => {
456
406
  const $ = cheerio.load(
457
407
  renderComponent('document-list', {
458
408
  documents: [EXAMPLE_DOCUMENT_LIST_WITH_MULTIPLE],
459
409
  }),
460
410
  );
461
411
 
462
- expect($('.ons-document-list__item-image').hasClass('ons-document-list__item-image--file')).toBe(true);
463
- });
412
+ test('THEN: passes jest-axe checks', async () => {
413
+ const results = await axe($.html());
414
+ expect(results).toHaveNoViolations();
415
+ });
464
416
 
465
- it('has the correct document list class', async () => {
466
- const $ = cheerio.load(
467
- renderComponent('document-list', {
468
- documents: [EXAMPLE_DOCUMENT_LIST_WITH_MULTIPLE],
469
- }),
470
- );
417
+ test('THEN: has the correct document thumbnail class', async () => {
418
+ expect($('.ons-document-list__item-image').hasClass('ons-document-list__item-image--file')).toBe(true);
419
+ });
471
420
 
472
- expect($('.ons-document-list__item-attribute').hasClass('ons-u-mr-no')).toBe(true);
421
+ test('THEN: the document list object item has the utility class that removes the margin between the object and file list items', async () => {
422
+ expect($('.ons-document-list__item-attribute').hasClass('ons-u-mr-no')).toBe(true);
423
+ });
473
424
  });
474
425
  });
475
426
  });