Skip to content

Commit e4cecae

Browse files
committed
Enforce use of --no-visited-link-state
We don’t use colour to indicate visited link state. To acheive this we use the `govuk-link--no-visited-link-state` modifier from GOV.UK Frontend. In case someone misses this, this commit adds a test which checks for any links missing this class.
1 parent f874de1 commit e4cecae

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

app/templates/views/document-download/confirm-email-address.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
<p class="govuk-body">
2121
If you have any questions,
2222
{% if current_service.contact_details_type == "url" %}
23-
<a href="{{ current_service.contact_link }}" class="govuk-link" rel="noreferrer"> contact {{ current_service.name }}</a>.
23+
<a href="{{ current_service.contact_link }}" class="govuk-link govuk-link--no-visited-state" rel="noreferrer"> contact {{ current_service.name }}</a>.
2424
{% elif current_service.contact_details_type == "email_address" %}
25-
email <a href="mailto:{{ current_service.contact_link }}" class="govuk-link">{{ current_service.contact_link }}</a>.
25+
email <a href="mailto:{{ current_service.contact_link }}" class="govuk-link govuk-link--no-visited-state">{{ current_service.contact_link }}</a>.
2626
{% else %}
2727
call {{ current_service.contact_link }}.
2828
{% endif %}

app/templates/views/document-download/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<p class="govuk-body">
1818
If you have any questions,
1919
{% if current_service.contact_details_type == "url" %}
20-
<a href="{{ current_service.contact_link }}" class="govuk-link" rel="noreferrer"> contact {{ current_service.name }}</a>.
20+
<a href="{{ current_service.contact_link }}" class="govuk-link govuk-link--no-visited-state" rel="noreferrer"> contact {{ current_service.name }}</a>.
2121
{% elif current_service.contact_details_type == "email_address" %}
22-
email <a href="mailto:{{ current_service.contact_link }}" class="govuk-link">{{ current_service.contact_link }}</a>.
22+
email <a href="mailto:{{ current_service.contact_link }}" class="govuk-link govuk-link--no-visited-state">{{ current_service.contact_link }}</a>.
2323
{% else %}
2424
call {{ current_service.contact_link }}.
2525
{% endif %}

app/templates/views/returned-letters.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
{% endif %}
2424

2525
<p class="bottom-gutter">
26-
<a download href="{{ url_for('main.returned_letters_report', service_id=current_service.id, reported_at=reported_at) }}" class="govuk-link heading-small">Download this report (<abbr title="Comma separated values">CSV</abbr>)</a>
26+
<a download href="{{ url_for('main.returned_letters_report', service_id=current_service.id, reported_at=reported_at) }}" class="govuk-link govuk-link--no-visited-state heading-small">Download this report (<abbr title="Comma separated values">CSV</abbr>)</a>
2727
</p>
2828

2929
<div class="dashboard-table">

app/templates/views/templates/email-template-files/email_file.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
template_id=template_id,
3232
template_email_file_id=template_email_file_data.id),
3333
"text": "Change",
34+
"classes": "govuk-link--no-visited-state",
3435
}
3536
]
3637
}
@@ -49,6 +50,7 @@
4950
"href": url_for("main.change_data_retention_period", service_id=current_service.id,
5051
template_id=template_id,template_email_file_id=template_email_file_data.id),
5152
"text": "Change",
53+
"classes": "govuk-link--no-visited-state",
5254
}
5355
]
5456
}
@@ -67,7 +69,7 @@
6769
"href": url_for("main.change_email_validation", service_id=current_service.id,
6870
template_id=template_id,template_email_file_id=template_email_file_data.id),
6971
"text": "Change",
70-
"classes": "govuk-link--no-visited-state"
72+
"classes": "govuk-link--no-visited-state",
7173
}
7274
]
7375
},

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,6 +3062,8 @@ def get_url(
30623062
if _test_for_non_smart_quotes:
30633063
ClientRequest.test_for_non_smart_quotes(page)
30643064

3065+
ClientRequest.test_for_visited_links(page)
3066+
30653067
ClientRequest.test_for_missing_en_dashes(page)
30663068

30673069
if _test_for_script_csp_nonce:
@@ -3196,6 +3198,23 @@ def test_for_elements_without_class(page):
31963198
"Use govuk-heading-l or set error_summary_enabled=False"
31973199
)
31983200

3201+
@staticmethod
3202+
def test_for_visited_links(page):
3203+
for element in page.select(f"a.govuk-link"):
3204+
if set(element["class"]).intersection({
3205+
# Link modifiers which already override the visited state
3206+
"govuk-link--destructive",
3207+
"govuk-link--inverse",
3208+
"govuk-link--text-colour",
3209+
}):
3210+
continue
3211+
assert 'govuk-link--no-visited-state' in element["class"], (
3212+
f"Found an <a> element with a visited link state:\n"
3213+
f" {element}\n"
3214+
f"\n"
3215+
f'(you probably want to add govuk-link--no-visited-state to the class attribute")'
3216+
)
3217+
31993218
@staticmethod
32003219
def test_forms_have_an_action_set(page):
32013220
assert not len(

0 commit comments

Comments
 (0)