@defra/lis-infra-ui-services 0.19.0 → 0.20.0-lreg-596.alpha.1
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.
package/package.json
CHANGED
|
@@ -225,6 +225,90 @@ test('shows the results range for the current page', () => {
|
|
|
225
225
|
assert.match(html, /Showing 6 to 7 of 7 results/)
|
|
226
226
|
})
|
|
227
227
|
|
|
228
|
+
test('renders the summary above the pagination by default', () => {
|
|
229
|
+
const html = render({
|
|
230
|
+
caption: 'Animals',
|
|
231
|
+
columns,
|
|
232
|
+
rows,
|
|
233
|
+
baseHref: '/animals',
|
|
234
|
+
pagination: {
|
|
235
|
+
currentPage: 1,
|
|
236
|
+
totalPages: 2,
|
|
237
|
+
totalItems: 7,
|
|
238
|
+
itemsPerPage: 5
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
assert.ok(
|
|
243
|
+
html.indexOf('Showing 1 to 5 of 7') < html.indexOf('govuk-pagination')
|
|
244
|
+
)
|
|
245
|
+
assert.doesNotMatch(html, /govuk-grid-row/)
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
test('always states the range, without "results", in the range summary format', () => {
|
|
249
|
+
const html = render({
|
|
250
|
+
caption: 'Animals',
|
|
251
|
+
columns,
|
|
252
|
+
rows,
|
|
253
|
+
baseHref: '/animals',
|
|
254
|
+
summaryFormat: 'range',
|
|
255
|
+
pagination: {
|
|
256
|
+
currentPage: 1,
|
|
257
|
+
totalPages: 1,
|
|
258
|
+
totalItems: 7,
|
|
259
|
+
itemsPerPage: 25
|
|
260
|
+
}
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
assert.match(html, /Showing 1 to 7 of 7</)
|
|
264
|
+
assert.doesNotMatch(html, /results/)
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
test('puts the summary beside the pagination, below the table, when positioned below', () => {
|
|
268
|
+
const html = render({
|
|
269
|
+
caption: 'Animals',
|
|
270
|
+
columns,
|
|
271
|
+
rows,
|
|
272
|
+
baseHref: '/animals',
|
|
273
|
+
summaryPosition: 'below',
|
|
274
|
+
pagination: {
|
|
275
|
+
currentPage: 1,
|
|
276
|
+
totalPages: 2,
|
|
277
|
+
totalItems: 7,
|
|
278
|
+
itemsPerPage: 5
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
assert.ok(html.indexOf('</table>') < html.indexOf('govuk-pagination'))
|
|
283
|
+
assert.ok(
|
|
284
|
+
html.indexOf('govuk-pagination') < html.indexOf('Showing 1 to 5 of 7')
|
|
285
|
+
)
|
|
286
|
+
assert.match(
|
|
287
|
+
html,
|
|
288
|
+
/govuk-grid-column-one-third govuk-!-text-align-right">\s*<p class="govuk-body govuk-!-margin-top-2">Showing 1 to 5 of 7 results<\/p>/
|
|
289
|
+
)
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
test('puts the summary alone below the table when positioned below with a single page', () => {
|
|
293
|
+
const html = render({
|
|
294
|
+
caption: 'Animals',
|
|
295
|
+
columns,
|
|
296
|
+
rows,
|
|
297
|
+
baseHref: '/animals',
|
|
298
|
+
summaryPosition: 'below',
|
|
299
|
+
pagination: {
|
|
300
|
+
currentPage: 1,
|
|
301
|
+
totalPages: 1,
|
|
302
|
+
totalItems: 7,
|
|
303
|
+
itemsPerPage: 25
|
|
304
|
+
}
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
assert.ok(html.indexOf('</table>') < html.indexOf('Showing 7 results'))
|
|
308
|
+
assert.doesNotMatch(html, /govuk-grid-row/)
|
|
309
|
+
assert.doesNotMatch(html, /govuk-pagination/)
|
|
310
|
+
})
|
|
311
|
+
|
|
228
312
|
test('renders pagination items and next but no previous on the first page', () => {
|
|
229
313
|
const html = render({
|
|
230
314
|
caption: 'Animals',
|
|
@@ -66,10 +66,13 @@
|
|
|
66
66
|
{%- set lastItemOnPage = currentPage * itemsPerPage -%}
|
|
67
67
|
{%- set endItem = totalItems if lastItemOnPage > totalItems else lastItemOnPage -%}
|
|
68
68
|
|
|
69
|
-
{
|
|
70
|
-
|
|
69
|
+
{#- "range" always states the range, even on a single page: "Showing 1 to 7 of 7" -#}
|
|
70
|
+
{%- if params.summaryFormat == "range" -%}
|
|
71
|
+
{%- set summaryText = "Showing " ~ startItem ~ " to " ~ endItem ~ " of " ~ totalItems -%}
|
|
72
|
+
{%- elif totalPages > 1 -%}
|
|
73
|
+
{%- set summaryText = "Showing " ~ startItem ~ " to " ~ endItem ~ " of " ~ totalItems ~ " results" -%}
|
|
71
74
|
{%- else -%}
|
|
72
|
-
|
|
75
|
+
{%- set summaryText = "Showing " ~ totalItems ~ (" results" if totalItems != 1 else " result") -%}
|
|
73
76
|
{%- endif -%}
|
|
74
77
|
|
|
75
78
|
{%- if totalPages > 1 -%}
|
|
@@ -82,10 +85,33 @@
|
|
|
82
85
|
{%- set previousHref = params.baseHref ~ "?" ~ (query | assign({ sort: params.sort, direction: params.direction, page: currentPage - 1 }) | queryString) -%}
|
|
83
86
|
{%- set nextHref = params.baseHref ~ "?" ~ (query | assign({ sort: params.sort, direction: params.direction, page: currentPage + 1 }) | queryString) -%}
|
|
84
87
|
|
|
85
|
-
{
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
{%- set paginationHtml -%}
|
|
89
|
+
{{ govukPagination({
|
|
90
|
+
items: items,
|
|
91
|
+
previous: { href: previousHref } if currentPage > 1 else undefined,
|
|
92
|
+
next: { href: nextHref } if currentPage < totalPages else undefined
|
|
93
|
+
}) }}
|
|
94
|
+
{%- endset -%}
|
|
95
|
+
{%- endif -%}
|
|
96
|
+
|
|
97
|
+
{#- "below" puts the summary under the table, beside the page links when there are any -#}
|
|
98
|
+
{%- if params.summaryPosition == "below" -%}
|
|
99
|
+
{%- if totalPages > 1 -%}
|
|
100
|
+
<div class="govuk-grid-row">
|
|
101
|
+
<div class="govuk-grid-column-two-thirds">
|
|
102
|
+
{{ paginationHtml | safe }}
|
|
103
|
+
</div>
|
|
104
|
+
<div class="govuk-grid-column-one-third govuk-!-text-align-right">
|
|
105
|
+
<p class="govuk-body govuk-!-margin-top-2">{{ summaryText }}</p>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
{%- else -%}
|
|
109
|
+
<p class="govuk-body">{{ summaryText }}</p>
|
|
110
|
+
{%- endif -%}
|
|
111
|
+
{%- else -%}
|
|
112
|
+
<p class="govuk-body">{{ summaryText }}</p>
|
|
113
|
+
{%- if totalPages > 1 -%}
|
|
114
|
+
{{ paginationHtml | safe }}
|
|
115
|
+
{%- endif -%}
|
|
90
116
|
{%- endif -%}
|
|
91
117
|
{%- endif -%}
|