Always show 4 items in the example list

If a library has lots of items then the first 3 should be shown, with
a count of how many more there are, for a total of 4 list items:
> a, b, c, and 23 more

If the library only has 4 items then all 4 should be shown, with
consistent use of conjunction and Oxford comma[1]:
> a, b, c, and d

This keeps the lengths of the examples nice and consistent.

1. We use an Oxford comma because it helps disambiguate when an area
itself has a comma or ‘and’ in it, for example ‘Armagh City, Banbridge
and Craigavon’
This commit is contained in:
Chris Hill-Scott
2020-08-12 12:17:40 +01:00
parent dfa2ae0ced
commit 4242078885
3 changed files with 8 additions and 6 deletions

View File

@@ -121,7 +121,7 @@ class BroadcastAreasRepository(object):
),
area_count AS (SELECT COUNT(*) AS c FROM areas),
subset_area_count AS (SELECT c - 4 FROM area_count),
description_area_names AS (SELECT name FROM areas ORDER BY name ASC LIMIT 4),
description_area_names AS (SELECT name FROM areas ORDER BY name ASC LIMIT 3),
description_areas_joined AS (
SELECT GROUP_CONCAT(name, ", ") FROM description_area_names
)
@@ -129,6 +129,8 @@ class BroadcastAreasRepository(object):
CASE (SELECT * FROM subset_area_count)
WHEN 0 THEN
(SELECT * FROM description_areas_joined)
|| ", and "
|| (SELECT name from areas ORDER BY name DESC limit 1)
ELSE
(SELECT * FROM description_areas_joined)
|| ", and "

View File

@@ -48,20 +48,20 @@ def test_loads_areas_from_library():
def test_examples():
countries = broadcast_area_libraries.get('countries').get_examples()
assert countries == 'England, Northern Ireland, Scotland, Wales'
assert countries == 'England, Northern Ireland, Scotland, and Wales'
regions = broadcast_area_libraries.get('regions-of-england').get_examples()
assert regions == 'East Midlands, East of England, London, North East, and 5 more…'
assert regions == 'East Midlands, East of England, London, and 5 more…'
counties = broadcast_area_libraries.get(
'counties-and-unitary-authorities-in-england-and-wales',
).get_examples()
assert counties == 'Barking and Dagenham, Barnet, Barnsley, Bath and North East Somerset, and 170 more…'
assert counties == 'Barking and Dagenham, Barnet, Barnsley, and 170 more…'
wards = broadcast_area_libraries.get(
'electoral-wards-of-the-united-kingdom',
).get_examples()
assert wards == 'Aberdeen City, Aberdeenshire, Adur, Allerdale, and 375 more…'
assert wards == 'Aberdeen City, Aberdeenshire, Adur, and 375 more…'
@pytest.mark.parametrize('id', (

View File

@@ -299,7 +299,7 @@ def test_choose_broadcast_library_page(
])
assert normalize_spaces(page.select('.file-list-hint-large')[1].text) == (
'England, Northern Ireland, Scotland, Wales'
'England, Northern Ireland, Scotland, and Wales'
)
assert page.select_one('a.file-list-filename-large.govuk-link')['href'] == url_for(