From ffcc122efb0e9f265d4b959942d17134205cad4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Wed, 18 Mar 2020 19:55:53 +0100
Subject: [PATCH] wcs: add message for empty states in drafts/forms cells
 (#13974)

---
 .../templates/combo/wcs/current_drafts.html   |  1 +
 .../templates/combo/wcs/current_forms.html    |  1 +
 .../templates/combo/wcs/user_all_forms.html   |  1 +
 .../templates/combo/wcs/user_done_forms.html  |  1 +
 tests/test_wcs.py                             | 19 +++++++++++++++++++
 5 files changed, 23 insertions(+)

diff --git a/combo/apps/wcs/templates/combo/wcs/current_drafts.html b/combo/apps/wcs/templates/combo/wcs/current_drafts.html
index 1a1e1b09..9a688e8f 100644
--- a/combo/apps/wcs/templates/combo/wcs/current_drafts.html
+++ b/combo/apps/wcs/templates/combo/wcs/current_drafts.html
@@ -17,5 +17,6 @@
   {% endif %}
 </div>
 {% endfor %}
+{% if not drafts %}<div class="empty-message"><p>{% trans "There are no current drafts." %}</p></div>{% endif %}
 {% include "combo/pagination.html" %}
 {% endblock %}
diff --git a/combo/apps/wcs/templates/combo/wcs/current_forms.html b/combo/apps/wcs/templates/combo/wcs/current_forms.html
index 38ce44a1..90623008 100644
--- a/combo/apps/wcs/templates/combo/wcs/current_forms.html
+++ b/combo/apps/wcs/templates/combo/wcs/current_forms.html
@@ -6,5 +6,6 @@
   {% include "combo/wcs/list_of_forms.html" with forms=forms %}
   </div>
 {% endfor %}
+{% if not forms %}<div class="empty-message"><p>{% trans "There are no current forms." %}</p></div>{% endif %}
 {% include "combo/pagination.html" %}
 {% endblock %}
diff --git a/combo/apps/wcs/templates/combo/wcs/user_all_forms.html b/combo/apps/wcs/templates/combo/wcs/user_all_forms.html
index 82d4fc89..078b2902 100644
--- a/combo/apps/wcs/templates/combo/wcs/user_all_forms.html
+++ b/combo/apps/wcs/templates/combo/wcs/user_all_forms.html
@@ -6,5 +6,6 @@
   {% include "combo/wcs/list_of_forms.html" with forms=forms %}
   </div>
 {% endfor %}
+{% if not forms %}<div class="empty-message"><p>{% trans "There are no forms." %}</p></div>{% endif %}
 {% include "combo/pagination.html" %}
 {% endblock %}
diff --git a/combo/apps/wcs/templates/combo/wcs/user_done_forms.html b/combo/apps/wcs/templates/combo/wcs/user_done_forms.html
index 754fc43c..d88ae148 100644
--- a/combo/apps/wcs/templates/combo/wcs/user_done_forms.html
+++ b/combo/apps/wcs/templates/combo/wcs/user_done_forms.html
@@ -6,5 +6,6 @@
   {% include "combo/wcs/list_of_forms.html" with forms=forms %}
   </div>
 {% endfor %}
+{% if not forms %}<div class="empty-message"><p>{% trans "There are no done forms or they have been removed." %}</p></div>{% endif %}
 {% include "combo/pagination.html" %}
 {% endblock %}
diff --git a/tests/test_wcs.py b/tests/test_wcs.py
index e92e7e2b..57f922ef 100644
--- a/tests/test_wcs.py
+++ b/tests/test_wcs.py
@@ -495,6 +495,20 @@ def test_current_forms_cell_render(context):
         cell.get_cell_extra_context(context)
     assert requests_get.call_args_list[0][0][0] == '/api/user/forms?limit=100&sort=desc&include-drafts=on'
 
+    # check empty messages
+    cell.categories = {'data': ['default:test-3']}
+    cell.current_forms = True
+    cell.done_forms = False
+    cell.include_drafts = False
+    result = cell.render(context)
+    assert 'There are no current forms.' in result
+    cell.done_forms = True
+    result = cell.render(context)
+    assert 'There are no forms.' in result
+    cell.current_forms = False
+    result = cell.render(context)
+    assert 'There are no done forms' in result
+
 
 @wcs_present
 def test_current_forms_cell_validity(context):
@@ -814,6 +828,7 @@ def test_current_drafts_cell_render_unlogged(context):
     result = cell.render(context)
     assert not 'http://127.0.0.1:8999/third-form-title' in result # no form
 
+
 @wcs_present
 def test_current_drafts_cell_render_logged_in(context):
     page = Page(title='xxx', slug='test_current_drafts_cell_render', template_name='standard')
@@ -844,6 +859,10 @@ def test_current_drafts_cell_render_logged_in(context):
     extra_context = cell.get_cell_extra_context(context)
     assert len(extra_context['drafts']) == 0
 
+    # check empty message
+    result = cell.render(context)
+    assert 'There are no current drafts.' in result
+
 
 @wcs_present
 def test_current_drafts_cell_check_validity(context):
-- 
2.26.0.rc2

