|
1 | 1 | # Copyright The IETF Trust 2009-2020, All Rights Reserved |
2 | 2 | # -*- coding: utf-8 -*- |
| 3 | +import debug # pyflakes: ignore |
3 | 4 |
|
4 | 5 | from django.template import Context, Template |
| 6 | +from pyquery import PyQuery |
5 | 7 |
|
6 | 8 | from ietf.meeting.factories import FloorPlanFactory, RoomFactory, TimeSlotFactory |
7 | 9 | from ietf.meeting.templatetags.agenda_custom_tags import AnchorNode |
| 10 | +from ietf.meeting.templatetags.editor_tags import constraint_icon_for |
| 11 | +from ietf.name.models import ConstraintName |
8 | 12 | from ietf.utils.test_utils import TestCase |
9 | 13 |
|
10 | 14 |
|
@@ -43,3 +47,80 @@ def test_location_anchor_node(self): |
43 | 47 | f'<span><a href="{context["show_location"].location.floorplan_url()}">show_location</a></span>', |
44 | 48 | result, |
45 | 49 | ) |
| 50 | + |
| 51 | + |
| 52 | +class EditorTagsTests(TestCase): |
| 53 | + def _supported_constraint_names(self): |
| 54 | + """Get all ConstraintNames that must be supported by the tags""" |
| 55 | + constraint_names = set(ConstraintName.objects.filter(used=True)) |
| 56 | + # Instantiate a couple that are added at run-time in meeting.utils |
| 57 | + constraint_names.add(ConstraintName(slug='joint_with_groups', name='joint with groups')) |
| 58 | + constraint_names.add(ConstraintName(slug='responsible_ad', name='AD')) |
| 59 | + # Reversed names are also added at run-time |
| 60 | + reversed = [ |
| 61 | + ConstraintName(slug=f'{n.slug}-reversed', name=f'{n.name} - reversed') |
| 62 | + for n in constraint_names |
| 63 | + ] |
| 64 | + constraint_names.update(reversed) |
| 65 | + return constraint_names |
| 66 | + |
| 67 | + def test_constraint_icon_for_supports_all(self): |
| 68 | + """constraint_icon_for tag should render all the necessary ConstraintNames |
| 69 | +
|
| 70 | + Relies on ConstraintNames in the names.json fixture being up-to-date |
| 71 | + """ |
| 72 | + for cn in self._supported_constraint_names(): |
| 73 | + self.assertGreater(len(constraint_icon_for(cn)), 0) |
| 74 | + self.assertGreater(len(constraint_icon_for(cn, count=1)), 0) |
| 75 | + |
| 76 | + def test_constraint_icon_for(self): |
| 77 | + """Constraint icons should render as expected |
| 78 | +
|
| 79 | + This is the authoritative definition of what should be rendered for each constraint. |
| 80 | + Update this before changing the constraint_icon_for tag. |
| 81 | + """ |
| 82 | + test_cases = ( |
| 83 | + # (ConstraintName slug, additional tag parameters, expected output HTML) |
| 84 | + ('conflict', '', '<span class="encircled">1</span>'), |
| 85 | + ('conflic2', '', '<span class="encircled">2</span>'), |
| 86 | + ('conflic3', '', '<span class="encircled">3</span>'), |
| 87 | + ('conflict-reversed', '', '<span class="encircled">-1</span>'), |
| 88 | + ('conflic2-reversed', '', '<span class="encircled">-2</span>'), |
| 89 | + ('conflic3-reversed', '', '<span class="encircled">-3</span>'), |
| 90 | + ('bethere', '27', '<i class="bi bi-person"></i>27'), |
| 91 | + ('timerange', '', '<i class="bi bi-calendar"></i>'), |
| 92 | + ('time_relation', '', '\u0394'), # \u0394 is a capital Greek Delta |
| 93 | + ('wg_adjacent', '', '<i class="bi bi-skip-end"></i>'), |
| 94 | + ('wg_adjacent-reversed', '', '-<i class="bi bi-skip-end"></i>'), |
| 95 | + ('chair_conflict', '', '<i class="bi bi-person-circle"></i>'), |
| 96 | + ('chair_conflict-reversed', '', '-<i class="bi bi-person-circle"></i>'), |
| 97 | + ('tech_overlap', '', '<i class="bi bi-link"></i>'), |
| 98 | + ('tech_overlap-reversed', '', '-<i class="bi bi-link"></i>'), |
| 99 | + ('key_participant', '', '<i class="bi bi-key"></i>'), |
| 100 | + ('key_participant-reversed', '', '-<i class="bi bi-key"></i>'), |
| 101 | + ('joint_with_groups', '', '<i class="bi bi-merge"></i>'), |
| 102 | + ('responsible_ad', '', '<span class="encircled">AD</span>'), |
| 103 | + ) |
| 104 | + # Create a template with a cn_i context variable for the ConstraintName in each test case. |
| 105 | + template = Template( |
| 106 | + '{% load editor_tags %}<html>' + |
| 107 | + ''.join( |
| 108 | + f'<div id="test-case-{index}">{{% constraint_icon_for cn_{index} {params} %}}</div>' |
| 109 | + for index, (_, params, _) in enumerate(test_cases) |
| 110 | + ) + |
| 111 | + '</html>' |
| 112 | + ) |
| 113 | + # Construct the cn_i in the Context and render. |
| 114 | + result = template.render( |
| 115 | + Context({ |
| 116 | + f'cn_{index}': ConstraintName(slug=slug) |
| 117 | + for index, (slug, _, _) in enumerate(test_cases) |
| 118 | + }) |
| 119 | + ) |
| 120 | + q = PyQuery(result) |
| 121 | + for index, (slug, params, expected) in enumerate(test_cases): |
| 122 | + self.assertHTMLEqual( |
| 123 | + q(f'#test-case-{index}').html(), |
| 124 | + expected, |
| 125 | + f'Unexpected output for {slug} {params}', |
| 126 | + ) |
0 commit comments