From a26dc325129961cf72d6dc6b1a63c3bf8e8770b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Mon, 24 Jan 2022 20:47:46 +0100
Subject: [PATCH] wcs: use <div> for all labels and values (#61033)

---
 .../combo/wcs/card-field-as-text.html         |   2 +-
 .../templates/combo/wcs/card-field-value.html |   4 +-
 combo/apps/wcs/templates/combo/wcs/card.html  |   4 +-
 tests/test_wcs.py                             | 109 +++++++++---------
 4 files changed, 58 insertions(+), 61 deletions(-)

diff --git a/combo/apps/wcs/templates/combo/wcs/card-field-as-text.html b/combo/apps/wcs/templates/combo/wcs/card-field-as-text.html
index 6d68a1a2..91f6890d 100644
--- a/combo/apps/wcs/templates/combo/wcs/card-field-as-text.html
+++ b/combo/apps/wcs/templates/combo/wcs/card-field-as-text.html
@@ -1,5 +1,5 @@
 {% if item.field_content == "label" or item.field_content == "label-and-value" %}
-  <p class="label">{{ field.label }}</p>
+  <div class="label">{{ field.label }}</div>
 {% endif %}
 {% if item.field_content == "value" or item.field_content == "label-and-value" %}
   {% include "combo/wcs/card-field-value.html" %}
diff --git a/combo/apps/wcs/templates/combo/wcs/card-field-value.html b/combo/apps/wcs/templates/combo/wcs/card-field-value.html
index 4297cdce..9530100e 100644
--- a/combo/apps/wcs/templates/combo/wcs/card-field-value.html
+++ b/combo/apps/wcs/templates/combo/wcs/card-field-value.html
@@ -2,7 +2,7 @@
 {% if field.type == "text" and mode != 'inline' and value %}
 <div class="value">{{ field|format_text:value }}</div>
 {% else %}
-{% if not mode == 'inline' %}<span class="value">{% endif %}
+{% if not mode == 'inline' %}<div class="value">{% endif %}
 {% if field.type == "date" %}
   {{ value|date }}
 {% elif field.type == "bool" and value is not None %}
@@ -18,6 +18,6 @@
 {% else %}
   {{ value|default:""|urlize }}
 {% endif %}
-{% if not mode == 'inline' %}</span>{% endif %}
+{% if not mode == 'inline' %}</div>{% endif %}
 {% endif %}
 {% endspaceless %}
diff --git a/combo/apps/wcs/templates/combo/wcs/card.html b/combo/apps/wcs/templates/combo/wcs/card.html
index 3f93631f..16085ffd 100644
--- a/combo/apps/wcs/templates/combo/wcs/card.html
+++ b/combo/apps/wcs/templates/combo/wcs/card.html
@@ -24,7 +24,7 @@
           {% elif item.display_mode == "subtitle" %}
             <h4>{{ value }}</h4>
           {% elif item.display_mode == "label" %}
-            <p class="label">{{ value }}</p>
+            <div class="label">{{ value }}</div>
           {% elif item.display_mode == "text" %}
             <div class="value">{{ value }}</div>
           {% endif %}
@@ -67,7 +67,7 @@
   {% if 'varname' in field and field.varname %}
   {% with card.fields|get:field.varname as value %}
   <div class="card--auto-field">
-    <span class="label">{{ field.label }}</span>
+    <div class="label">{{ field.label }}</div>
     {% include "combo/wcs/card-field-value.html" %}
   </div>
   {% endwith %}
diff --git a/tests/test_wcs.py b/tests/test_wcs.py
index 61fe1601..f1736f55 100644
--- a/tests/test_wcs.py
+++ b/tests/test_wcs.py
@@ -2344,13 +2344,13 @@ def test_card_cell_render(mock_send, context, app):
     mock_send.reset_mock()
     result = cell.render(context)
     assert '<h2>Card Model 1 - aa</h2>' in result
-    assert PyQuery(result).find('span.label:contains("Field A") + span').text() == 'a'
-    assert PyQuery(result).find('span.label:contains("Field B") + span').text() == 'yes'
-    assert PyQuery(result).find('span.label:contains("Field C") + span').text() == 'Sept. 28, 2020'
-    assert PyQuery(result).find('span.label:contains("Related") + span').text() == 'Foo Bar'
+    assert PyQuery(result).find('.label:contains("Field A") + .value').text() == 'a'
+    assert PyQuery(result).find('.label:contains("Field B") + .value').text() == 'yes'
+    assert PyQuery(result).find('.label:contains("Field C") + .value').text() == 'Sept. 28, 2020'
+    assert PyQuery(result).find('.label:contains("Related") + .value').text() == 'Foo Bar'
     assert 'related_raw' not in result
     assert 'related_structured' not in result
-    assert PyQuery(result).find('span.label:contains("Field D") + span a').text() == 'file.pdf'
+    assert PyQuery(result).find('.label:contains("Field D") + .value a').text() == 'file.pdf'
 
     context.pop('title')
     cell.title_type = 'manual'
@@ -2427,17 +2427,17 @@ def test_card_cell_render_text_field(mock_send, context):
 
     # field E is split in paragraphs
     assert (
-        PyQuery(result).find('span.label:contains("Field E") + div.value p:first-child').text().strip()
+        PyQuery(result).find('.label:contains("Field E") + .value p:first-child').text().strip()
         == 'lorem<strong>ipsum'
     )
     assert (
-        PyQuery(result).find('span.label:contains("Field E") + div.value p:last-child').text().strip()
+        PyQuery(result).find('.label:contains("Field E") + .value p:last-child').text().strip()
         == 'hello world'
     )
 
     # field F is put in a <pre>
     assert (
-        PyQuery(result).find('span.label:contains("Field F") + div.value pre').text()
+        PyQuery(result).find('.label:contains("Field F") + .value pre').text()
         == 'lorem<strong>ipsum hello world'
     )
 
@@ -2457,11 +2457,10 @@ def test_card_cell_render_email_field(mock_send, context):
 
     result = cell.render(context)
 
-    assert PyQuery(result).find('span.label:contains("Field G") + .value a').text() == 'test@localhost'
+    assert PyQuery(result).find('.label:contains("Field G") + .value a').text() == 'test@localhost'
 
     assert (
-        PyQuery(result).find('span.label:contains("Field G") + .value a').attr['href']
-        == 'mailto:test@localhost'
+        PyQuery(result).find('.label:contains("Field G") + .value a').attr['href'] == 'mailto:test@localhost'
     )
 
 
@@ -2481,12 +2480,10 @@ def test_card_cell_render_string_with_url_field(mock_send, context):
 
     result = cell.render(context)
 
-    assert (
-        PyQuery(result).find('span.label:contains("Field H") + .value a').text() == 'https://www.example.net/'
-    )
+    assert PyQuery(result).find('.label:contains("Field H") + .value a').text() == 'https://www.example.net/'
 
     assert (
-        PyQuery(result).find('span.label:contains("Field H") + .value a').attr['href']
+        PyQuery(result).find('.label:contains("Field H") + .value a').attr['href']
         == 'https://www.example.net/'
     )
 
@@ -2537,12 +2534,12 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     cell.custom_schema['cells'][0] = {'varname': 'fielda', 'field_content': 'label', 'display_mode': 'text'}
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Field A'
+    assert PyQuery(result).find('.label').text() == 'Field A'
 
     cell.custom_schema['cells'][0] = {'varname': 'fielda', 'field_content': 'value', 'display_mode': 'text'}
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('span.value').text() == 'a'
+    assert PyQuery(result).find('.value').text() == 'a'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'fielda',
@@ -2551,8 +2548,8 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Field A'
-    assert PyQuery(result).find('span.value').text() == 'a'
+    assert PyQuery(result).find('.label').text() == 'Field A'
+    assert PyQuery(result).find('.value').text() == 'a'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'fieldb',
@@ -2561,8 +2558,8 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Field B'
-    assert PyQuery(result).find('span.value').text() == 'yes'
+    assert PyQuery(result).find('.label').text() == 'Field B'
+    assert PyQuery(result).find('.value').text() == 'yes'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'fieldc',
@@ -2571,8 +2568,8 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Field C'
-    assert PyQuery(result).find('span.value').text() == 'Sept. 28, 2020'
+    assert PyQuery(result).find('.label').text() == 'Field C'
+    assert PyQuery(result).find('.value').text() == 'Sept. 28, 2020'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'related',
@@ -2581,8 +2578,8 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Related'
-    assert PyQuery(result).find('span.value').text() == 'Foo Bar'
+    assert PyQuery(result).find('.label').text() == 'Related'
+    assert PyQuery(result).find('.value').text() == 'Foo Bar'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'fieldd',
@@ -2591,8 +2588,8 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Field D'
-    assert PyQuery(result).find('span.value').text() == 'file.pdf'
+    assert PyQuery(result).find('.label').text() == 'Field D'
+    assert PyQuery(result).find('.value').text() == 'file.pdf'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'fielde',
@@ -2601,9 +2598,9 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Field E'
-    assert PyQuery(result).find('div.value p:first-child').text().strip() == 'lorem<strong>ipsum'
-    assert PyQuery(result).find('div.value p:last-child').text().strip() == 'hello world'
+    assert PyQuery(result).find('.label').text() == 'Field E'
+    assert PyQuery(result).find('.value p:first-child').text().strip() == 'lorem<strong>ipsum'
+    assert PyQuery(result).find('.value p:last-child').text().strip() == 'hello world'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'fieldf',
@@ -2612,8 +2609,8 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Field F'
-    assert PyQuery(result).find('div.value pre').text() == 'lorem<strong>ipsum hello world'
+    assert PyQuery(result).find('.label').text() == 'Field F'
+    assert PyQuery(result).find('.value pre').text() == 'lorem<strong>ipsum hello world'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'fieldg',
@@ -2622,9 +2619,9 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Field G'
-    assert PyQuery(result).find('span.value a').text() == 'test@localhost'
-    assert PyQuery(result).find('span.value a').attr['href'] == 'mailto:test@localhost'
+    assert PyQuery(result).find('.label').text() == 'Field G'
+    assert PyQuery(result).find('.value a').text() == 'test@localhost'
+    assert PyQuery(result).find('.value a').attr['href'] == 'mailto:test@localhost'
 
     cell.custom_schema['cells'][0] = {
         'varname': 'fieldh',
@@ -2633,9 +2630,9 @@ def test_card_cell_render_custom_schema_card_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Field H'
-    assert PyQuery(result).find('span.value a').text() == 'https://www.example.net/'
-    assert PyQuery(result).find('span.value a').attr['href'] == 'https://www.example.net/'
+    assert PyQuery(result).find('.label').text() == 'Field H'
+    assert PyQuery(result).find('.value a').text() == 'https://www.example.net/'
+    assert PyQuery(result).find('.value a').attr['href'] == 'https://www.example.net/'
 
 
 @mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
@@ -2665,8 +2662,8 @@ def test_card_cell_render_custom_schema_card_empty_field(mock_send, context):
     context['synchronous'] = True  # to get fresh content
 
     result = cell.render(context)
-    assert PyQuery(result).find('p.label') == []
-    assert PyQuery(result).find('span.value') == []
+    assert PyQuery(result).find('.label') == []
+    assert PyQuery(result).find('.value') == []
 
     cell.custom_schema['cells'][0] = {
         'varname': 'empty',
@@ -2676,8 +2673,8 @@ def test_card_cell_render_custom_schema_card_empty_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Empty'
-    assert PyQuery(result).find('span.value').text() == ''
+    assert PyQuery(result).find('.label').text() == 'Empty'
+    assert PyQuery(result).find('.value').text() == ''
 
     cell.custom_schema['cells'][0] = {
         'varname': 'empty',
@@ -2687,8 +2684,8 @@ def test_card_cell_render_custom_schema_card_empty_field(mock_send, context):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Empty'
-    assert PyQuery(result).find('span.value').text() == 'Custom text'
+    assert PyQuery(result).find('.label').text() == 'Empty'
+    assert PyQuery(result).find('.value').text() == 'Custom text'
 
     for field_content in ['label', 'value']:
         for display_mode in ['text', 'title', 'subtitle']:
@@ -2697,9 +2694,9 @@ def test_card_cell_render_custom_schema_card_empty_field(mock_send, context):
             elif display_mode == 'subtitle':
                 html_tag = 'h4'
             elif display_mode == 'text' and field_content == 'label':
-                html_tag = 'p.label'
+                html_tag = '.label'
             elif display_mode == 'text' and field_content == 'value':
-                html_tag = 'span.value'
+                html_tag = '.value'
             cell.custom_schema['cells'][0] = {
                 'varname': 'empty',
                 'field_content': field_content,
@@ -2780,8 +2777,8 @@ def test_card_cell_render_custom_schema_custom_entry(mock_send, context, app):
     }
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('p.label').text() == 'Foo bar baz'
-    assert PyQuery(result).find('div.value').text() == 'Foo,Bar'
+    assert PyQuery(result).find('.label').text() == 'Foo bar baz'
+    assert PyQuery(result).find('.value').text() == 'Foo,Bar'
 
     # test available context
     cell.card_ids = '11'
@@ -2799,7 +2796,7 @@ def test_card_cell_render_custom_schema_custom_entry(mock_send, context, app):
         kwargs={'page_pk': page.pk, 'cell_reference': cell.get_reference()},
     )
     cell_resp = app.get(cell_url + '?ctx=' + extra_ctx[0])
-    assert '<p class="label">Foo bar baz Xhttp://testserverY</p>' in cell_resp
+    assert PyQuery(cell_resp.text).find('.label').text() == 'Foo bar baz Xhttp://testserverY'
 
     cell.card_ids = '{{ cards|objects:"card_model_1"|getlist:"id"|join:"," }}'
     cell.custom_schema = {
@@ -2817,7 +2814,7 @@ def test_card_cell_render_custom_schema_custom_entry(mock_send, context, app):
     )
     for i in range(0, 3):
         cell_resp = app.get(cell_url + '?ctx=' + extra_ctx[i])
-        assert '<p class="label">Foo bar baz X%sY</p>' % i in cell_resp
+        assert PyQuery(cell_resp.text).find('.label').text() == 'Foo bar baz X%sY' % i
 
     # custom schema but empty
     cell.custom_schema = {'cells': []}
@@ -2853,16 +2850,16 @@ def test_card_cell_render_custom_schema_link_entry(mock_send, context, app):
     context['synchronous'] = True  # to get fresh content
 
     result = cell.render(context)
-    assert PyQuery(result).find('div.value a').text() == 'a - Foo Bar'
-    assert PyQuery(result).find('div.value a').attr['href'] == '/foo/bar/42/'
-    assert PyQuery(result).find('div.value a').attr['class'] is None
+    assert PyQuery(result).find('.value a').text() == 'a - Foo Bar'
+    assert PyQuery(result).find('.value a').attr['href'] == '/foo/bar/42/'
+    assert PyQuery(result).find('.value a').attr['class'] is None
 
     cell.custom_schema['cells'][0]['display_mode'] = 'button'
     cell.save()
     result = cell.render(context)
-    assert PyQuery(result).find('div.value a').text() == 'a - Foo Bar'
-    assert PyQuery(result).find('div.value a').attr['href'] == '/foo/bar/42/'
-    assert PyQuery(result).find('div.value a').attr['class'] == 'pk-button'
+    assert PyQuery(result).find('.value a').text() == 'a - Foo Bar'
+    assert PyQuery(result).find('.value a').attr['href'] == '/foo/bar/42/'
+    assert PyQuery(result).find('.value a').attr['class'] == 'pk-button'
 
     cell.custom_schema['cells'][0][
         'url_template'
-- 
2.34.1

