mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 17:45:32 -04:00
Remove whitespace from copy to clipboard component
If there is whitespace in the element containing the value to be copied then Firefox[1] includes that space in the value it puts in the clipboard. This is obviously annoying since `foo-bar` might be a valid API key where `foo-bar ` is not. This commit fixes that by using the `-` in Jinja to gobble whitespace. I also looked at doing this in the Javascript, but the browser API for selecting some text and copying it doesn’t give an obvious place for using `String.prototype.trim()`. 1. Tested with Firefox 100.0 on Mac OS 12.2.1
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<div data-module="copy-to-clipboard" data-value="{{ value }}" data-thing="{{ thing }}" data-name="{{ name }}">
|
<div data-module="copy-to-clipboard" data-value="{{ value }}" data-thing="{{ thing }}" data-name="{{ name }}">
|
||||||
<span class="copy-to-clipboard__value">
|
<span class="copy-to-clipboard__value">
|
||||||
{% if name|lower != thing|lower %}<span class="govuk-visually-hidden">{{ thing }}: </span>{% endif %}{{ value }}
|
{%- if name|lower != thing|lower %}<span class="govuk-visually-hidden">{{ thing }}: </span>{% endif %}{{ value -}}
|
||||||
</span>
|
</span>
|
||||||
<span class="copy-to-clipboard__notice" aria-live="assertive"></span>
|
<span class="copy-to-clipboard__notice" aria-live="assertive"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -281,8 +281,9 @@ def test_should_create_api_key_with_type_normal(
|
|||||||
_expected_status=200,
|
_expected_status=200,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert page.select_one('span.copy-to-clipboard__value').text.strip() == (
|
assert page.select_one('span.copy-to-clipboard__value').text == (
|
||||||
'some_default_key_name_12-{}-{}'.format(SERVICE_ONE_ID, fake_uuid)
|
# The text should be exactly this, with no leading or trailing whitespace
|
||||||
|
f'some_default_key_name_12-{SERVICE_ONE_ID}-{fake_uuid}'
|
||||||
)
|
)
|
||||||
|
|
||||||
post.assert_called_once_with(url='/service/{}/api-key'.format(SERVICE_ONE_ID), data={
|
post.assert_called_once_with(url='/service/{}/api-key'.format(SERVICE_ONE_ID), data={
|
||||||
|
|||||||
Reference in New Issue
Block a user