mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 10:28:41 -04:00
Merge pull request #3167 from alphagov/hide-len-1-template-statistics
Don’t show template statistics on dashboard if only one template has been used
This commit is contained in:
@@ -334,7 +334,6 @@ def get_dashboard_partials(service_id):
|
|||||||
[row['count'] for row in template_statistics] or [0]
|
[row['count'] for row in template_statistics] or [0]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'has_template_statistics': bool(template_statistics),
|
|
||||||
'jobs': render_template(
|
'jobs': render_template(
|
||||||
'views/dashboard/_jobs.html',
|
'views/dashboard/_jobs.html',
|
||||||
jobs=immediate_jobs
|
jobs=immediate_jobs
|
||||||
|
|||||||
@@ -33,13 +33,7 @@
|
|||||||
'See messages sent per month'
|
'See messages sent per month'
|
||||||
) }}
|
) }}
|
||||||
|
|
||||||
{% if partials['has_template_statistics'] %}
|
{{ ajax_block(partials, updates_url, 'template-statistics', interval=5) }}
|
||||||
{{ ajax_block(partials, updates_url, 'template-statistics', interval=5) }}
|
|
||||||
{{ show_more(
|
|
||||||
url_for('.template_usage', service_id=current_service.id),
|
|
||||||
'See templates used by month'
|
|
||||||
) }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if partials['has_jobs'] %}
|
{% if partials['has_jobs'] %}
|
||||||
{{ ajax_block(partials, updates_url, 'jobs', interval=5) }}
|
{{ ajax_block(partials, updates_url, 'jobs', interval=5) }}
|
||||||
|
|||||||
@@ -2,46 +2,44 @@
|
|||||||
{% from "components/message-count-label.html" import message_count_label %}
|
{% from "components/message-count-label.html" import message_count_label %}
|
||||||
{% from "components/big-number.html" import big_number %}
|
{% from "components/big-number.html" import big_number %}
|
||||||
{% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading, spark_bar_field %}
|
{% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading, spark_bar_field %}
|
||||||
|
{% from "components/show-more.html" import show_more %}
|
||||||
|
|
||||||
<div class='dashboard-table'>
|
<div class="ajax-block-container">
|
||||||
{% call(item, row_number) list_table(
|
{% if template_statistics|length > 1 %}
|
||||||
template_statistics,
|
<div class='dashboard-table'>
|
||||||
caption="Templates used",
|
{% call(item, row_number) list_table(
|
||||||
caption_visible=False,
|
template_statistics,
|
||||||
empty_message='',
|
caption="Templates used",
|
||||||
field_headings=[
|
caption_visible=False,
|
||||||
'Template',
|
empty_message='',
|
||||||
'Messages sent'
|
field_headings=[
|
||||||
],
|
'Template',
|
||||||
field_headings_visible=True
|
'Messages sent'
|
||||||
) %}
|
],
|
||||||
|
field_headings_visible=True
|
||||||
|
) %}
|
||||||
|
|
||||||
{% call row_heading() %}
|
{% call row_heading() %}
|
||||||
{% if item.is_precompiled_letter %}
|
{% if item.is_precompiled_letter %}
|
||||||
<span class="file-list-filename">
|
<span class="file-list-filename">
|
||||||
Provided as PDF
|
Provided as PDF
|
||||||
</span>
|
</span>
|
||||||
<span class="file-list-hint">
|
<span class="file-list-hint">
|
||||||
Letter
|
Letter
|
||||||
</span>
|
</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a class="file-list-filename" href="{{ url_for('.view_template', service_id=current_service.id, template_id=item.template_id) }}">{{ item.template_name }}</a>
|
<a class="file-list-filename" href="{{ url_for('.view_template', service_id=current_service.id, template_id=item.template_id) }}">{{ item.template_name }}</a>
|
||||||
<span class="file-list-hint">
|
<span class="file-list-hint">
|
||||||
{{ message_count_label(1, item.template_type, suffix='template')|capitalize }}
|
{{ message_count_label(1, item.template_type, suffix='template')|capitalize }}
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% if template_statistics|length > 1 %}
|
{{ spark_bar_field(item.count, most_used_template_count, id=item.template_id) }}
|
||||||
{{ spark_bar_field(item.count, most_used_template_count, id=item.template_id) }}
|
|
||||||
{% else %}
|
|
||||||
{% call field() %}
|
|
||||||
<span id='{{item.template_id}}' class="heading-small">
|
|
||||||
{{ big_number(
|
|
||||||
item.count,
|
|
||||||
smallest=True
|
|
||||||
) }}
|
|
||||||
</span>
|
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% endif %}
|
{{ show_more(
|
||||||
{% endcall %}
|
url_for('.template_usage', service_id=current_service.id),
|
||||||
|
'See templates used by month'
|
||||||
|
) }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -496,6 +496,45 @@ def test_should_show_recent_templates_on_dashboard(
|
|||||||
assert '100' in table_rows[3].find_all('td')[0].text
|
assert '100' in table_rows[3].find_all('td')[0].text
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('stats', (
|
||||||
|
pytest.param(
|
||||||
|
[stub_template_stats[0]],
|
||||||
|
),
|
||||||
|
pytest.param(
|
||||||
|
[stub_template_stats[0], stub_template_stats[1]],
|
||||||
|
marks=pytest.mark.xfail(raises=AssertionError),
|
||||||
|
)
|
||||||
|
))
|
||||||
|
def test_should_not_show_recent_templates_on_dashboard_if_only_one_template_used(
|
||||||
|
client_request,
|
||||||
|
mocker,
|
||||||
|
mock_get_service_templates,
|
||||||
|
mock_get_jobs,
|
||||||
|
mock_get_service_statistics,
|
||||||
|
mock_get_usage,
|
||||||
|
mock_get_inbound_sms_summary,
|
||||||
|
stats,
|
||||||
|
):
|
||||||
|
mock_template_stats = mocker.patch(
|
||||||
|
'app.template_statistics_client.get_template_statistics_for_service',
|
||||||
|
return_value=stats,
|
||||||
|
)
|
||||||
|
|
||||||
|
page = client_request.get('main.service_dashboard', service_id=SERVICE_ONE_ID)
|
||||||
|
main = page.select_one('main').text
|
||||||
|
|
||||||
|
mock_template_stats.assert_called_once_with(SERVICE_ONE_ID, limit_days=7)
|
||||||
|
|
||||||
|
assert stats[0]['template_name'] == 'one'
|
||||||
|
assert stats[0]['template_name'] not in main
|
||||||
|
|
||||||
|
# count appears as total, but not per template
|
||||||
|
expected_count = stats[0]['count']
|
||||||
|
assert expected_count == 50
|
||||||
|
assert main.count(str(expected_count)) == 1
|
||||||
|
assert '50 text messages sent' in normalize_spaces(main)
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2016-07-01 12:00") # 4 months into 2016 financial year
|
@freeze_time("2016-07-01 12:00") # 4 months into 2016 financial year
|
||||||
@pytest.mark.parametrize('extra_args', [
|
@pytest.mark.parametrize('extra_args', [
|
||||||
{},
|
{},
|
||||||
@@ -763,7 +802,7 @@ def test_should_show_recent_jobs_on_dashboard(
|
|||||||
assert third_call[1]['limit_days'] == 7
|
assert third_call[1]['limit_days'] == 7
|
||||||
assert 'scheduled' not in third_call[1]['statuses']
|
assert 'scheduled' not in third_call[1]['statuses']
|
||||||
|
|
||||||
table_rows = page.find_all('tbody')[2].find_all('tr')
|
table_rows = page.find_all('tbody')[1].find_all('tr')
|
||||||
|
|
||||||
assert len(table_rows) == 4
|
assert len(table_rows) == 4
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user